gg-mysql-connector 1.0.92 → 1.0.93

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.
@@ -25,7 +25,7 @@ class MyDBMigrator {
25
25
  await this.alterDataType(row.tableName, col);
26
26
  await this.alterUniqueKey(row.tableName, col.COLUMN_NAME, col.IS_UNIQUE);
27
27
  await this.alterIndex(row.tableName, col.COLUMN_NAME, col.IS_INDEX);
28
- await this.alterPossibleEnum(row.tableName, col.COLUMN_NAME, col.POSSIBLE_VALUE);
28
+ await this.alterPossibleEnum(row.tableName, col.COLUMN_NAME, col.POSSIBLE_VALUE, col.IS_NOT_NULL);
29
29
  await this.alterForeignKey(row.tableName, col);
30
30
  }
31
31
  await this.alterUniqueColumnCombination(row.tableName, row.compoisteUniqueColumn);
@@ -88,14 +88,15 @@ class MyDBMigrator {
88
88
  const columnDefault = col.COLUMN_DEFAULT
89
89
  ? `DEFAULT ${col.COLUMN_DEFAULT}`
90
90
  : "";
91
+ const notNull = col.IS_NOT_NULL ? "NOT NULL" : "";
91
92
  const isColumnChange = await this.checkIsColumnDataTypeChange(tableName, col.COLUMN_NAME, col.DATA_TYPE, col.COLUMN_DEFAULT);
92
93
  if (isColumnChange) {
93
94
  const isColumnExist = await this.columnInTableExist(tableName, col.COLUMN_NAME);
94
95
  if (!isColumnExist) {
95
- await this.MyDB.query(`ALTER TABLE ${tableName} ADD COLUMN ${col.COLUMN_NAME} ${col.DATA_TYPE} ${AutoIncrement} ${columnDefault}`);
96
+ await this.MyDB.query(`ALTER TABLE ${tableName} ADD COLUMN ${col.COLUMN_NAME} ${col.DATA_TYPE} ${AutoIncrement} ${notNull} ${columnDefault}`);
96
97
  }
97
98
  else {
98
- await this.MyDB.query(`ALTER TABLE ${tableName} MODIFY COLUMN ${col.COLUMN_NAME} ${col.DATA_TYPE} ${AutoIncrement} ${columnDefault}`);
99
+ await this.MyDB.query(`ALTER TABLE ${tableName} MODIFY COLUMN ${col.COLUMN_NAME} ${col.DATA_TYPE} ${AutoIncrement} ${notNull} ${columnDefault}`);
99
100
  }
100
101
  }
101
102
  }
@@ -178,16 +179,17 @@ class MyDBMigrator {
178
179
  }
179
180
  }
180
181
  }
