adonis run specific seeder 1

adonis run specific seeder

node ace db:seed --files "./database/seeders/User.ts"

Here is what the above code is Doing:
1. We’re using the `npx` command to run the `typeorm` CLI.
2. We’re using the `migration:create` command to create a new migration file.
3. We’re using the `-n` flag to specify the name of the migration file.
4. We’re using the `-d` flag to specify the directory where the migration file should be created.

The `typeorm` CLI will create a new migration file in the `./database/migrations` directory.

The migration file will look something like this:

“`typescript
import {MigrationInterface, QueryRunner} from “typeorm”;

export class MyFirstMigration1599098181208 implements MigrationInterface {

public async up(queryRunner: QueryRunner): Promise {
}

public async down(queryRunner: QueryRunner): Promise {
}

}
“`

The `up` method is where we’ll write the code to create the table.
The `down` method is where we’ll write the code to undo the changes made by the `up` method.

Let’s add the code to create the `users` table:

“`typescript
import {MigrationInterface, QueryRunner} from “typeorm”;

export class MyFirstMigration1599098181208 implements MigrationInterface {

public async up(queryRunner: QueryRunner): Promise {
await queryRunner.query(`
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL
)
`);
}

public async down(queryRunner: QueryRunner): Promise {
await queryRunner.query(`DROP TABLE users`);
}

}
“`

The `up` method uses the `queryRunner` to execute a SQL query to create the `users` table.
The `down` method uses the `queryRunner` to execute a SQL query to drop the `users` table.

Now that we’ve created the migration file, we need to run it.

We can run the migration file using the `typeorm` CLI:

npx typeorm migration:run

Similar Posts