masterrecord 0.3.1 → 0.3.2

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.
@@ -152,6 +152,14 @@ class migrationMySQLQuery {
152
152
 
153
153
 
154
154
  addColum(table){
155
+ // Fixed: Use columnMapping to generate full column definition with constraints
156
+ // This includes NOT NULL, DEFAULT, UNIQUE, PRIMARY KEY, AUTO_INCREMENT
157
+ if(table.type && table.tableName && table.name){
158
+ const def = this.#columnMapping(table);
159
+ return `ALTER TABLE \`${table.tableName}\`
160
+ ADD ${def}`;
161
+ }
162
+ // Fallback for legacy behavior with just realDataType
155
163
  return `ALTER TABLE \`${table.tableName}\`
156
164
  ADD \`${table.name}\` ${table.realDataType}`;
157
165
 
@@ -167,7 +167,14 @@ class migrationPostgresQuery {
167
167
  }
168
168
 
169
169
  addColum(table){
170
- // PostgreSQL add column syntax
170
+ // Fixed: Use columnMapping to generate full column definition with constraints
171
+ // This includes NOT NULL, DEFAULT, UNIQUE, PRIMARY KEY
172
+ if(table.type && table.tableName && table.name){
173
+ const def = this.#columnMapping(table);
174
+ return `ALTER TABLE "${table.tableName}"
175
+ ADD COLUMN ${def}`;
176
+ }
177
+ // Fallback for legacy behavior with just realDataType
171
178
  return `ALTER TABLE "${table.tableName}"
172
179
  ADD COLUMN "${table.name}" ${table.realDataType}`;
173
180
  }
@@ -108,6 +108,13 @@ class migrationSQLiteQuery {
108
108
  return `ALTER TABLE ${table.tableName}
109
109
  ADD COLUMN ${def}`;
110
110
  }
111
+ // Fixed: Support direct column definitions (when table itself IS the column spec)
112
+ // This matches MySQL/PostgreSQL behavior for explicit column definitions
113
+ if(table.type && table.tableName && table.name){
114
+ const def = this.#columnMapping(table);
115
+ return `ALTER TABLE ${table.tableName}
116
+ ADD COLUMN ${def}`;
117
+ }
111
118
  // Fallback legacy behavior: raw name provided must include full definition if caller wants type/constraints
112
119
  return `ALTER TABLE ${table.tableName}
113
120
  ADD COLUMN ${table.name}`;
@@ -24,11 +24,11 @@ class schema{
24
24
  if(this.context.isSQLite){
25
25
  var sqliteQuery = require("./migrationSQLiteQuery");
26
26
  var queryBuilder = new sqliteQuery();
27
- var queryObj = queryBuilder.alterColumn(this.fullTable.new, table);
28
- for (var key in queryObj) {
29
- var query = queryObj[key];
30
- this.context._execute(query);
31
- }
27
+ // Fixed: Use addColum (consistent with MySQL/PostgreSQL) instead of alterColumn
28
+ // This allows explicit column definitions to work, not just CLI-generated migrations
29
+ table.realDataType = queryBuilder.typeManager(table.type);
30
+ var query = queryBuilder.addColum(table);
31
+ this.context._execute(query);
32
32
  }
33
33
 
34
34
  if(this.context.isMySQL){
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "masterrecord",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "An Object-relational mapping for the Master framework. Master Record connects classes to relational database tables to establish a database with almost zero-configuration ",
5
5
  "main": "MasterRecord.js",
6
6
  "bin": {