In version 4, does lucid have soft delete feature like in version 3?


#1

I don’t find any information about soft deleting on version 4 documentation. And when I tried to create soft delete timestamp with softDeletes() method, error shows that it is not a function.

class UserSchema extends Schema {
  up() {
    return this.create('users', table => {
      table.increments();
      table.string('username', 80).notNullable().unique();
      table.string('email', 254).notNullable().unique();
      table.string('password', 60).notNullable();
      table.timestamps();
      table.softDeletes();
    });
  }

  down() {
    this.drop('users');
  }
};

TypeError: table.softDeletes is not a function
    at TableBuilder.create.table [as _fn] (/home/chabib/Code/api.askodis/.dist/database/migrations/1503250034279_user.js:17:16)
    at TableBuilder.toSQL (/home/chabib/Code/api.askodis/node_modules/knex/lib/schema/tablebuilder.js:71:12)
    at SchemaCompiler_MySQL.createTable (/home/chabib/Code/api.askodis/node_modules/knex/lib/schema/compiler.js:62:23)
    at SchemaCompiler_MySQL.toSQL (/home/chabib/Code/api.askodis/node_modules/knex/lib/schema/compiler.js:51:26)
    at SchemaBuilder.toSQL (/home/chabib/Code/api.askodis/node_modules/knex/lib/schema/builder.js:57:43)
    at /home/chabib/Code/api.askodis/node_modules/knex/lib/runner.js:56:32
From previous event:
    at Runner.run (/home/chabib/Code/api.askodis/node_modules/knex/lib/runner.js:51:31)
    at SchemaBuilder.Target.then (/home/chabib/Code/api.askodis/node_modules/knex/lib/interface.js:35:43)

#2

Hi @chabib! After fast looking in lucid codebase i found, that it unit test has code like this:

   db.schema.createTable('profiles', function (table) {
     table.integer('likes')
     table.timestamps()
     table.timestamp('deleted_at').nullable()
   })

It’s look like this feature exists, but nod documented yet and npt obvious. Can you try it?


#3

Yes soft deletes are not part of the core of Lucid, I will be creating a trait for that.


#4

@virk Hey bro :slight_smile:, when is possible release with that?


#5

Where can I find it?


#6

Sorry for bumping this thread. Is there a solution out there yet?

Many thanks.


#7

Hey @jacksoncharles! :wave:

Yes, there’s an experimental package build by radmen.

It will be added to the score after some testing.
Here’s the related PR about it: https://github.com/adonisjs/adonis-lucid/pull/315