masterrecord 1.1.5 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,16 +5,16 @@ class migrationMySQLQuery {
5
5
  #tempTableName = "_temp_alter_column_update"
6
6
 
7
7
  #getTableColumns(table){
8
- var columnList = [];
9
- for (var key in table) {
8
+ const columnList = [];
9
+ for (const key in table) {
10
10
  if(typeof table[key] === "object"){
11
- var col = table[key];
11
+ const col = table[key];
12
12
  // Skip relationship-only fields
13
13
  if(col.type === 'hasOne' || col.type === 'hasMany' || col.type === 'hasManyThrough'){
14
14
  continue;
15
15
  }
16
16
  // Map belongsTo to its foreignKey name
17
- var name = (col.relationshipType === 'belongsTo' && col.foreignKey) ? col.foreignKey : col.name;
17
+ const name = (col.relationshipType === 'belongsTo' && col.foreignKey) ? col.foreignKey : col.name;
18
18
  columnList.push(`\`${name}\``);
19
19
  }
20
20
  }
@@ -38,16 +38,16 @@ class migrationMySQLQuery {
38
38
  */
39
39
  // name TEXT NOT NULL,
40
40
 
41
- var auto = table.auto ? " AUTO_INCREMENT":"";
42
- var primaryKey = table.primary ? " PRIMARY KEY" : "";
43
- var nullName = table.nullable ? "" : " NOT NULL";
44
- var unique = table.unique ? " UNIQUE" : "";
45
- var type = this.typeManager(table.type);
46
- var tableName = table.name;
41
+ const auto = table.auto ? " AUTO_INCREMENT":"";
42
+ const primaryKey = table.primary ? " PRIMARY KEY" : "";
43
+ const nullName = table.nullable ? "" : " NOT NULL";
44
+ const unique = table.unique ? " UNIQUE" : "";
45
+ const type = this.typeManager(table.type);
46
+ let tableName = table.name;
47
47
  if(table.relationshipType === 'belongsTo' && table.foreignKey){
48
48
  tableName = table.foreignKey;
49
49
  }
50
- var defaultValue = "";
50
+ let defaultValue = "";
51
51
  if(table.default !== undefined && table.default !== null){
52
52
  let def = table.default;
53
53
  if(table.type === 'boolean'){
@@ -69,18 +69,12 @@ class migrationMySQLQuery {
69
69
  boolType(type){
70
70
  switch(type) {
71
71
  case "true":
72
- return "1"
73
- break;
74
- case "false":
75
- return "0"
76
- break;
77
- case true:
78
- return "1"
79
- break;
80
- case false:
81
- return "0"
82
- break;
83
- default:
72
+ case true:
73
+ return "1";
74
+ case "false":
75
+ case false:
76
+ return "0";
77
+ default:
84
78
  return type;
85
79
  }
86
80
  }
@@ -197,16 +191,16 @@ class migrationMySQLQuery {
197
191
 
198
192
  createTable(table){
199
193
 
200
- var queryVar = "";
194
+ let queryVar = "";
201
195
  //console.log("Dsfdsfdsf---------", table)
202
- for (var key in table) {
196
+ for (const key in table) {
203
197
  // Skip metadata properties (indexes, __compositeIndexes, __name, etc.)
204
198
  if(key === 'indexes' || key.startsWith('__')){
205
199
  continue;
206
200
  }
207
201
 
208
202
  if(typeof table[key] === "object"){
209
- var col = table[key];
203
+ const col = table[key];
210
204
 
211
205
  if(col.type !== "hasOne" && col.type !== "hasMany" && col.type !== "hasManyThrough"){
212
206
  // Whitelist: Only process objects that look like column definitions
@@ -220,7 +214,7 @@ class migrationMySQLQuery {
220
214
  }
221
215
  }
222
216
 
223
- var completeQuery = `CREATE TABLE IF NOT EXISTS \`${table.__name}\` (${queryVar.replace(/,\s*$/, "")});`;
217
+ const completeQuery = `CREATE TABLE IF NOT EXISTS \`${table.__name}\` (${queryVar.replace(/,\s*$/, "")});`;
224
218
  return completeQuery;
225
219
 
226
220
  /*
@@ -4,16 +4,16 @@ class migrationPostgresQuery {
4
4
  #tempTableName = "_temp_alter_column_update"
5
5
 
6
6
  #getTableColumns(table){
7
- var columnList = [];
8
- for (var key in table) {
7
+ const columnList = [];
8
+ for (const key in table) {
9
9
  if(typeof table[key] === "object"){
10
- var col = table[key];
10
+ const col = table[key];
11
11
  // Skip relationship-only fields
12
12
  if(col.type === 'hasOne' || col.type === 'hasMany' || col.type === 'hasManyThrough'){
13
13
  continue;
14
14
  }
15
15
  // Map belongsTo to its foreignKey name
16
- var name = (col.relationshipType === 'belongsTo' && col.foreignKey) ? col.foreignKey : col.name;
16
+ const name = (col.relationshipType === 'belongsTo' && col.foreignKey) ? col.foreignKey : col.name;
17
17
  columnList.push(`"${name}"`);
18
18
  }
19
19
  }
@@ -36,13 +36,13 @@ class migrationPostgresQuery {
36
36
  */
37
37
 
38
38
  // PostgreSQL uses SERIAL for auto-increment, not separate AUTO_INCREMENT keyword
39
- var auto = "";
40
- var primaryKey = table.primary ? " PRIMARY KEY" : "";
41
- var nullName = table.nullable ? "" : " NOT NULL";
42
- var unique = table.unique ? " UNIQUE" : "";
39
+ let auto = "";
40
+ let primaryKey = table.primary ? " PRIMARY KEY" : "";
41
+ const nullName = table.nullable ? "" : " NOT NULL";
42
+ const unique = table.unique ? " UNIQUE" : "";
43
43
 
44
44
  // For PostgreSQL, if auto-increment primary key, use SERIAL or BIGSERIAL
45
- var type;
45
+ let type;
46
46
  if(table.auto && table.primary && (table.type === 'integer' || table.type === 'int')){
47
47
  type = "SERIAL"; // Auto-incrementing integer
48
48
  auto = "";
@@ -55,12 +55,12 @@ class migrationPostgresQuery {
55
55
  type = this.typeManager(table.type);
56
56
  }
57
57
 
58
- var tableName = table.name;
58
+ let tableName = table.name;
59
59
  if(table.relationshipType === 'belongsTo' && table.foreignKey){
60
60
  tableName = table.foreignKey;
61
61
  }
62
62
 
63
- var defaultValue = "";
63
+ let defaultValue = "";
64
64
  if(table.default !== undefined && table.default !== null){
65
65
  let def = table.default;
66
66
  if(table.type === 'boolean' || table.type === 'bool'){
@@ -135,7 +135,7 @@ class migrationPostgresQuery {
135
135
  const type = this.typeManager(table.table.type);
136
136
 
137
137
  // Build ALTER statements - PostgreSQL requires separate statements for different changes
138
- let statements = [];
138
+ const statements = [];
139
139
 
140
140
  // Change type
141
141
  statements.push(`ALTER TABLE "${tableName}" ALTER COLUMN "${colName}" TYPE ${type}`);
@@ -200,16 +200,16 @@ class migrationPostgresQuery {
200
200
  }
201
201
 
202
202
  createTable(table){
203
- var queryVar = "";
203
+ let queryVar = "";
204
204
 
205
- for (var key in table) {
205
+ for (const key in table) {
206
206
  // Skip metadata properties (indexes, __compositeIndexes, __name, etc.)
207
207
  if(key === 'indexes' || key.startsWith('__')){
208
208
  continue;
209
209
  }
210
210
 
211
211
  if(typeof table[key] === "object"){
212
- var col = table[key];
212
+ const col = table[key];
213
213
 
214
214
  if(col.type !== "hasOne" && col.type !== "hasMany" && col.type !== "hasManyThrough"){
215
215
  // Whitelist: Only process objects that look like column definitions
@@ -223,7 +223,7 @@ class migrationPostgresQuery {
223
223
  }
224
224
  }
225
225
 
226
- var completeQuery = `CREATE TABLE IF NOT EXISTS "${table.__name}" (${queryVar.replace(/,\s*$/, "")});`;
226
+ const completeQuery = `CREATE TABLE IF NOT EXISTS "${table.__name}" (${queryVar.replace(/,\s*$/, "")});`;
227
227
  return completeQuery;
228
228
  }
229
229
 
@@ -5,16 +5,16 @@ class migrationSQLiteQuery {
5
5
  #tempTableName = "_temp_alter_column_update"
6
6
 
7
7
  #getTableColumns(table){
8
- var columnList = [];
9
- for (var key in table) {
8
+ const columnList = [];
9
+ for (const key in table) {
10
10
  if(typeof table[key] === "object"){
11
- var col = table[key];
11
+ const col = table[key];
12
12
  // Skip relationship-only fields
13
13
  if(col.type === 'hasOne' || col.type === 'hasMany' || col.type === 'hasManyThrough'){
14
14
  continue;
15
15
  }
16
16
  // Map belongsTo to its foreignKey name
17
- var name = (col.relationshipType === 'belongsTo' && col.foreignKey) ? col.foreignKey : col.name;
17
+ const name = (col.relationshipType === 'belongsTo' && col.foreignKey) ? col.foreignKey : col.name;
18
18
  columnList.push(name);
19
19
  }
20
20
  }
@@ -38,17 +38,17 @@ class migrationSQLiteQuery {
38
38
  */
39
39
  // name TEXT NOT NULL,
40
40
 
41
- var auto = table.auto ? " AUTOINCREMENT":"";
42
- var primaryKey = table.primary ? " PRIMARY KEY" : "";
43
- var nullName = table.nullable ? "" : " NOT NULL";
44
- var unique = table.unique ? " UNIQUE" : "";
45
- var type = this.#typeManager(table.type);
46
- var colName = table.name;
41
+ const auto = table.auto ? " AUTOINCREMENT":"";
42
+ const primaryKey = table.primary ? " PRIMARY KEY" : "";
43
+ const nullName = table.nullable ? "" : " NOT NULL";
44
+ const unique = table.unique ? " UNIQUE" : "";
45
+ const type = this.#typeManager(table.type);
46
+ let colName = table.name;
47
47
  if(table.relationshipType === 'belongsTo' && table.foreignKey){
48
48
  colName = table.foreignKey;
49
49
  }
50
50
  // DEFAULT clause
51
- var defaultClause = "";
51
+ let defaultClause = "";
52
52
  if(table.default !== undefined && table.default !== null){
53
53
  let def = table.default;
54
54
  if(table.type === 'boolean'){
@@ -163,15 +163,15 @@ class migrationSQLiteQuery {
163
163
  }
164
164
 
165
165
  createTable(table){
166
- var queryVar = "";
167
- for (var key in table) {
166
+ let queryVar = "";
167
+ for (const key in table) {
168
168
  // Skip metadata properties (indexes, __compositeIndexes, __name, etc.)
169
169
  if(key === 'indexes' || key.startsWith('__')){
170
170
  continue;
171
171
  }
172
172
 
173
173
  if(typeof table[key] === "object"){
174
- var col = table[key];
174
+ const col = table[key];
175
175
  // Skip relationship-only fields
176
176
  if(col.type === 'hasOne' || col.type === 'hasMany' || col.type === 'hasManyThrough'){
177
177
  continue;
@@ -258,7 +258,6 @@ class migrationSQLiteQuery {
258
258
  createFullTextIndex(info){
259
259
  const ftsTable = info.ftsTableName || `${info.tableName}_fts`;
260
260
  const cols = info.columns.join(', ');
261
- const insertCols = info.columns.map(c => `[${c}]`).join(', ');
262
261
  const newCols = info.columns.map(c => `new.[${c}]`).join(', ');
263
262
  const oldCols = info.columns.map(c => `old.[${c}]`).join(', ');
264
263
 
@@ -37,7 +37,7 @@ export default ${this.name};
37
37
  `;
38
38
  }
39
39
 
40
- alterColumn(type, name, parent){
40
+ alterColumn(type, name, _parent){
41
41
  if(type === "up"){
42
42
  this.#up += os.EOL + ` await this.alterColumn(table.${name});`
43
43
  }
@@ -54,7 +54,7 @@ export default ${this.name};
54
54
  }
55
55
  }
56
56
 
57
- addColumn(type, name, parent){
57
+ addColumn(type, name, _parent){
58
58
  if(type === "up"){
59
59
  this.#up += os.EOL + ` await this.addColumn(table.${name});`
60
60
  }
@@ -73,7 +73,7 @@ export default ${this.name};
73
73
  }
74
74
  }
75
75
 
76
- dropColumn(type, name, parent){
76
+ dropColumn(type, name, _parent){
77
77
  if(type === "up"){
78
78
  this.#up += os.EOL + ` await this.dropColumn(table.${name});`
79
79
  }
@@ -83,7 +83,7 @@ export default ${this.name};
83
83
  }
84
84
 
85
85
  createIndex(type, indexInfo){
86
- const indexName = indexInfo.indexName === true
86
+ const _indexName = indexInfo.indexName === true
87
87
  ? `idx_${indexInfo.tableName.toLowerCase()}_${indexInfo.columnName.toLowerCase()}`
88
88
  : indexInfo.indexName;
89
89
 
@@ -102,7 +102,7 @@ export default ${this.name};
102
102
  }
103
103
 
104
104
  dropIndex(type, indexInfo){
105
- const indexName = indexInfo.indexName === true
105
+ const _indexName = indexInfo.indexName === true
106
106
  ? `idx_${indexInfo.tableName.toLowerCase()}_${indexInfo.columnName.toLowerCase()}`
107
107
  : indexInfo.indexName;
108
108
 
@@ -277,7 +277,7 @@ export default ${this.name};
277
277
  }
278
278
 
279
279
  const pkValue = rollback.value;
280
- const pkKey = rollback.key || 'id';
280
+ const _pkKey = rollback.key || 'id';
281
281
 
282
282
  // Generate delete code with error handling
283
283
  this.#down += os.EOL + ` try {`;
@@ -15,12 +15,12 @@ import { resolveMigrationsDirectory } from './pathUtils.js';
15
15
  class Migrations{
16
16
 
17
17
  #organizeSchemaByTables(oldSchema, newSchema){
18
- var tables = []
19
- var seenTableNames = new Set(); // Track processed table names to prevent duplicates
18
+ const tables = []
19
+ const seenTableNames = new Set(); // Track processed table names to prevent duplicates
20
20
 
21
21
  if(oldSchema.length === 0){
22
- newSchema.forEach(function (item, index) {
23
- var tableName = item["__name"];
22
+ newSchema.forEach(function (item, _index) {
23
+ const tableName = item["__name"];
24
24
 
25
25
  // Skip if we've already processed this table name
26
26
  if(seenTableNames.has(tableName)){
@@ -29,7 +29,7 @@ class Migrations{
29
29
  }
30
30
  seenTableNames.add(tableName);
31
31
 
32
- var table = {
32
+ const table = {
33
33
  name: tableName,
34
34
  new :item,
35
35
  old : {},
@@ -47,8 +47,8 @@ class Migrations{
47
47
  });
48
48
  }
49
49
  else{
50
- newSchema.forEach(function (item, index) {
51
- var tableName = item["__name"];
50
+ newSchema.forEach(function (item, _index) {
51
+ const tableName = item["__name"];
52
52
 
53
53
  // Skip if we've already processed this table name
54
54
  if(seenTableNames.has(tableName)){
@@ -57,7 +57,7 @@ class Migrations{
57
57
  }
58
58
  seenTableNames.add(tableName);
59
59
 
60
- var table = {
60
+ const table = {
61
61
  name: tableName,
62
62
  old: {},
63
63
  new :item,
@@ -72,8 +72,8 @@ class Migrations{
72
72
  newSeedData : []
73
73
  }
74
74
 
75
- oldSchema.forEach(function (oldItem, index) {
76
- var oldItemName = oldItem["__name"];
75
+ oldSchema.forEach(function (oldItem, _index) {
76
+ const oldItemName = oldItem["__name"];
77
77
  if(table.name === oldItemName){
78
78
  table.old = oldItem;
79
79
  }
@@ -87,14 +87,14 @@ class Migrations{
87
87
  }
88
88
 
89
89
  #findDeletedColumns(tables){
90
- tables.forEach(function (item, index) {
91
- var deletedColumn = null;
90
+ tables.forEach(function (item, _index) {
91
+ let deletedColumn = null;
92
92
  if(item.new && item.old){
93
93
  Object.keys(item.old).forEach(function (key) {
94
- var value = item.old[key].name;
94
+ const value = item.old[key].name;
95
95
  deletedColumn = null;
96
96
  Object.keys(item.new).forEach(function (newKey) {
97
- var newValue = item.new[newKey].name;
97
+ const newValue = item.new[newKey].name;
98
98
  if(value === newValue){
99
99
  deletedColumn = value;
100
100
  }
@@ -111,13 +111,13 @@ class Migrations{
111
111
  #findUpdatedColumns(tables){
112
112
 
113
113
 
114
- tables.forEach(function (item, index) {
114
+ tables.forEach(function (item, _index) {
115
115
 
116
- var UD = diff.updatedDiff(item.old, item.new);
116
+ const UD = diff.updatedDiff(item.old, item.new);
117
117
  const isEmpty = Object.keys(UD).length === 0;
118
118
  if(!isEmpty){
119
- for (var key in UD) {
120
- var tableChanges = {
119
+ for (const key in UD) {
120
+ const tableChanges = {
121
121
  changes : UD[key],
122
122
  table : item.new[key],
123
123
  tableName : item.name
@@ -131,15 +131,15 @@ class Migrations{
131
131
  }
132
132
 
133
133
  #findNewColumns(tables){
134
- tables.forEach(function (item, index) {
134
+ tables.forEach(function (item, _index) {
135
135
  if(item.new && item.old){
136
136
  Object.keys(item.new).forEach(function (key) {
137
137
  if(typeof item.new[key] === "object"){
138
- var value = item.new[key].name;
139
- var columnNotFound = false;
138
+ const value = item.new[key].name;
139
+ let columnNotFound = false;
140
140
  Object.keys(item.old).forEach(function (oldKey) {
141
141
  if(typeof item.old[oldKey] === "object"){
142
- var oldValue = item.old[oldKey].name;
142
+ const oldValue = item.old[oldKey].name;
143
143
  if(value === oldValue){
144
144
  columnNotFound = true;
145
145
  }
@@ -170,7 +170,7 @@ class Migrations{
170
170
 
171
171
  #findNewTables(tables){
172
172
  // find new tables
173
- tables.forEach(function (item, index) {
173
+ tables.forEach(function (item, _index) {
174
174
  if(item.new && item.old){
175
175
  if(Object.keys(item.old).length === 0){
176
176
  item.newTables.push(item);
@@ -186,7 +186,7 @@ class Migrations{
186
186
  // build table to build new migration snapshot
187
187
  #buildMigrationObject(oldSchema, newSchema, newSeedData = {}){
188
188
 
189
- var tables = this.#organizeSchemaByTables(oldSchema, newSchema);
189
+ let tables = this.#organizeSchemaByTables(oldSchema, newSchema);
190
190
 
191
191
  tables = this.#findNewTables(tables);
192
192
  tables = this.#findNewColumns(tables);
@@ -201,18 +201,18 @@ class Migrations{
201
201
  }
202
202
 
203
203
  #findNewIndexes(tables){
204
- tables.forEach(function (item, index) {
204
+ tables.forEach(function (item, _index) {
205
205
  // Skip new tables — createTable() in schema.js already creates their indexes
206
206
  if(item.newTables && item.newTables.length > 0) return;
207
207
 
208
208
  if(item.new && item.old){
209
209
  Object.keys(item.new).forEach(function (key) {
210
210
  if(typeof item.new[key] === "object" && item.new[key].indexes){
211
- var columnName = item.new[key].name;
212
- var newIndexes = item.new[key].indexes;
211
+ const columnName = item.new[key].name;
212
+ const newIndexes = item.new[key].indexes;
213
213
 
214
214
  // Check if this column existed before
215
- var oldColumn = null;
215
+ let oldColumn = null;
216
216
  Object.keys(item.old).forEach(function (oldKey) {
217
217
  if(typeof item.old[oldKey] === "object" && item.old[oldKey].name === columnName){
218
218
  oldColumn = item.old[oldKey];
@@ -248,15 +248,15 @@ class Migrations{
248
248
  }
249
249
 
250
250
  #findDeletedIndexes(tables){
251
- tables.forEach(function (item, index) {
251
+ tables.forEach(function (item, _index) {
252
252
  if(item.new && item.old){
253
253
  Object.keys(item.old).forEach(function (key) {
254
254
  if(typeof item.old[key] === "object" && item.old[key].indexes){
255
- var columnName = item.old[key].name;
256
- var oldIndexes = item.old[key].indexes;
255
+ const columnName = item.old[key].name;
256
+ const oldIndexes = item.old[key].indexes;
257
257
 
258
258
  // Check if this column still exists
259
- var newColumn = null;
259
+ let newColumn = null;
260
260
  Object.keys(item.new).forEach(function (newKey) {
261
261
  if(typeof item.new[newKey] === "object" && item.new[newKey].name === columnName){
262
262
  newColumn = item.new[newKey];
@@ -292,7 +292,7 @@ class Migrations{
292
292
  }
293
293
 
294
294
  #findNewCompositeIndexes(tables) {
295
- tables.forEach(function (item, index) {
295
+ tables.forEach(function (item, _index) {
296
296
  // Skip new tables — createTable() in schema.js already creates their composite indexes
297
297
  if(item.newTables && item.newTables.length > 0) return;
298
298
 
@@ -320,7 +320,7 @@ class Migrations{
320
320
  }
321
321
 
322
322
  #findDeletedCompositeIndexes(tables) {
323
- tables.forEach(function (item, index) {
323
+ tables.forEach(function (item, _index) {
324
324
  if (item.new && item.old) {
325
325
  const newComposite = item.new.__compositeIndexes || [];
326
326
  const oldComposite = item.old.__compositeIndexes || [];
@@ -358,22 +358,22 @@ class Migrations{
358
358
 
359
359
 
360
360
  findContextFile(executedLocation, contextFileName){
361
- var files = globSync(`**/*${contextFileName}.js`, {
361
+ const files = globSync(`**/*${contextFileName}.js`, {
362
362
  cwd: executedLocation,
363
363
  dot: true,
364
364
  windowsPathsNoEscape: true
365
365
  });
366
- var file = files && files[0] ? path.resolve(executedLocation, files[0]) : null;
366
+ const file = files && files[0] ? path.resolve(executedLocation, files[0]) : null;
367
367
  return file;
368
368
  }
369
369
 
370
370
  async findContext(executedLocation, contextFileName){
371
- var files = globSync(`**/*${contextFileName}.js`, {
371
+ const files = globSync(`**/*${contextFileName}.js`, {
372
372
  cwd: executedLocation,
373
373
  dot: true,
374
374
  windowsPathsNoEscape: true
375
375
  });
376
- var file = files && files[0] ? path.resolve(executedLocation, files[0]) : null;
376
+ const file = files && files[0] ? path.resolve(executedLocation, files[0]) : null;
377
377
  if(!file){
378
378
  return null;
379
379
  }
@@ -387,13 +387,13 @@ class Migrations{
387
387
 
388
388
  // remove hasMany and hasOne and hasManyThrough
389
389
  cleanEntities(entities){
390
- var newEntity = [];
390
+ const newEntity = [];
391
391
  for (let i = 0; i < entities.length; i++) {
392
- var entity = entities[i];
393
- var newObj = {}
392
+ const entity = entities[i];
393
+ const newObj = {}
394
394
 
395
- for (let key in entity) {
396
- if (entity.hasOwnProperty(key)) {
395
+ for (const key in entity) {
396
+ if (Object.prototype.hasOwnProperty.call(entity, key)) {
397
397
 
398
398
  if(entity[key].type !== "hasOne" && entity[key].type !== "hasMany" && entity[key].type !== "hasManyThrough"){
399
399
  // if(entity[key].relationshipType == "belongsTo" ){
@@ -454,31 +454,31 @@ class Migrations{
454
454
 
455
455
  // validate if schema has changed based on new and old
456
456
  buildUpObject(oldSchema, newSchema){
457
- var tableObj = {}
458
- var tables = this.#buildMigrationObject(oldSchema, newSchema);
457
+ const tableObj = {}
458
+ const tables = this.#buildMigrationObject(oldSchema, newSchema);
459
459
 
460
460
  tables.forEach(function (item, index) {
461
461
  // add new columns for table
462
- var columnInfo = tables[index];
462
+ const columnInfo = tables[index];
463
463
  // Always expose each table under its name so templates like
464
464
  // this.createTable(table.TableName) can safely access it.
465
465
  tableObj[item.name] = columnInfo.new;
466
466
 
467
- item.newTables.forEach(function (column, ind) {
467
+ item.newTables.forEach(function (_column, _ind) {
468
468
  tableObj[item.name] = columnInfo.new;
469
469
  });
470
470
 
471
- item.newColumns.forEach(function (column, ind) {
471
+ item.newColumns.forEach(function (column, _ind) {
472
472
  columnInfo.new[column].tableName = item.name;
473
473
  tableObj[column] = columnInfo.new[column];
474
474
  });
475
475
 
476
- item.deletedColumns.forEach(function (column, ind) {
476
+ item.deletedColumns.forEach(function (column, _ind) {
477
477
  columnInfo.old[column].tableName = item.name;
478
478
  tableObj[column] = columnInfo.old[column];
479
479
  });
480
480
 
481
- item.updatedColumns.forEach(function (column, ind) {
481
+ item.updatedColumns.forEach(function (column, _ind) {
482
482
  tableObj[column.table.name] = column;
483
483
  });
484
484
 
@@ -514,41 +514,37 @@ class Migrations{
514
514
  }
515
515
 
516
516
  template(name, oldSchema, newSchema, newSeedData = {}, seedConfig = {}, currentEnv = null){
517
- var MT = new MigrationTemplate(name);
517
+ const MT = new MigrationTemplate(name);
518
518
  // Determine current environment if not provided
519
519
  if (!currentEnv) {
520
520
  currentEnv = process.env.NODE_ENV || process.env.master || 'development';
521
521
  }
522
- var tables = this.#buildMigrationObject(oldSchema, newSchema, newSeedData);
523
-
524
- tables.forEach(function (item, index) {
525
- if(item.old === null){
526
- MT.createTable("up", column, item.name);
527
- MT.dropTable("down", column, item.name);
528
- }
522
+ const tables = this.#buildMigrationObject(oldSchema, newSchema, newSeedData);
529
523
 
530
- if(item.new === null){
531
- MT.dropTable("up", column, item.name);
532
- MT.createTable("down", column, item.name);
533
- }
524
+ tables.forEach(function (item, _index) {
525
+ // (Whole-table create/drop is handled below via item.newTables /
526
+ // item.deletedColumns. The previous `if (item.old === null)` /
527
+ // `if (item.new === null)` branches here referenced an undefined
528
+ // `column` and never ran — old/new are always {} or an object,
529
+ // never null — so they were dead, broken code and were removed.)
534
530
 
535
- item.newTables.forEach(function (column, ind) {
531
+ item.newTables.forEach(function (_column, _ind) {
536
532
  MT.createTable("up", item.name);
537
533
  MT.dropTable("down", item.name);
538
534
  });
539
535
 
540
536
  // add new columns for table
541
- item.newColumns.forEach(function (column, index) {
537
+ item.newColumns.forEach(function (column, _index) {
542
538
  MT.addColumn("up", column, item.name);
543
539
  MT.dropColumn("down", column, item.name);
544
540
  });
545
541
 
546
- item.deletedColumns.forEach(function (column, index) {
542
+ item.deletedColumns.forEach(function (column, _index) {
547
543
  MT.dropColumn("up", column, item.name);
548
544
  MT.addColumn("down",column, item.name);
549
545
  });
550
546
 
551
- item.updatedColumns.forEach(function (column, index) {
547
+ item.updatedColumns.forEach(function (column, _index) {
552
548
  const isEmpty = Object.keys(column).length === 0;
553
549
  if(!isEmpty){
554
550
  MT.alterColumn("up", column.table.name, item.name);
@@ -556,19 +552,19 @@ class Migrations{
556
552
  }
557
553
  });
558
554
 
559
- item.newIndexes.forEach(function (indexInfo, index) {
555
+ item.newIndexes.forEach(function (indexInfo, _index) {
560
556
  MT.createIndex("up", indexInfo);
561
557
  });
562
558
 
563
- item.deletedIndexes.forEach(function (indexInfo, index) {
559
+ item.deletedIndexes.forEach(function (indexInfo, _index) {
564
560
  MT.dropIndex("up", indexInfo);
565
561
  });
566
562
 
567
- item.newCompositeIndexes.forEach(function (indexInfo, index) {
563
+ item.newCompositeIndexes.forEach(function (indexInfo, _index) {
568
564
  MT.createCompositeIndex("up", indexInfo);
569
565
  });
570
566
 
571
- item.deletedCompositeIndexes.forEach(function (indexInfo, index) {
567
+ item.deletedCompositeIndexes.forEach(function (indexInfo, _index) {
572
568
  MT.dropCompositeIndex("up", indexInfo);
573
569
  });
574
570