I have a new web app and I've written a migrator to create a user table. However, no matter what I try, typeorm does not appear to find this migrator and hence, does not run it.
My file structure (other files/folders not shown):
├── Server
│ ├── dist
| | ├── Migrations
| | | ├── 1234567891234567890-AddUserTable.js
| | | ├── 1234567891234567890-AddUserTable.js.map
| | | ├── 1234567891234567890-AddUserTable.d.ts
│ ├── src
| | ├── Migrations
| | | ├── 1234567891234567890-AddUserTable.ts
| | ├── app.module.ts
app.module.ts
@Module({
imports: [
ConfigModule.forRoot({ envFilePath: '.env' }),
TypeOrmModule.forRootAsync({
imports: [ConfigModule],
useFactory: (configService: ConfigService) => ({
type: 'mysql',
host: configService.get('TYPEORM_HOST'),
port: +configService.get<number>('TYPEORM_PORT'),
username: configService.get('TYPEORM_USERNAME'),
password: configService.get('TYPEORM_PASSWORD'),
database: configService.get('TYPEORM_DATABASE'),
synchronize: configService.get('TYPEORM_SYNCHRONIZE'),
entities: [__dirname + '/**/*.entity{.ts,.js}'],
migrations: [__dirname + '/Migrations/**/*.js'],
migrationsRun: false,
cli: {
migrationsDir: './Migrations',
},
}),
inject: [ConfigService],
}),
],
controllers: [],
providers: [],
})
export class AppModule {
constructor(private connection: Connection) {}
}
In order to run this, in my console window, I type: nest start in order get my Server started.
Then, I run npx typeorm migration:run which I get:
query: SELECT * FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA` = 'myDB' AND `TABLE_NAME` = 'migrations'
query: SELECT * FROM `myDB`.`migrations` `migrations` ORDER BY `id` DESC
No migrations are pending
If I look in my DB, I see a migrations table with no entries inside.
I have tried to delete my migrator file and create it again with a more recent timestamp and that does not work either.
npx typeorm migration:create -n "MyMigratorName"
Any help would be greatly appreciated.