1

I have a web app, and I've written a migrator to create all my tables and relations, recently no matter what I try, typeorm does not appear to find this migrator and hence, does not run it.

My file structure (just the migrations)

src> Databas> Migrations>1663525805095-add_users.ts,1663529676790-make_institute_nullable.ts

ormconfig.ts

import { DataSource } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { config } from 'dotenv';

config();

const configService = new ConfigService();

const source = new DataSource({
  type: 'postgres',
  host: configService.get('POSTGRES_HOST'),
  port: configService.get('POSTGRES_PORT'),
  username: configService.get('POSTGRES_USER'),
  password: configService.get('POSTGRES_PASSWORD'),
  database: configService.get('POSTGRES_DB'),
  synchronize: false,
  logging: false,
  migrations: ['src/database/migrations/*.ts'],
  migrationsTableName: 'migrations',
  entities: ['src/**/*.entity.ts'],
});

export default source;

In order to run this, I type yarn start:dev in order to get my Server started. Then I run yarn migrations:run which I get:

query: SELECT * FROM current_schema()
query: SELECT version();
query: SELECT * FROM "information_schema"."tables" WHERE "table_schema" = 'public' AND "table_name" = 'migrations'
query: CREATE TABLE "migrations" ("id" SERIAL NOT NULL, "timestamp" bigint NOT NULL, "name" character varying NOT NULL, CONSTRAINT "PK_8c82d7f526340ab734260ea46be" PRIMARY KEY ("id"))
query: SELECT * FROM "migrations" "migrations" ORDER BY "id" DESC
No migrations are pending

When I look at my db, I see a migrations table with no entries.

I have tried to delete my migrator file and create it again with a more recent timestamp and that does not work either.

scripts from my package.json "migrations:run": "yarn typeorm migration:run" "typeorm": "typeorm-ts-node-commonjs -d ./ormconfig.ts" "start:dev": "nest start --watch"

Other info I'm using docker for the postgres DB and pgAdmin, it connects with no problem. Any help would be greatly appreciated.

Ken White
  • 123,280
  • 14
  • 225
  • 444
Stol3nH4t
  • 11
  • 3
  • if you are windows user and you are using typeorm `0.3.12` and you are facing this issue directly on you windows system (and not docker) then this might be the issue https://github.com/typeorm/typeorm/issues/9766. In such case downgrade to typeorm `0.3.11` and check manually `package-lock.json` really depend on that version and not `0.3.12` Btw, right at the moment i am facing `no migrations pending` issue when i setup my docker-compose - database service and app service are working nice, but typeorm migrations are somehow missing (`0.2.41` is the current version of i use for this project) – Stefan Mar 12 '23 at 15:19

1 Answers1

1

try

  migrations: ['dist/database/migrations/*.{ts,js}'],
  migrationsRun: true,

and remember to build before generating migration

Hai Alison
  • 419
  • 2
  • 9