-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): migrations and config updates (#157)
- Loading branch information
1 parent
9121c74
commit 9428bfc
Showing
26 changed files
with
212 additions
and
198 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
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
13 changes: 13 additions & 0 deletions
13
examples/2-complex-example/db/migrations/1562027331912-UserModel.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,13 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class UserModel1562027331912 implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<any> { | ||
await queryRunner.query( | ||
`CREATE TABLE "users" ("id" character varying NOT NULL, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "created_by_id" character varying NOT NULL, "updated_at" TIMESTAMP DEFAULT now(), "updated_by_id" character varying, "deleted_at" TIMESTAMP, "deleted_by_id" character varying, "version" integer NOT NULL, "first_name" character varying(30) NOT NULL, "last_name" character varying(50) NOT NULL, "string_enum_field" character varying NOT NULL, "email" character varying NOT NULL, "nick_name" character varying(30), "private_field" character varying, "json_field" jsonb, CONSTRAINT "UQ_97672ac88f789774dd47f7c8be3" UNIQUE ("email"), CONSTRAINT "UQ_8b0d982b1bfea7d0518840535b2" UNIQUE ("first_name", "string_enum_field"), CONSTRAINT "PK_a3ffb1c0c8416b9fc6f907b7433" PRIMARY KEY ("id"))` | ||
); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<any> { | ||
await queryRunner.query(`DROP TABLE "users"`); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,35 +1,3 @@ | ||
import { getBaseConfig } from '../../../src'; | ||
|
||
import { | ||
getDatabaseName, | ||
getDatabaseEntityPaths, | ||
getDatabaseHost, | ||
getDatabaseLoggingLevel, | ||
getDatabaseMigrationPaths, | ||
getDatabaseSubscriberPaths, | ||
getDatabasePassword, | ||
getDatabasePort, | ||
shouldSchronizeDatabaseSchema, | ||
getDatabaseType, | ||
getDatabaseUsername, | ||
SnakeNamingStrategy } from '../../../src'; | ||
|
||
module.exports = { | ||
cli: { | ||
entitiesDir: 'src/models', | ||
migrationsDir: 'db/migrations', | ||
subscribersDir: 'src/subscribers' | ||
}, | ||
database: getDatabaseName(), | ||
entities: getDatabaseEntityPaths(), | ||
host: getDatabaseHost(), | ||
logger: 'advanced-console', | ||
logging: getDatabaseLoggingLevel(), | ||
migrations: getDatabaseMigrationPaths(), | ||
namingStrategy: new SnakeNamingStrategy(), | ||
password: getDatabasePassword(), | ||
port: getDatabasePort(), | ||
subscribers: getDatabaseSubscriberPaths(), | ||
synchronize: shouldSchronizeDatabaseSchema(), | ||
type: getDatabaseType(), | ||
username: getDatabaseUsername() | ||
}; | ||
module.exports = getBaseConfig(); |
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 |
---|---|---|
@@ -1,35 +1,4 @@ | ||
|
||
import { | ||
getDatabaseName, | ||
getDatabaseEntityPaths, | ||
getDatabaseHost, | ||
getDatabaseLoggingLevel, | ||
getDatabaseMigrationPaths, | ||
getDatabaseSubscriberPaths, | ||
getDatabasePassword, | ||
getDatabasePort, | ||
shouldSchronizeDatabaseSchema, | ||
getDatabaseType, | ||
getDatabaseUsername, | ||
SnakeNamingStrategy } from '../../../src'; | ||
import { getBaseConfig } from '../../../src'; | ||
|
||
module.exports = { | ||
cli: { | ||
entitiesDir: 'src/models', | ||
migrationsDir: 'db/migrations', | ||
subscribersDir: 'src/subscribers' | ||
}, | ||
database: getDatabaseName(), | ||
entities: getDatabaseEntityPaths(), | ||
host: getDatabaseHost(), | ||
logger: 'advanced-console', | ||
logging: getDatabaseLoggingLevel(), | ||
migrations: getDatabaseMigrationPaths(), | ||
namingStrategy: new SnakeNamingStrategy(), | ||
password: getDatabasePassword(), | ||
port: getDatabasePort(), | ||
subscribers: getDatabaseSubscriberPaths(), | ||
synchronize: shouldSchronizeDatabaseSchema(), | ||
type: getDatabaseType(), | ||
username: getDatabaseUsername() | ||
}; | ||
module.exports = getBaseConfig(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// "db:migration:generate": "yarn typeorm:cli migration:generate -n migration1", | ||
// ts-node ./node_modules/.bin/typeorm -f ./generated/ormconfig.ts | ||
|
||
import { WarthogGluegunToolbox } from '../types'; | ||
|
||
export default { | ||
name: 'db:migrate', | ||
run: async (toolbox: WarthogGluegunToolbox) => { | ||
const { | ||
db, | ||
print: { error } | ||
} = toolbox; | ||
|
||
try { | ||
await db.migrate(); | ||
} catch (e) { | ||
error(e); | ||
} | ||
} | ||
}; |
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,26 @@ | ||
// "db:migration:generate": "yarn typeorm:cli migration:generate -n migration1", | ||
// ts-node ./node_modules/.bin/typeorm -f ./generated/ormconfig.ts | ||
|
||
import { WarthogGluegunToolbox } from '../types'; | ||
|
||
export default { | ||
name: 'db:migrate:generate', | ||
run: async (toolbox: WarthogGluegunToolbox) => { | ||
const { | ||
db, | ||
parameters: { options }, | ||
print: { error } | ||
} = toolbox; | ||
|
||
if (!options.name) { | ||
error('"name" option is required'); | ||
process.exit(1); | ||
} | ||
|
||
try { | ||
await db.generateMigration(options.name); | ||
} catch (e) { | ||
error(e); | ||
} | ||
} | ||
}; |
Oops, something went wrong.