181
- async alterPossibleEnum(tableName, columnName, possibleValue) {
182
+ async alterPossibleEnum(tableName, columnName, possibleValue, isNotNull) {
182
183
  if (!possibleValue)
183
184
  return null;
184
185
  const data = this.onetimeLoadColumnContent.find((row) => row.COLUMN_NAME === columnName && row.TABLE_NAME === tableName);
186
+ const notNull = isNotNull ? "NOT NULL" : "";
185
187
  if (data) {
186
188
  let possibleValueString = possibleValue
187
189
  .map((row) => `"${row}"`)
188
190
  .join(", ");
189
191
  try {
190
- await this.MyDB.query(`ALTER TABLE ${tableName} MODIFY COLUMN ${columnName} ENUM(${possibleValueString}) ;`);
192
+ await this.MyDB.query(`ALTER TABLE ${tableName} MODIFY COLUMN ${columnName} ENUM(${possibleValueString}) ${notNull} ;`);
191
193
  }
192
194
  catch (e) {
193
195
  const data = await this.MyDB.query(`SELECT DISTINCT(${columnName}) as columnValue FROM ${tableName}`);
@@ -14,6 +14,7 @@ export interface columnContent {
14
14
  }[];
15
15
  IS_UNIQUE?: boolean;
16
16
  IS_INDEX?: boolean;
17
+ IS_NOT_NULL?: boolean;
17
18
  }
18
19
  export interface compoisteUniqueColumn {
19
20
  columnName: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gg-mysql-connector",
3
- "version": "1.0.92",
3
+ "version": "1.0.93",
4
4
  "description": "",
5
5
  "main": "dist/src/index.js",
6
6
  "scripts": {
@@ -41,7 +41,8 @@ export default class MyDBMigrator {
41
41
  await this.alterPossibleEnum(
42
42
  row.tableName,
43
43
  col.COLUMN_NAME,
44
- col.POSSIBLE_VALUE
44
+ col.POSSIBLE_VALUE,
45
+ col.IS_NOT_NULL
45
46
  )
46
47
  await this.alterForeignKey(row.tableName, col)
47
48
  }
@@ -143,6 +144,7 @@ export default class MyDBMigrator {
143
144
  const columnDefault = col.COLUMN_DEFAULT
144
145
  ? `DEFAULT ${col.COLUMN_DEFAULT}`
145
146
  : ""
147
+ const notNull = col.IS_NOT_NULL ? "NOT NULL" : ""
146
148
  const isColumnChange = await this.checkIsColumnDataTypeChange(
147
149
  tableName,
148
150
  col.COLUMN_NAME,
@@ -156,11 +158,11 @@ export default class MyDBMigrator {
156
158
  )
157
159
  if (!isColumnExist) {
158
160
  await this.MyDB.query(
159
- `ALTER TABLE ${tableName} ADD COLUMN ${col.COLUMN_NAME} ${col.DATA_TYPE} ${AutoIncrement} ${columnDefault}`
161
+ `ALTER TABLE ${tableName} ADD COLUMN ${col.COLUMN_NAME} ${col.DATA_TYPE} ${AutoIncrement} ${notNull} ${columnDefault}`
160
162
  )
161
163
  } else {
162
164
  await this.MyDB.query(
163
- `ALTER TABLE ${tableName} MODIFY COLUMN ${col.COLUMN_NAME} ${col.DATA_TYPE} ${AutoIncrement} ${columnDefault}`
165
+ `ALTER TABLE ${tableName} MODIFY COLUMN ${col.COLUMN_NAME} ${col.DATA_TYPE} ${AutoIncrement} ${notNull} ${columnDefault}`
164
166
  )
165
167
  }
166
168
  }
@@ -294,12 +296,14 @@ export default class MyDBMigrator {
294
296
  private async alterPossibleEnum(
295
297
  tableName: string,
296
298
  columnName: string,
297
- possibleValue?: string[]
299
+ possibleValue?: string[],
300
+ isNotNull?: boolean
298
301
  ) {
299
302
  if (!possibleValue) return null
300
303
  const data = this.onetimeLoadColumnContent.find(
301
304
  (row) => row.COLUMN_NAME === columnName && row.TABLE_NAME === tableName
302
305
  )
306
+ const notNull = isNotNull ? "NOT NULL" : ""
303
307
  if (data) {
304
308
  let possibleValueString = possibleValue
305
309
  .map((row) => `"${row}"`)
@@ -307,7 +311,7 @@ export default class MyDBMigrator {
307
311
 
308
312
  try {
309
313
  await this.MyDB.query(
310
- `ALTER TABLE ${tableName} MODIFY COLUMN ${columnName} ENUM(${possibleValueString}) ;`
314
+ `ALTER TABLE ${tableName} MODIFY COLUMN ${columnName} ENUM(${possibleValueString}) ${notNull} ;`
311
315
  )
312
316
  } catch (e) {
313
317
  const data: { columnValue: any }[] = await this.MyDB.query(
package/src/myModel.ts CHANGED
@@ -31,6 +31,7 @@ export interface columnContent {
31
31
  }[]
32
32
  IS_UNIQUE?: boolean
33
33
  IS_INDEX?: boolean
34
+ IS_NOT_NULL?: boolean
34
35
  }
35
36
 
36
37
  export interface compoisteUniqueColumn {