Reputation: 1
Steps to reproduce or a small repository showing the problem:
I am working on a project with typeorm on nestjs. the problem is even after running migration after generating migration files, i get No migrations are pending
The commands i am using are
"scripts": {
"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli -d ./dist/modules/config/app-migration.js",
"migration:create": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli migration:create ./src/migrations/migration",
"migration:run": "npm run typeorm -- migration:run",
"migration:revert": "npm run typeorm -- migration:revert",
"migration:generate": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli -d ./src/modules/config/app-migration.ts migration:generate ./src/migrations/migration"
},
Packages version :-
"typeorm": "^0.3.11",
"typeorm-cli": "^1.0.7"
"ts-node": "^10.0.0",
"tsconfig-paths": "4.1.0",
BTW: my src/module/config/app-migration.ts file looks like this
import { cwd } from 'process';
import { DataSource, DataSourceOptions } from 'typeorm';
import configuration from './configuration';
import { config } from 'dotenv';
config();
const {
database: { username, password, database, host, port, schema },
nodeEnv,
} = configuration();
let entities = '/src/**/*.entity.ts';
let migrations = '/src/migrations/*.ts';
if (nodeEnv.toLowerCase() === 'production') {
entities = '/dist/**/*.entity.js';
migrations = '/dist/migrations/*.js';
}
const dataSourceObj: DataSourceOptions = {
type: 'postgres',
host: host,
port: parseInt(port),
username: username,
password: password,
database: database,
schema: schema,
entities: [cwd() + entities],
migrations: [cwd() + migrations],
extra: {
seeds: [cwd() + '/src/seeds/*.ts'],
},
migrationsTableName: 'migrations',
synchronize: false,
dropSchema: false,
};
export const dataSource = new DataSource(dataSourceObj);
export default dataSourceObj;
I tried npm run buld npm run migration:run
Out Put
[email protected] migration:run npm run typeorm -- migration:run
[email protected] typeorm ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli -d ./dist/modules/config/app-migration.js
query: SELECT * FROM current_schema() query: SELECT version(); query: SELECT * FROM "information_schema"."tables" WHERE "table_schema" = 'rms-academic' AND "table_name" = 'migrations' query: SELECT * FROM "schema"."migrations" "migrations" ORDER BY "id" DESC No migrations are pending
Upvotes: 0
Views: 464
Reputation: 88
in typeorm version 0.3.x you have to provide the entities, migrations,.. with array, the use of glob pattern is deprecated
so try with something like this it will work :
const ENTITIES=[User]
const MIGRATIONS=[migration1]
export const DATA_SOURCE_OPTIONS: DataSourceOptions = {
type: 'postgres',
host: process.env.DATABASE_HOST || 'localhost',
port: parseInt(process.env.DATABASE_PORT, 10),
database: process.env.DATABASE_NAME,
username: process.env.DATABASE_USER,
password: process.env.DATABASE_PASSWORD,
entities: ENTITIES,
migrations: MIGRATIONS,
migrationsTableName: 'typeorm_migrations',
namingStrategy: new SnakeNamingStrategy(),
migrationsRun: false,
synchronize: false,
};
export default new DataSource(DATA_SOURCE_OPTIONS);
Upvotes: 0