Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 52 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,29 +191,64 @@ services:
```

## Migrations
Custom scripts have been added to streamline and simplify handling migrations with two database contexts.
```bash
# each script comes in sqlite | postgres | all variations
# scripts ending with "all" perform the action on both databases
# Note: due to configuration differences, run build before generating sqlite migrations!

# create a migration generated from the entity schema
$ npm run migration:generate:<sqlite|postgres|all>
Migrations are managed via the mikro-orm CLI.

# create a blank migration
$ npm run migration:create:<sqlite|postgres|all>
Config values are available via the following:

# apply migrations
$ npm run migration:up:<sqlite|postgres|all>
```bash
# Note: due to configuration differences, run build before generating sqlite migrations!

# revert most recently applied migration
$ npm run migration:down:<sqlite|postgres|all>
# Create a Sqlite Migration
$ npx mikro-orm migration:create --config mikro-orm.sqlite.cli-config.ts

# lists pending queries to executed based on the entity schema
$ npm run migration:log:all
# Create a Postgresql Migration
$ npx mikro-orm migration:create --config mikro-orm.postgres.cli-config.ts
```

# displays what migrations have been applied to the databases
$ npm run migration:show:all
```bash
$ npx mikro-orm
Usage: mikro-orm <command> [options]

Commands:
mikro-orm cache:clear Clear metadata cache
mikro-orm cache:generate Generate metadata cache
mikro-orm generate-entities Generate entities based on current database
schema
mikro-orm database:create Create your database if it does not exist
mikro-orm database:import <file> Imports the SQL file to the database
mikro-orm seeder:run Seed the database using the seeder class
mikro-orm seeder:create <seeder> Create a new seeder class
mikro-orm schema:create Create database schema based on current
metadata
mikro-orm schema:drop Drop database schema based on current
metadata
mikro-orm schema:update Update database schema based on current
metadata
mikro-orm schema:fresh Drop and recreate database schema based on
current metadata
mikro-orm migration:create Create new migration with current schema
diff
mikro-orm migration:up Migrate up to the latest version
mikro-orm migration:down Migrate one step down
mikro-orm migration:list List all executed migrations
mikro-orm migration:check Check if migrations are needed. Useful for
bash scripts.
mikro-orm migration:pending List all pending migrations
mikro-orm migration:fresh Clear the database and rerun all migrations
mikro-orm debug Debug CLI configuration

Options:
--config Set path to the ORM configuration file [array]
--contextName, --context Set name of config to load out of the ORM
configuration file. Used when config file
exports an array or a function
[string] [default: "default"]
-v, --version Show version number [boolean]
-h, --help Show help [boolean]

Examples:
mikro-orm schema:update --run Runs schema synchronization
```

## Web Push Notifications
Expand Down
23 changes: 23 additions & 0 deletions mikro-orm.postgres.cli-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Options } from '@mikro-orm/core';
import { Migrator } from '@mikro-orm/migrations';
import { PostgreSqlDriver } from '@mikro-orm/postgresql';

export default {
name: 'postgre',
driver: PostgreSqlDriver,
extensions: [Migrator],
host: 'localhost',
port: 5432,
user: 'postgres',
// default credential used for cli migration generation against a local debugging instance of postgres
// This is overriden in application startup in the mikro-orm module initiation with configuration values
password: 'Password123',
dbName: 'postgres',
entities: ['src/dal/entity/**/*.*.*'],
migrations: {
path: 'src/dal/migrations/postgres',
pattern: /^[\w-]+\d+|\d\.ts$/,
transactional: true,
},
debug: true,
} as Options;
19 changes: 0 additions & 19 deletions mikro-orm.postgres.config.js

This file was deleted.

15 changes: 8 additions & 7 deletions mikro-orm.sqlite.config.js → mikro-orm.sqlite.cli-config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
const mikroOrmSqliteConfig = {
type: 'sqlite',
contextName: 'sqliteConfig',
import { BetterSqliteDriver } from '@mikro-orm/better-sqlite';
import { Options } from '@mikro-orm/core';
import { Migrator } from '@mikro-orm/migrations';

export default {
name: 'sqlite',
driver: BetterSqliteDriver,
extensions: [Migrator],
dbName: './data/sqlite3.db',
entities: ['./src/dal/entity/**/*.*.*'],
entitiesTs: ['./dist/dal/entity/**/*.*.*'],
migrations: {
path: './dist/dal/migrations/sqlite',
pathTs: './src/dal/migrations/sqlite',
transactional: true,
snapshot: false // see https://github.com/mikro-orm/mikro-orm/issues/2710
},
debug: true,
};

module.exports = mikroOrmSqliteConfig;
} as Options;
Loading
Loading