Skip to content

Commit

Permalink
default migration file number format changed to dateTime
Browse files Browse the repository at this point in the history
  • Loading branch information
okv committed Jun 9, 2020
1 parent 5432bd7 commit d833131
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and `MigrationManager` class)
- Builtin TypeScript migration template file

### Changed
- *Breaking change:* Default migration file number format changed to "dateTime"
- *Breaking change:* Default migration template now uses `async` functions
- *Breaking change:* `MigrationManager` `onSkipMigration` event reasons are
renamed: canNotMigrateAlreadyExecuted -> cannotMigrateAlreadyExecuted,
Expand Down
26 changes: 9 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,25 +191,17 @@ or you can use a special adapter for database (see [adapters](#adapters) section
#### Migration file number format
The default format for migration file names is to prepend a number to the
filename which is incremented with every new file. This creates migration files
such as "migrations/1_doSomething.js", "migrations/2_doSomethingElse.js".
East supports following migration file number formats (`migrationNumberFormat`
option):
If you prefer your files to be created with a date-time instead of sequential
numbers, you can set the `migrationNumberFormat` configuration parameter in
your `.eastrc` to "dateTime":
* "dateTime" - will create migration files with date-time prefix in `YYYYMMDDhhmmss`
format (e.g. "migrations/20190720172730_doSomething.js")
* "sequentialNumber" - prepend a number to the filename which is incremented
with every new file. This creates migration files such as
"migrations/1_doSomething.js", "migrations/2_doSomethingElse.js".
```json
{
"migrationNumberFormat": "dateTime"
}
```
This will create migration files with date-time prefix in `YYYYMMDDhhmmss`
format (e.g. "migrations/20190720172730_doSomething.js").
For the default behavior, you can omit the `migrationNumberFormat`
configuration option or set it to:
Default format is "dateTime", you can change `migrationNumberFormat` via your
`.eastrc` e.g.:
```json
{
Expand Down
2 changes: 1 addition & 1 deletion lib/migrator/methods/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = function configure(params = {}) {
// db url
url: null,
// number format for migration filenames
migrationNumberFormat: 'sequentialNumber',
migrationNumberFormat: 'dateTime',
trace: false,
// whether to load or not config file
loadConfig: _(params).has('loadConfig') ? params.loadConfig : true,
Expand Down
16 changes: 7 additions & 9 deletions test/01-migrator/create/withDateTimeMigrationNumberFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ describe('migrator create with date time migration number format', () => {
return Promise.resolve()
.then(() => {
return testUtils.createEnv({
migratorParams: {init: true, connect: true}
migratorParams: {
init: true,
connect: true,
configureParams: {
migrationNumberFormat: 'dateTime'
}
}
});
})
.then((createdTestEnv) => {
Expand All @@ -29,14 +35,6 @@ describe('migrator create with date time migration number format', () => {

after(() => testUtils.destroyEnv(testEnv));

before(() => {
migrator.params.migrationNumberFormat = 'dateTime';
});

after(() => {
migrator.params.migrationNumberFormat = 'sequentialNumber';
});

it('should create migrations without errors', () => {
return Promise.resolve()
.then(() => testUtils.createMigrations({migrator, baseNames}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ describe('migrator create with sequential migration number format', () => {
return Promise.resolve()
.then(() => {
return testUtils.createEnv({
migratorParams: {init: true, connect: true}
migratorParams: {
init: true,
connect: true,
configureParams: {
migrationNumberFormat: 'sequentialNumber'
}
}
});
})
.then((createdTestEnv) => {
Expand Down
8 changes: 7 additions & 1 deletion testUtils/createEnv.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ module.exports = (params = {}) => {
.then(() => {
const migrationsDir = pathUtils.join(dir, 'migrations');

return createEastrc({dir, configParams: {dir: migrationsDir}});
return createEastrc({
dir,
configParams: {
dir: migrationsDir,
migrationNumberFormat: 'sequentialNumber'
}
});
})
.then((createdConfigPath) => {
configPath = createdConfigPath;
Expand Down
5 changes: 4 additions & 1 deletion testUtils/createMigrator.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const _ = require('underscore');
const Migrator = require('../lib/migrator');
const removeMigratorDir = require('./removeMigratorDir');

Expand All @@ -10,7 +11,9 @@ module.exports = ({
const migrator = new Migrator();

return Promise.resolve()
.then(() => migrator.configure(configureParams))
.then(() => migrator.configure(_({
migrationNumberFormat: 'sequentialNumber'
}).extend(configureParams)))
// always connect migrator coz `removeDirBefore` makes unmark executed
.then(() => migrator.connect())
.then(() => {
Expand Down

0 comments on commit d833131

Please sign in to comment.