-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
close #62 Add command to create a new migration file
- Loading branch information
Showing
4 changed files
with
45 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env node | ||
|
||
let debug | ||
try { | ||
debug = require('debug')('migrate:make') | ||
} catch (e) { | ||
debug = console.log | ||
} | ||
|
||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
let file = process.argv[2] | ||
if (!file) { | ||
debug('name for the migration needs to be given as argument') | ||
process.exit(1) | ||
} | ||
if (!file.includes('.')) { | ||
file += '.sql' | ||
} | ||
if (!file.endsWith('.js') && !file.endsWith('.sql')) { | ||
debug('file ending needs to be ".js" or ".sql" (default if no file ending is given)') | ||
process.exit(1) | ||
} | ||
|
||
const currentUnixTimestamp = Math.floor(Date.now() / 1000) | ||
file = `${currentUnixTimestamp}_${file}` | ||
|
||
const directory = path.join(process.cwd(), 'migrations') | ||
if (file.endsWith('.js')) { | ||
fs.copyFileSync(path.join(__dirname, 'templates/migration.js'), path.join(directory, file)) | ||
} | ||
if (file.endsWith('.sql')) { | ||
fs.copyFileSync(path.join(__dirname, 'templates/migration.sql'), path.join(directory, file)) | ||
} | ||
|
||
debug(`file "${file}" is created in the migrations directory`) |
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,3 @@ | ||
module.exports = async sql => sql.query( | ||
sql`` | ||
) |
Empty file.
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