Skip to content

Commit

Permalink
Use migrations/sample-migration.js as sample content if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
tennox committed Jul 20, 2019
1 parent 296c44d commit 0bffe1b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ module.exports = {
};
````

#### Overriding the sample migration
To override the content of the sample migration that will be created by the `create` command,
create a file **`sample-migration.js`** in the migrations directory.

### Checking the status of the migrations
At any time, you can check which migrations are applied (or not)

Expand Down
15 changes: 13 additions & 2 deletions lib/actions/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,22 @@ module.exports = async description => {
throw new Error("Missing parameter: description");
}
await migrationsDir.shouldExist();
const source = path.join(__dirname, "../../samples/migration.js");
const migrationsDirPath = await migrationsDir.resolve();

// Check if there is a 'sample-migration.js' file in migrations dir - if there is, use that
const migrationDirSample = path.join(migrationsDirPath, 'sample-migration.js');
let source;
try {
await fs.access(migrationDirSample); // check if file exists
source = migrationDirSample;
} catch (e) {
source = path.join(__dirname, "../../samples/migration.js");
}

const filename = `${date.nowAsString()}-${description
.split(" ")
.join("_")}.js`;
const destination = path.join(await migrationsDir.resolve(), filename);
const destination = path.join(migrationsDirPath, filename);
await fs.copy(source, destination);
return filename;
};

0 comments on commit 0bffe1b

Please sign in to comment.