node-pg-migrate
Advanced tools
Comparing version 5.0.2 to 5.1.0
# Change Log | ||
## [5.1.0](2020-06-05) | ||
### Added | ||
- Ability to specify own template file [#642](https://github.com/salsita/node-pg-migrate/pull/642) | ||
## [5.0.2](2020-06-05) | ||
@@ -4,0 +10,0 @@ |
@@ -16,4 +16,14 @@ import { DBConnection } from './db'; | ||
} | ||
export interface CreateOptionsTemplate { | ||
templateFileName: string; | ||
} | ||
export interface CreateOptionsDefault { | ||
language?: 'js' | 'ts' | 'sql'; | ||
ignorePattern?: string; | ||
} | ||
export declare type CreateOptions = { | ||
filenameFormat?: FilenameFormat; | ||
} & (CreateOptionsTemplate | CreateOptionsDefault); | ||
export declare class Migration implements RunMigration { | ||
static create(name: string, directory: string, language?: 'js' | 'ts' | 'sql', ignorePattern?: string, filenameFormat?: FilenameFormat): Promise<string>; | ||
static create(name: string, directory: string, _language?: 'js' | 'ts' | 'sql' | CreateOptions, _ignorePattern?: string, _filenameFormat?: FilenameFormat): Promise<string>; | ||
readonly db: DBConnection; | ||
@@ -20,0 +30,0 @@ readonly path: string; |
@@ -23,6 +23,7 @@ "use strict"; | ||
}; | ||
const getSuffixFromFileName = (fileName) => path_1.default.extname(fileName).substr(1); | ||
const getLastSuffix = async (dir, ignorePattern) => { | ||
try { | ||
const files = await exports.loadMigrationFiles(dir, ignorePattern); | ||
return files.length > 0 ? path_1.default.extname(files[files.length - 1]).substr(1) : undefined; | ||
return files.length > 0 ? getSuffixFromFileName(files[files.length - 1]) : undefined; | ||
} | ||
@@ -53,2 +54,3 @@ catch (err) { | ||
}; | ||
const resolveSuffix = async (directory, { language, ignorePattern }) => language || (await getLastSuffix(directory, ignorePattern)) || 'js'; | ||
var FilenameFormat; | ||
@@ -71,10 +73,20 @@ (function (FilenameFormat) { | ||
} | ||
static async create(name, directory, language, ignorePattern, filenameFormat = FilenameFormat.timestamp) { | ||
static async create(name, directory, _language, _ignorePattern, _filenameFormat) { | ||
if (typeof _language === 'string') { | ||
console.warn('This usage is deprecated. Please use this method with options object argument'); | ||
} | ||
const options = typeof _language === 'object' | ||
? _language | ||
: { language: _language, ignorePattern: _ignorePattern, filenameFormat: _filenameFormat }; | ||
const { filenameFormat = FilenameFormat.timestamp } = options; | ||
mkdirp_1.default.sync(directory); | ||
const suffix = language || (await getLastSuffix(directory, ignorePattern)) || 'js'; | ||
const now = new Date(); | ||
const time = filenameFormat === FilenameFormat.utc ? now.toISOString().replace(/[^\d]/g, '') : now.valueOf(); | ||
const templateFileName = 'templateFileName' in options | ||
? path_1.default.resolve(process.cwd(), options.templateFileName) | ||
: path_1.default.resolve(__dirname, `../templates/migration-template.${await resolveSuffix(directory, options)}`); | ||
const suffix = getSuffixFromFileName(templateFileName); | ||
const newFile = `${directory}/${time}${SEPARATOR}${name}.${suffix}`; | ||
await new Promise((resolve, reject) => { | ||
fs_1.default.createReadStream(path_1.default.resolve(__dirname, `../templates/migration-template.${suffix}`)) | ||
fs_1.default.createReadStream(templateFileName) | ||
.pipe(fs_1.default.createWriteStream(newFile)) | ||
@@ -81,0 +93,0 @@ .on('close', resolve) |
@@ -71,3 +71,5 @@ # CLI Usage | ||
- `ignore-pattern` - Regex pattern for file names to ignore (e.g. `ignore_file|\..*|.*\.spec\.js`) | ||
- `migration-filename-format` - Choose prefix of file - either UTC (`20200605075829074`) or timestamp (`1591343909074`) | ||
- `migration-file-language` (`j`) - Language of the migration file to create (`js` or `ts`) | ||
- `template-file-name` - Use your own template file for migrations (language will be determined from the extension of the template). The file must export the `up` method accepting `MigrationBuilder` instance. | ||
- `tsconfig` - Path to tsconfig.json. Used to setup transpiling of TS migration files. (Also sets `migration-file-language` to typescript, if not overriden) | ||
@@ -74,0 +76,0 @@ - `timestamp` - Treats number argument to up/down migration as timestamp (running up migrations less or equal to timestamp or down migrations greater or equal to timestamp) |
{ | ||
"name": "node-pg-migrate", | ||
"version": "5.0.2", | ||
"version": "5.1.0", | ||
"description": "Postgresql database migration management tool for node.js", | ||
@@ -5,0 +5,0 @@ "author": "Theo Ephraim", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
281449
3378