From c8f549e5628ccdf634f99bf157c3ea64c4d2e838 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 14 May 2019 23:54:39 +0900 Subject: [PATCH] Resolve #4925 --- CHANGELOG.md | 23 ++--------------------- CONTRIBUTING.md | 2 +- package.json | 2 ++ src/ormconfig.ts | 18 ++++++++++++++++++ 4 files changed, 23 insertions(+), 22 deletions(-) create mode 100644 src/ormconfig.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 55e1f900b..795bef150 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,32 +8,13 @@ If you encounter any problems with updating, please try the following: Migration ------------------------------ #### 1 -`ormconfig.json`という名前で、Misskeyのインストール場所(package.jsonとかがあるディレクトリ)に新たなファイルを作る。中身は次のようにします: -``` json -{ - "type": "postgres", - "host": "PostgreSQLのホスト", - "port": 5432, - "username": "PostgreSQLのユーザー名", - "password": "PostgreSQLのパスワード", - "database": "PostgreSQLのデータベース名", - "entities": ["src/models/entities/*.ts"], - "migrations": ["migration/*.ts"], - "cli": { - "migrationsDir": "migration" - } -} -``` -上記の各種PostgreSQLの設定(ポートも)は、設定ファイルに書いてあるものをコピーしてください。 - -#### 2 ``` npm i -g ts-node ``` -#### 3 +#### 2 ``` -ts-node ./node_modules/typeorm/cli.js migration:run +npm run migrate ``` How to migrate to v11 from v10 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c0c72c470..ace822c63 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -199,7 +199,7 @@ const user = await Users.findOne(userId).then(ensure); ``` ### Migration作成方法 -コードの変更をした後、`ormconfig.json`(書き方はCONTRIBUTING.mdを参照)を用意し、 +コードの変更をした後、`ormconfig.json`(`npm run ormconfig`で生成)を用意し、 ``` npm i -g ts-node diff --git a/package.json b/package.json index 71fa1509e..5301118fd 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,8 @@ "scripts": { "start": "node ./index.js", "init": "node ./built/init.js", + "ormconfig": "node ./built/ormconfig.js", + "migrate": "npm run ormconfig && ts-node ./node_modules/typeorm/cli.js migration:run", "build": "webpack && gulp build", "webpack": "webpack", "watch": "webpack --watch", diff --git a/src/ormconfig.ts b/src/ormconfig.ts new file mode 100644 index 000000000..91f33181f --- /dev/null +++ b/src/ormconfig.ts @@ -0,0 +1,18 @@ +import * as fs from 'fs'; +import config from './config'; + +const json = { + type: 'postgres', + host: config.db.host, + port: config.db.port, + username: config.db.user, + password: config.db.pass, + database: config.db.db, + entities: ['src/models/entities/*.ts'], + migrations: ['migration/*.ts'], + cli: { + migrationsDir: 'migration' + } +}; + +fs.writeFileSync('ormconfig.json', JSON.stringify(json));