masterrecord 1.1.4 → 1.1.6
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.
- package/CHANGES.md +24 -0
- package/Entity/entityModelBuilder.js +7 -7
- package/Entity/entityTrackerModel.js +15 -15
- package/Migrations/cli.js +126 -121
- package/Migrations/migrationMySQLQuery.js +21 -27
- package/Migrations/migrationPostgresQuery.js +16 -16
- package/Migrations/migrationSQLiteQuery.js +14 -14
- package/Migrations/migrations.js +41 -45
- package/Migrations/schema.js +3 -3
- package/QueryLanguage/queryMethods.js +26 -26
- package/QueryLanguage/queryScript.js +28 -28
- package/SQLLiteEngine.js +116 -118
- package/Tools.js +19 -19
- package/context.js +1 -1
- package/mySQLEngine.js +3 -3
- package/package.json +22 -2
- package/postgresEngine.js +6 -6
- package/.claude/settings.local.json +0 -10
- package/Migrations/pathUtils.test.js +0 -37
- package/eslint.config.js +0 -40
- package/prettier.config.js +0 -22
- package/test/belongs-to-fk-setter.test.js +0 -154
- package/test/belongs-to-fk-type.test.js +0 -253
- package/test/broad-audit.test.js +0 -256
- package/test/context-errors.test.js +0 -43
- package/test/count-chained-where.test.js +0 -136
- package/test/count-no-from-audit.test.js +0 -124
- package/test/ctx-dollar-placeholder.test.js +0 -142
- package/test/drop-column-idempotent.test.js +0 -181
- package/test/edge-cases-audit.test.js +0 -180
- package/test/esm-imports.test.js +0 -110
- package/test/full-text-search.test.js +0 -340
- package/test/migration-template.test.js +0 -47
- package/test/new-setter-large-string.test.js +0 -191
- package/test/pool-key.test.js +0 -43
- package/test/postgres-camelcase-quoting.test.js +0 -249
- package/test/query-builder-parity.test.js +0 -260
- package/test/setter-and-update-drop.test.js +0 -168
- package/test/sqlite-lifecycle.test.js +0 -76
- package/test/text-types.test.js +0 -167
- package/test/update-database-multi.test.js +0 -239
|
@@ -5,16 +5,16 @@ class migrationMySQLQuery {
|
|
|
5
5
|
#tempTableName = "_temp_alter_column_update"
|
|
6
6
|
|
|
7
7
|
#getTableColumns(table){
|
|
8
|
-
|
|
9
|
-
for (
|
|
8
|
+
const columnList = [];
|
|
9
|
+
for (const key in table) {
|
|
10
10
|
if(typeof table[key] === "object"){
|
|
11
|
-
|
|
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
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
194
|
+
let queryVar = "";
|
|
201
195
|
//console.log("Dsfdsfdsf---------", table)
|
|
202
|
-
for (
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
8
|
-
for (
|
|
7
|
+
const columnList = [];
|
|
8
|
+
for (const key in table) {
|
|
9
9
|
if(typeof table[key] === "object"){
|
|
10
|
-
|
|
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
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
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
|
-
|
|
58
|
+
let tableName = table.name;
|
|
59
59
|
if(table.relationshipType === 'belongsTo' && table.foreignKey){
|
|
60
60
|
tableName = table.foreignKey;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
|
|
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
|
-
|
|
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
|
-
|
|
203
|
+
let queryVar = "";
|
|
204
204
|
|
|
205
|
-
for (
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
9
|
-
for (
|
|
8
|
+
const columnList = [];
|
|
9
|
+
for (const key in table) {
|
|
10
10
|
if(typeof table[key] === "object"){
|
|
11
|
-
|
|
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
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
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
|
-
|
|
167
|
-
for (
|
|
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
|
-
|
|
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;
|
package/Migrations/migrations.js
CHANGED
|
@@ -15,12 +15,12 @@ import { resolveMigrationsDirectory } from './pathUtils.js';
|
|
|
15
15
|
class Migrations{
|
|
16
16
|
|
|
17
17
|
#organizeSchemaByTables(oldSchema, newSchema){
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
const tables = []
|
|
19
|
+
const seenTableNames = new Set(); // Track processed table names to prevent duplicates
|
|
20
20
|
|
|
21
21
|
if(oldSchema.length === 0){
|
|
22
22
|
newSchema.forEach(function (item, index) {
|
|
23
|
-
|
|
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
|
-
|
|
32
|
+
const table = {
|
|
33
33
|
name: tableName,
|
|
34
34
|
new :item,
|
|
35
35
|
old : {},
|
|
@@ -48,7 +48,7 @@ class Migrations{
|
|
|
48
48
|
}
|
|
49
49
|
else{
|
|
50
50
|
newSchema.forEach(function (item, index) {
|
|
51
|
-
|
|
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
|
-
|
|
60
|
+
const table = {
|
|
61
61
|
name: tableName,
|
|
62
62
|
old: {},
|
|
63
63
|
new :item,
|
|
@@ -73,7 +73,7 @@ class Migrations{
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
oldSchema.forEach(function (oldItem, index) {
|
|
76
|
-
|
|
76
|
+
const oldItemName = oldItem["__name"];
|
|
77
77
|
if(table.name === oldItemName){
|
|
78
78
|
table.old = oldItem;
|
|
79
79
|
}
|
|
@@ -88,13 +88,13 @@ class Migrations{
|
|
|
88
88
|
|
|
89
89
|
#findDeletedColumns(tables){
|
|
90
90
|
tables.forEach(function (item, index) {
|
|
91
|
-
|
|
91
|
+
let deletedColumn = null;
|
|
92
92
|
if(item.new && item.old){
|
|
93
93
|
Object.keys(item.old).forEach(function (key) {
|
|
94
|
-
|
|
94
|
+
const value = item.old[key].name;
|
|
95
95
|
deletedColumn = null;
|
|
96
96
|
Object.keys(item.new).forEach(function (newKey) {
|
|
97
|
-
|
|
97
|
+
const newValue = item.new[newKey].name;
|
|
98
98
|
if(value === newValue){
|
|
99
99
|
deletedColumn = value;
|
|
100
100
|
}
|
|
@@ -113,11 +113,11 @@ class Migrations{
|
|
|
113
113
|
|
|
114
114
|
tables.forEach(function (item, index) {
|
|
115
115
|
|
|
116
|
-
|
|
116
|
+
const UD = diff.updatedDiff(item.old, item.new);
|
|
117
117
|
const isEmpty = Object.keys(UD).length === 0;
|
|
118
118
|
if(!isEmpty){
|
|
119
|
-
for (
|
|
120
|
-
|
|
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
|
|
@@ -135,11 +135,11 @@ class Migrations{
|
|
|
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
|
-
|
|
139
|
-
|
|
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
|
-
|
|
142
|
+
const oldValue = item.old[oldKey].name;
|
|
143
143
|
if(value === oldValue){
|
|
144
144
|
columnNotFound = true;
|
|
145
145
|
}
|
|
@@ -186,7 +186,7 @@ class Migrations{
|
|
|
186
186
|
// build table to build new migration snapshot
|
|
187
187
|
#buildMigrationObject(oldSchema, newSchema, newSeedData = {}){
|
|
188
188
|
|
|
189
|
-
|
|
189
|
+
let tables = this.#organizeSchemaByTables(oldSchema, newSchema);
|
|
190
190
|
|
|
191
191
|
tables = this.#findNewTables(tables);
|
|
192
192
|
tables = this.#findNewColumns(tables);
|
|
@@ -208,11 +208,11 @@ class Migrations{
|
|
|
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
|
-
|
|
212
|
-
|
|
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
|
-
|
|
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];
|
|
@@ -252,11 +252,11 @@ class Migrations{
|
|
|
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
|
-
|
|
256
|
-
|
|
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
|
-
|
|
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];
|
|
@@ -358,22 +358,22 @@ class Migrations{
|
|
|
358
358
|
|
|
359
359
|
|
|
360
360
|
findContextFile(executedLocation, contextFileName){
|
|
361
|
-
|
|
361
|
+
const files = globSync(`**/*${contextFileName}.js`, {
|
|
362
362
|
cwd: executedLocation,
|
|
363
363
|
dot: true,
|
|
364
364
|
windowsPathsNoEscape: true
|
|
365
365
|
});
|
|
366
|
-
|
|
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
|
-
|
|
371
|
+
const files = globSync(`**/*${contextFileName}.js`, {
|
|
372
372
|
cwd: executedLocation,
|
|
373
373
|
dot: true,
|
|
374
374
|
windowsPathsNoEscape: true
|
|
375
375
|
});
|
|
376
|
-
|
|
376
|
+
const file = files && files[0] ? path.resolve(executedLocation, files[0]) : null;
|
|
377
377
|
if(!file){
|
|
378
378
|
return null;
|
|
379
379
|
}
|
|
@@ -387,12 +387,12 @@ class Migrations{
|
|
|
387
387
|
|
|
388
388
|
// remove hasMany and hasOne and hasManyThrough
|
|
389
389
|
cleanEntities(entities){
|
|
390
|
-
|
|
390
|
+
const newEntity = [];
|
|
391
391
|
for (let i = 0; i < entities.length; i++) {
|
|
392
|
-
|
|
393
|
-
|
|
392
|
+
const entity = entities[i];
|
|
393
|
+
const newObj = {}
|
|
394
394
|
|
|
395
|
-
for (
|
|
395
|
+
for (const key in entity) {
|
|
396
396
|
if (entity.hasOwnProperty(key)) {
|
|
397
397
|
|
|
398
398
|
if(entity[key].type !== "hasOne" && entity[key].type !== "hasMany" && entity[key].type !== "hasManyThrough"){
|
|
@@ -454,12 +454,12 @@ class Migrations{
|
|
|
454
454
|
|
|
455
455
|
// validate if schema has changed based on new and old
|
|
456
456
|
buildUpObject(oldSchema, newSchema){
|
|
457
|
-
|
|
458
|
-
|
|
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
|
-
|
|
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;
|
|
@@ -514,23 +514,19 @@ class Migrations{
|
|
|
514
514
|
}
|
|
515
515
|
|
|
516
516
|
template(name, oldSchema, newSchema, newSeedData = {}, seedConfig = {}, currentEnv = null){
|
|
517
|
-
|
|
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
|
-
|
|
522
|
+
const tables = this.#buildMigrationObject(oldSchema, newSchema, newSeedData);
|
|
523
523
|
|
|
524
524
|
tables.forEach(function (item, index) {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
if(item.new === null){
|
|
531
|
-
MT.dropTable("up", column, item.name);
|
|
532
|
-
MT.createTable("down", column, item.name);
|
|
533
|
-
}
|
|
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
531
|
item.newTables.forEach(function (column, ind) {
|
|
536
532
|
MT.createTable("up", item.name);
|
package/Migrations/schema.js
CHANGED
|
@@ -538,9 +538,9 @@ class schema{
|
|
|
538
538
|
if(this.fullTable){
|
|
539
539
|
if(this.context.isSQLite){
|
|
540
540
|
var queryBuilder = new sqliteQuery();
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
for (
|
|
541
|
+
const tableSchema = (this._tableObj && this._tableObj[table.tableName]) || this.fullTable.new;
|
|
542
|
+
const queryObj = queryBuilder.alterColumn(tableSchema, table);
|
|
543
|
+
for (const key in queryObj) {
|
|
544
544
|
var query = queryObj[key];
|
|
545
545
|
await this.context._execute(query);
|
|
546
546
|
}
|