fix typeorm commands + add documentation about creating migrations

This commit is contained in:
sam 2023-07-21 02:54:50 +02:00
parent 8b40d7e042
commit 40ad12c924
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
3 changed files with 13 additions and 3 deletions

View file

@ -16,6 +16,15 @@ Consider all environment variables required.
- Formatting: `pnpm format` - Formatting: `pnpm format`
- Linting (if you don't have an ESLint plugin): `pnpm format` - Linting (if you don't have an ESLint plugin): `pnpm format`
## Creating migrations
Creating migrations is a little awkward because TypeORM expects `ts-node`, which uses `tsc`.
To create a migration, first run `pnpm build`,
then run `pnpm typeorm migration:generate -p -d ./dist/db/index.js ./src/db/migrations/<name>`,
replacing `<name>` with the name of the migration you're creating.
Then rename the created file to end in `.js` and remove the TypeScript-specific code from it.
(Yes, this is incredibly janky, but it works, and it only needs to be done once per migration, actually migrating works flawlessly)
## License ## License
Mercury is licensed under the GNU Affero General Public License, version 3 **only**. Mercury is licensed under the GNU Affero General Public License, version 3 **only**.

View file

@ -14,8 +14,8 @@
"watch:dev": "nodemon --watch \"dist/**/*\" -e js ./dist/index.js", "watch:dev": "nodemon --watch \"dist/**/*\" -e js ./dist/index.js",
"format": "prettier -w", "format": "prettier -w",
"lint": "eslint src/", "lint": "eslint src/",
"typeorm": "typeorm-ts-node-esm", "typeorm": "typeorm",
"migrate": "typeorm-ts-node-esm migration:run -d ./src/db/index.ts" "migrate": "pnpm build && typeorm migration:run -d ./dist/db/index.js"
}, },
"dependencies": { "dependencies": {
"argon2": "^0.30.3", "argon2": "^0.30.3",

View file

@ -21,5 +21,6 @@
"~/*": ["./src/*"], "~/*": ["./src/*"],
"~entities/*": ["./src/db/entities/*"] "~entities/*": ["./src/db/entities/*"]
} }
} },
"exclude": ["./dist/"]
} }