Fix #4926
This commit is contained in:
parent
763b70e01b
commit
bb2d76ffa3
|
@ -588,10 +588,9 @@ mongodb:
|
||||||
3. migration ブランチに切り替え
|
3. migration ブランチに切り替え
|
||||||
4. `npm i`
|
4. `npm i`
|
||||||
5. `npm run build`
|
5. `npm run build`
|
||||||
6. `npm run init`
|
6. `npm run migrate`
|
||||||
7. `npm run migrate`
|
7. master ブランチに戻す
|
||||||
8. master ブランチに戻す
|
8. enjoy
|
||||||
9. enjoy
|
|
||||||
|
|
||||||
10.100.0
|
10.100.0
|
||||||
----------
|
----------
|
||||||
|
|
|
@ -219,8 +219,6 @@ const user = await Users.findOne(userId).then(ensure);
|
||||||
```
|
```
|
||||||
|
|
||||||
### Migration作成方法
|
### Migration作成方法
|
||||||
コードの変更をした後、`ormconfig.json`(`npm run ormconfig`で生成)を用意し、
|
|
||||||
|
|
||||||
```
|
```
|
||||||
npm i -g ts-node
|
npm i -g ts-node
|
||||||
ts-node ./node_modules/typeorm/cli.js migration:generate -n 変更の名前
|
ts-node ./node_modules/typeorm/cli.js migration:generate -n 変更の名前
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import * as fs from 'fs';
|
const config = require('./built/config').default;
|
||||||
import config from './config';
|
const entities = require('./built/db/postgre').entities;
|
||||||
|
|
||||||
const json = {
|
module.exports = {
|
||||||
type: 'postgres',
|
type: 'postgres',
|
||||||
host: config.db.host,
|
host: config.db.host,
|
||||||
port: config.db.port,
|
port: config.db.port,
|
||||||
|
@ -9,11 +9,9 @@ const json = {
|
||||||
password: config.db.pass,
|
password: config.db.pass,
|
||||||
database: config.db.db,
|
database: config.db.db,
|
||||||
extra: config.db.extra,
|
extra: config.db.extra,
|
||||||
entities: ['src/models/entities/*.ts'],
|
entities: entities,
|
||||||
migrations: ['migration/*.ts'],
|
migrations: ['migration/*.ts'],
|
||||||
cli: {
|
cli: {
|
||||||
migrationsDir: 'migration'
|
migrationsDir: 'migration'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fs.writeFileSync('ormconfig.json', JSON.stringify(json));
|
|
|
@ -11,9 +11,9 @@
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node ./index.js",
|
"start": "node ./index.js",
|
||||||
"init": "node ./built/init.js",
|
"init": "npm run migrate",
|
||||||
"ormconfig": "node ./built/ormconfig.js",
|
"ormconfig": "node ./built/ormconfig.js",
|
||||||
"migrate": "npm run ormconfig && ts-node ./node_modules/typeorm/cli.js migration:run",
|
"migrate": "ts-node ./node_modules/typeorm/cli.js migration:run",
|
||||||
"migrateandstart": "npm run migrate && npm run start",
|
"migrateandstart": "npm run migrate && npm run start",
|
||||||
"build": "webpack && gulp build",
|
"build": "webpack && gulp build",
|
||||||
"webpack": "webpack",
|
"webpack": "webpack",
|
||||||
|
|
|
@ -80,37 +80,7 @@ class MyCustomLogger implements Logger {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function initDb(justBorrow = false, sync = false, log = false) {
|
export const entities = [
|
||||||
try {
|
|
||||||
const conn = getConnection();
|
|
||||||
return Promise.resolve(conn);
|
|
||||||
} catch (e) {}
|
|
||||||
|
|
||||||
return createConnection({
|
|
||||||
type: 'postgres',
|
|
||||||
host: config.db.host,
|
|
||||||
port: config.db.port,
|
|
||||||
username: config.db.user,
|
|
||||||
password: config.db.pass,
|
|
||||||
database: config.db.db,
|
|
||||||
extra: config.db.extra,
|
|
||||||
synchronize: process.env.NODE_ENV === 'test' || sync,
|
|
||||||
dropSchema: process.env.NODE_ENV === 'test' && !justBorrow,
|
|
||||||
cache: !config.db.disableCache ? {
|
|
||||||
type: 'redis',
|
|
||||||
options: {
|
|
||||||
host: config.redis.host,
|
|
||||||
port: config.redis.port,
|
|
||||||
options:{
|
|
||||||
password: config.redis.pass,
|
|
||||||
prefix: config.redis.prefix,
|
|
||||||
db: config.redis.db || 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} : false,
|
|
||||||
logging: log,
|
|
||||||
logger: log ? new MyCustomLogger() : undefined,
|
|
||||||
entities: [
|
|
||||||
Meta,
|
Meta,
|
||||||
Instance,
|
Instance,
|
||||||
App,
|
App,
|
||||||
|
@ -153,6 +123,38 @@ export function initDb(justBorrow = false, sync = false, log = false) {
|
||||||
ReversiGame,
|
ReversiGame,
|
||||||
ReversiMatching,
|
ReversiMatching,
|
||||||
...charts as any
|
...charts as any
|
||||||
]
|
];
|
||||||
|
|
||||||
|
export function initDb(justBorrow = false, sync = false, log = false) {
|
||||||
|
try {
|
||||||
|
const conn = getConnection();
|
||||||
|
return Promise.resolve(conn);
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
return createConnection({
|
||||||
|
type: 'postgres',
|
||||||
|
host: config.db.host,
|
||||||
|
port: config.db.port,
|
||||||
|
username: config.db.user,
|
||||||
|
password: config.db.pass,
|
||||||
|
database: config.db.db,
|
||||||
|
extra: config.db.extra,
|
||||||
|
synchronize: process.env.NODE_ENV === 'test' || sync,
|
||||||
|
dropSchema: process.env.NODE_ENV === 'test' && !justBorrow,
|
||||||
|
cache: !config.db.disableCache ? {
|
||||||
|
type: 'redis',
|
||||||
|
options: {
|
||||||
|
host: config.redis.host,
|
||||||
|
port: config.redis.port,
|
||||||
|
options:{
|
||||||
|
password: config.redis.pass,
|
||||||
|
prefix: config.redis.prefix,
|
||||||
|
db: config.redis.db || 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} : false,
|
||||||
|
logging: log,
|
||||||
|
logger: log ? new MyCustomLogger() : undefined,
|
||||||
|
entities: entities
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue