From bb2d76ffa362dd0fb032d5faf975661b1c9a26f7 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 29 Jun 2019 23:12:00 +0900 Subject: [PATCH] Fix #4926 --- CHANGELOG.md | 7 ++- CONTRIBUTING.md | 2 - src/ormconfig.ts => ormconfig.js | 10 ++-- package.json | 4 +- src/db/postgre.ts | 90 ++++++++++++++++---------------- 5 files changed, 55 insertions(+), 58 deletions(-) rename src/ormconfig.ts => ormconfig.js (58%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a0193fa1..ee64b1d55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -588,10 +588,9 @@ mongodb: 3. migration ブランチに切り替え 4. `npm i` 5. `npm run build` -6. `npm run init` -7. `npm run migrate` -8. master ブランチに戻す -9. enjoy +6. `npm run migrate` +7. master ブランチに戻す +8. enjoy 10.100.0 ---------- diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 179cf5304..894122b04 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -219,8 +219,6 @@ const user = await Users.findOne(userId).then(ensure); ``` ### Migration作成方法 -コードの変更をした後、`ormconfig.json`(`npm run ormconfig`で生成)を用意し、 - ``` npm i -g ts-node ts-node ./node_modules/typeorm/cli.js migration:generate -n 変更の名前 diff --git a/src/ormconfig.ts b/ormconfig.js similarity index 58% rename from src/ormconfig.ts rename to ormconfig.js index 6b7297b2c..8a0196947 100644 --- a/src/ormconfig.ts +++ b/ormconfig.js @@ -1,7 +1,7 @@ -import * as fs from 'fs'; -import config from './config'; +const config = require('./built/config').default; +const entities = require('./built/db/postgre').entities; -const json = { +module.exports = { type: 'postgres', host: config.db.host, port: config.db.port, @@ -9,11 +9,9 @@ const json = { password: config.db.pass, database: config.db.db, extra: config.db.extra, - entities: ['src/models/entities/*.ts'], + entities: entities, migrations: ['migration/*.ts'], cli: { migrationsDir: 'migration' } }; - -fs.writeFileSync('ormconfig.json', JSON.stringify(json)); diff --git a/package.json b/package.json index 7943d8187..3e21a9da5 100644 --- a/package.json +++ b/package.json @@ -11,9 +11,9 @@ "private": true, "scripts": { "start": "node ./index.js", - "init": "node ./built/init.js", + "init": "npm run migrate", "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", "build": "webpack && gulp build", "webpack": "webpack", diff --git a/src/db/postgre.ts b/src/db/postgre.ts index c91cd8e1d..925e3fcbf 100644 --- a/src/db/postgre.ts +++ b/src/db/postgre.ts @@ -80,6 +80,51 @@ class MyCustomLogger implements Logger { } } +export const entities = [ + Meta, + Instance, + App, + AuthSession, + AccessToken, + User, + UserProfile, + UserKeypair, + UserPublickey, + UserList, + UserListJoining, + UserGroup, + UserGroupJoining, + UserGroupInvite, + UserNotePining, + Following, + FollowRequest, + Muting, + Blocking, + Note, + NoteFavorite, + NoteReaction, + NoteWatching, + NoteUnread, + Page, + PageLike, + Log, + DriveFile, + DriveFolder, + Poll, + PollVote, + Notification, + Emoji, + Hashtag, + SwSubscription, + AbuseUserReport, + RegistrationTicket, + MessagingMessage, + Signin, + ReversiGame, + ReversiMatching, + ...charts as any +]; + export function initDb(justBorrow = false, sync = false, log = false) { try { const conn = getConnection(); @@ -110,49 +155,6 @@ export function initDb(justBorrow = false, sync = false, log = false) { } : false, logging: log, logger: log ? new MyCustomLogger() : undefined, - entities: [ - Meta, - Instance, - App, - AuthSession, - AccessToken, - User, - UserProfile, - UserKeypair, - UserPublickey, - UserList, - UserListJoining, - UserGroup, - UserGroupJoining, - UserGroupInvite, - UserNotePining, - Following, - FollowRequest, - Muting, - Blocking, - Note, - NoteFavorite, - NoteReaction, - NoteWatching, - NoteUnread, - Page, - PageLike, - Log, - DriveFile, - DriveFolder, - Poll, - PollVote, - Notification, - Emoji, - Hashtag, - SwSubscription, - AbuseUserReport, - RegistrationTicket, - MessagingMessage, - Signin, - ReversiGame, - ReversiMatching, - ...charts as any - ] + entities: entities }); }