Gathering detailed insights and metrics for sequelize-typescript-migration
Gathering detailed insights and metrics for sequelize-typescript-migration
Gathering detailed insights and metrics for sequelize-typescript-migration
Gathering detailed insights and metrics for sequelize-typescript-migration
npm install sequelize-typescript-migration
50.8
Supply Chain
93
Quality
72
Maintenance
25
Vulnerability
97.3
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
20 Stars
13 Commits
45 Forks
2 Watching
13 Branches
1 Contributors
Updated on 22 Sept 2024
TypeScript (86.08%)
JavaScript (13.92%)
Cumulative downloads
Total Downloads
Last day
-2.9%
33
Compared to previous day
Last week
-16.6%
146
Compared to previous week
Last month
-37.5%
639
Compared to previous month
Last year
-18.8%
9,254
Compared to previous year
It is based on sequelize-typescript, not supports "sequelize" based model codes. and you need prior knowledge of migration of Sequelize.
This scans models and its decorators to find changes, and generates migration code with this changes so don't need to write up, down function manually. this is like "makemigration" in django framework.
After generate successfully, you can use "migrate" in Sequelize Sequelize Migration Manual
This refers to GitHub - flexxnn/sequelize-auto-migrations: Migration generator && runner for sequelize and its forks, and modified to typescript.
Sometimes, undo(down) action may not work, then you should modify manually. Maybe it's because of ordering of relations of models. That issue is currently in the works.
npm i -D sequelize-typescript-migration
1import { Sequelize } from "sequelize-typescript"; 2import { SequelizeTypescriptMigration } from "sequelize-typescript-migration"; 3 4const sequelize: Sequelize = new Sequelize({ 5 // .. options 6}); 7 8await SequelizeTypescriptMigration.makeMigration(sequelize, { 9 outDir: path.join(__dirname, "../migrations"), 10 migrationName: "add-awesome-field-in-my-table" 11 preview: false, 12});
let's see example, if you have this two models and run first makeMigration, it detects all table change from nothing.
1@Table 2export class CarBrand extends Model<CarBrand> { 3 @Column 4 name: string; 5 6 @Default(true) 7 @Column(DataType.BOOLEAN) 8 isCertified: boolean; 9 10 @Column 11 imgUrl: string; 12 13 @Column 14 orderNo: number; 15 16 @Column 17 carsCount: number; 18}
1@Table 2export class Car extends Model<Car> { 3 @Column 4 name: string; 5 6 @ForeignKey(() => CarBrand) 7 @Column 8 carBrandId: number; 9 10 @BelongsTo(() => CarBrand) 11 carBrand: CarBrand; 12}
then this code written to 00000001-noname.js in migrations path.
1"use strict"; 2 3var Sequelize = require("sequelize"); 4 5/** 6 * Actions summary: 7 * 8 * createTable "CarBrands", deps: [] 9 * createTable "Cars", deps: [CarBrands] 10 * 11 **/ 12 13var info = { 14 revision: 1, 15 name: "noname", 16 created: "2020-04-12T15:49:58.814Z", 17 comment: "", 18}; 19 20var migrationCommands = [ 21 { 22 fn: "createTable", 23 params: [ 24 "CarBrands", 25 { 26 id: { 27 autoIncrement: true, 28 primaryKey: true, 29 allowNull: false, 30 type: Sequelize.INTEGER, 31 }, 32 name: { 33 type: Sequelize.STRING, 34 }, 35 isCertified: { 36 type: Sequelize.BOOLEAN, 37 }, 38 imgUrl: { 39 type: Sequelize.STRING, 40 }, 41 orderNo: { 42 type: Sequelize.INTEGER, 43 }, 44 carsCount: { 45 type: Sequelize.INTEGER, 46 }, 47 createdAt: { 48 allowNull: false, 49 type: Sequelize.DATE, 50 }, 51 updatedAt: { 52 allowNull: false, 53 type: Sequelize.DATE, 54 }, 55 }, 56 {}, 57 ], 58 }, 59 60 { 61 fn: "createTable", 62 params: [ 63 "Cars", 64 { 65 id: { 66 autoIncrement: true, 67 primaryKey: true, 68 allowNull: false, 69 type: Sequelize.INTEGER, 70 }, 71 name: { 72 type: Sequelize.STRING, 73 }, 74 carBrandId: { 75 onDelete: "NO ACTION", 76 onUpdate: "CASCADE", 77 references: { 78 model: "CarBrands", 79 key: "id", 80 }, 81 allowNull: true, 82 type: Sequelize.INTEGER, 83 }, 84 createdAt: { 85 allowNull: false, 86 type: Sequelize.DATE, 87 }, 88 updatedAt: { 89 allowNull: false, 90 type: Sequelize.DATE, 91 }, 92 }, 93 {}, 94 ], 95 }, 96]; 97 98var rollbackCommands = [ 99 { 100 fn: "dropTable", 101 params: ["Cars"], 102 }, 103 { 104 fn: "dropTable", 105 params: ["CarBrands"], 106 }, 107]; 108 109module.exports = { 110 pos: 0, 111 up: function (queryInterface, Sequelize) { 112 var index = this.pos; 113 return new Promise(function (resolve, reject) { 114 function next() { 115 if (index < migrationCommands.length) { 116 let command = migrationCommands[index]; 117 console.log("[#" + index + "] execute: " + command.fn); 118 index++; 119 queryInterface[command.fn] 120 .apply(queryInterface, command.params) 121 .then(next, reject); 122 } else resolve(); 123 } 124 next(); 125 }); 126 }, 127 down: function (queryInterface, Sequelize) { 128 var index = this.pos; 129 return new Promise(function (resolve, reject) { 130 function next() { 131 if (index < rollbackCommands.length) { 132 let command = rollbackCommands[index]; 133 console.log("[#" + index + "] execute: " + command.fn); 134 index++; 135 queryInterface[command.fn] 136 .apply(queryInterface, command.params) 137 .then(next, reject); 138 } else resolve(); 139 } 140 next(); 141 }); 142 }, 143 info: info, 144};
then you can apply this npx sequelize db:migrate --to 00000001-noname.js
not ready yet.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/13 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
29 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More