Chore: Create script to add new migrations (#23822)

pull/23871/head
Kevin Aleman 4 years ago committed by GitHub
parent aec724fd9d
commit 049956cc07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 50
      .scripts/make-migration.ts
  2. 9
      .scripts/migration.template
  3. 71
      package-lock.json
  4. 2
      package.json

@ -0,0 +1,50 @@
import { readdirSync, readFileSync, writeFileSync } from 'fs';
import { renderFile } from 'template-file';
function main(number: string, comment: string): void {
if (!(Number(number) >= 0)) {
console.error(`1st param must be a valid number. ${ number } provided`);
return;
}
if (comment.trim()) {
comment = `// ${ comment }`;
}
// check if migration will conflict with current on-branch migrations
const migrationName = `v${ number }`;
const fileList = readdirSync('./server/startup/migrations');
if (fileList.includes(`${ migrationName }.ts`)) {
console.error('Migration with specified number already exists');
return;
}
renderFile('./.scripts/migration.template', { number, comment })
.then((renderedMigration) => {
// generate new migration file
writeFileSync(`./server/startup/migrations/${ migrationName }.ts`, renderedMigration);
// get contents of index.ts to append new migration
const indexFile = readFileSync('./server/startup/migrations/index.ts');
const splittedIndexLines = indexFile.toString().split('\n');
// remove end line + xrun import
splittedIndexLines.splice(splittedIndexLines.length - 2, 0, `import './${ migrationName }';`);
const data = splittedIndexLines.join('\n');
// append migration import to indexfile
writeFileSync('./server/startup/migrations/index.ts', data);
console.log(`Migration ${ migrationName } created`);
})
.catch(console.error);
}
const [, , number, comment = ''] = process.argv;
if (!number || (comment && !comment.trim())) {
console.error('Usage:\n\tmeteor npm run migration:add <migration number> [migration comment: optional]\n');
process.exit(1);
}
main(number, comment);

@ -0,0 +1,9 @@
import { addMigration } from '../../lib/migrations';
{{ comment }}
addMigration({
version: {{ number }},
up() {
},
});

71
package-lock.json generated

@ -3433,6 +3433,22 @@
"integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==",
"dev": true
},
"@blakek/curry": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/@blakek/curry/-/curry-2.0.2.tgz",
"integrity": "sha512-B/KkDnZqm9Y92LwETU80BaxbQ61bYTR2GaAY41mKisaICwBoC8lcuw7lwQLl52InMhviCTJBO39GJOA8d+BrVw==",
"dev": true
},
"@blakek/deep": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@blakek/deep/-/deep-2.2.0.tgz",
"integrity": "sha512-aRq/qF1yrlhCWNk2tI4epXNpo+cA8/MrxsR5oIkpKKNYtYOQKjAxRMbgnhASPx+b328MkDN+T706yFKJg8VZkQ==",
"dev": true,
"requires": {
"@blakek/curry": "^2.0.2",
"pathington": "^1.1.7"
}
},
"@bugsnag/browser": {
"version": "7.11.0",
"resolved": "https://registry.npmjs.org/@bugsnag/browser/-/browser-7.11.0.tgz",
@ -28646,6 +28662,12 @@
"util-ex": "^0.3.10"
}
},
"pathington": {
"version": "1.1.7",
"resolved": "https://registry.npmjs.org/pathington/-/pathington-1.1.7.tgz",
"integrity": "sha512-JxzhUzagDfNIOm4qqwQqP3rWeo7rNNOfIahy4n+3GTEdwXLqw5cJHUR0soSopQtNEv763lzxb6eA2xBllpR8zw==",
"dev": true
},
"pathval": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.1.tgz",
@ -35240,6 +35262,55 @@
}
}
},
"template-file": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/template-file/-/template-file-6.0.0.tgz",
"integrity": "sha512-KWHrRYAaK0njUGmn77gqHpb8vr5/Zj9YIWS2B5cstiNWEZLvF63p/LG8rTCgvfpOJwAb1PeiPmtMUjBT7qw2Tw==",
"dev": true,
"requires": {
"@blakek/deep": "^2.2.0",
"glob": "^7.1.6",
"mkdirp": "^1.0.4",
"p-limit": "^4.0.0"
},
"dependencies": {
"glob": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz",
"integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==",
"dev": true,
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.0.4",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
},
"mkdirp": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",
"integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==",
"dev": true
},
"p-limit": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-4.0.0.tgz",
"integrity": "sha512-5b0R4txpzjPWVw/cXXUResoD4hb6U/x9BH08L7nw+GN1sezDzPdxeRvpc9c433fZhBan/wusjbCsqwqm4EIBIQ==",
"dev": true,
"requires": {
"yocto-queue": "^1.0.0"
}
},
"yocto-queue": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.0.0.tgz",
"integrity": "sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==",
"dev": true
}
}
},
"term-size": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/term-size/-/term-size-2.2.1.tgz",

@ -17,6 +17,7 @@
"ha": "meteor npm run ha:start",
"ha:start": "ts-node .scripts/run-ha.ts main",
"ha:add": "ts-node .scripts/run-ha.ts instance",
"migration:add": "ts-node-transpile-only --skip-project .scripts/make-migration.ts",
"debug": "meteor run --inspect",
"debug-brk": "meteor run --inspect-brk",
"lint": "meteor npm run stylelint && meteor npm run eslint",
@ -156,6 +157,7 @@
"stylelint": "^13.13.1",
"stylelint-order": "^4.1.0",
"supertest": "^6.1.6",
"template-file": "^6.0.0",
"ts-loader": "^8.3.0",
"ts-node": "^10.0.0",
"typescript": "^4.3.4",

Loading…
Cancel
Save