Skip to content

Commit

Permalink
Fix issue in db migration scripts (#1608)
Browse files Browse the repository at this point in the history
* Change commands to use typeorm cli

* Select migration files based on node env

* Fix eslint errors on staging branch
ae2079 authored Jun 5, 2024
1 parent 54d61ad commit a0d2db9
Showing 4 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -209,8 +209,8 @@
"db:migrate:revert:test": "NODE_ENV=test npx typeorm-ts-node-commonjs migration:revert -d ./src/ormconfig.ts",
"db:migrate:run:local": "NODE_ENV=development npx typeorm-ts-node-commonjs migration:run -d ./src/ormconfig.ts",
"db:migrate:revert:local": "NODE_ENV=development npx typeorm-ts-node-commonjs migration:revert -d ./src/ormconfig.ts",
"db:migrate:run:production": "NODE_ENV=production npx typeorm-ts-node-commonjs migration:run -d ./src/ormconfig.ts",
"db:migrate:rever:productiont": "NODE_ENV=production npx typeorm-ts-node-commonjs migration:revert -d ./src/ormconfig.ts",
"db:migrate:run:production": "NODE_ENV=production typeorm migration:run -d ./build/src/ormconfig.js",
"db:migrate:revert:production": "NODE_ENV=production typeorm migration:revert -d ./build/src/ormconfig.js",
"prettify": "prettier --write '**/*.ts*' '**/*.test.ts*'",
"db:migrate:seedToken:run": "NODE_ENV=development ts-node ./node_modules/typeorm/cli -f ./src/seedToken-ormconfig.ts migration:run",
"db:migrate:seedToken:revert": "NODE_ENV=development ts-node ./node_modules/typeorm/cli -f ./src/seedToken-ormconfig.ts migration:revert",
13 changes: 7 additions & 6 deletions src/debug.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
JSON.safeStringify = (obj, indent = 2) => {
let cache = []
let cache = [];
const retVal = JSON.stringify(
obj,
(key, value) =>
@@ -9,8 +10,8 @@ JSON.safeStringify = (obj, indent = 2) => {
? undefined // Duplicate reference found, discard key
: cache.push(value) && value // Store value in our collection
: value,
indent
)
cache = []
return retVal
}
indent,
);
cache = [];
return retVal;
};
6 changes: 4 additions & 2 deletions src/dev.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require('ts-node/register/transpile-only')
// eslint-disable-next-line no-undef
require('ts-node/register/transpile-only');

require('./index')
// eslint-disable-next-line no-undef
require('./index');
6 changes: 5 additions & 1 deletion src/ormconfig.ts
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ if (loadConfigResult.error) {

import { DataSource, DataSourceOptions } from 'typeorm';
import { getEntities } from './entities/entities';
import { ENVIRONMENTS } from './utils/utils';

const ormConfig: DataSourceOptions = {
type: 'postgres',
@@ -29,7 +30,10 @@ const ormConfig: DataSourceOptions = {
password: process.env.TYPEORM_DATABASE_PASSWORD,
database: process.env.TYPEORM_DATABASE_NAME,
entities: getEntities(),
migrations: ['migration/*.ts'],
migrations:
process.env.NODE_ENV === ENVIRONMENTS.PRODUCTION
? ['migration/*.js']
: ['migration/*.ts'],
// cli: {
// migrationsDir: 'migration',
// },

0 comments on commit a0d2db9

Please sign in to comment.