-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
In order to get rid of mongoose and switch to mikro-orm migration, it was necessary to upgrade mikro-orm and remove old migrations.
- Loading branch information
1 parent
d2baaef
commit 53c02d8
Showing
72 changed files
with
1,857 additions
and
8,157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,6 @@ jobs: | |
uses: actions/dependency-review-action@v3 | ||
with: | ||
allow-licenses: AGPL-3.0-only, LGPL-3.0, MIT, Apache-2.0, BSD-2-Clause, BSD-3-Clause, ISC, X11, 0BSD, GPL-3.0, Unlicense | ||
# temporarily ignore dependency error for upgrade mongodb 4.9 to 4.11, remove when mikroORM is upgraded to 5.9 | ||
# temporarily ignore dependency error sprintf-js 1.0.3, remove when it gets upgraded to 1.1.3 | ||
allow-dependencies-licenses: 'pkg:npm/[email protected]' | ||
allow-ghsas: 'GHSA-vxvm-qww3-2fh7' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,9 @@ on: | |
pull_request: | ||
branches: [ main ] | ||
|
||
env: | ||
MONGODB_VERSION: 4.4 | ||
NODE_VERSION: '18' | ||
jobs: | ||
migration: | ||
runs-on: ubuntu-latest | ||
|
@@ -14,21 +17,13 @@ jobs: | |
timeout-minutes: 5 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: check all migrations are up in database seed | ||
run: test $(grep "\"down\"" ./backup/setup/migrations.json -c) -eq 0 | ||
- name: mongodb setup | ||
uses: supercharge/[email protected] | ||
- name: setup | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '16' | ||
node-version: ${{ env.NODE_VERSION }} | ||
- run: npm ci | ||
- run: npm run setup | ||
- name: check migrations.json formatting | ||
run: | | ||
npm run migration-persist | ||
git diff --exit-code backup/** | ||
- name: check filesystem migrations have been added to database | ||
run: npm run migration-list | ||
- name: check migrations in database exist in filesystem | ||
run: npm run migration-prune | ||
- run: npm run setup:db:seed | ||
- name: check no pending migrations (migration is in db) | ||
run: test $(npx mikro-orm migration:pending | grep -c "Migration") -eq 0 | ||
This comment has been minimized.
Sorry, something went wrong. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { MikroOrmModuleSyncOptions } from '@mikro-orm/nestjs/typings'; | ||
import { ALL_ENTITIES } from '@shared/domain/entity'; | ||
import { FileEntity } from '@modules/files/entity'; | ||
import { FileRecord } from '@modules/files-storage/entity'; | ||
import path from 'path'; | ||
import { DB_PASSWORD, DB_URL, DB_USERNAME } from './index'; | ||
|
||
const migrationsPath = path.resolve(__dirname, '..', 'migrations', 'mikro-orm'); | ||
|
||
export const mikroOrmCliConfig: MikroOrmModuleSyncOptions = { | ||
// TODO repeats server module definitions | ||
type: 'mongo', | ||
clientUrl: DB_URL, | ||
password: DB_PASSWORD, | ||
user: DB_USERNAME, | ||
entities: [...ALL_ENTITIES, FileEntity, FileRecord], | ||
allowGlobalContext: true, | ||
/* | ||
findOneOrFailHandler: (entityName: string, where: Dictionary | IPrimaryKey) => | ||
new NotFoundException(`The requested ${entityName}: ${JSON.stringify(where)} has not been found.`), | ||
*/ | ||
migrations: { | ||
tableName: 'migrations', // name of database table with log of executed transactions | ||
path: migrationsPath, // path to the folder with migrations | ||
pathTs: migrationsPath, // path to the folder with TS migrations (if used, we should put path to compiled files in `path`) | ||
glob: '!(*.d).{js,ts}', // how to match migration files (all .js and .ts files, but not .d.ts) | ||
transactional: false, // wrap each migration in a transaction | ||
disableForeignKeys: true, // wrap statements with `set foreign_key_checks = 0` or equivalent | ||
allOrNothing: false, // wrap all migrations in master transaction | ||
dropTables: false, // allow to disable table dropping | ||
safe: false, // allow to disable table and column dropping | ||
snapshot: true, // save snapshot when creating new migrations | ||
emit: 'ts', // migration generation mode | ||
// generator: TSMigrationGenerator, // migration generator, e.g. to allow custom formatting | ||
}, | ||
}; | ||
|
||
export default mikroOrmCliConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
apps/server/src/migrations/mikro-orm/Migration20240108145519.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Migration } from '@mikro-orm/migrations-mongodb'; | ||
|
||
/* | ||
* cleanup old migration records from db | ||
*/ | ||
export class Migration20240108111130 extends Migration { | ||
async up(): Promise<void> { | ||
const { deletedCount } = await this.getCollection('migrations').deleteMany({}, { session: this.ctx }); | ||
console.log(`removed ${deletedCount} records`); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/require-await | ||
async down(): Promise<void> { | ||
// do nothing | ||
console.error(`Migration down not implemented. You might need to restore database from backup!`); | ||
} | ||
} |
Oops, something went wrong.
do not use npx!