@itrocks/mysql-maintainer 0.4.1 → 0.4.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.
- package/README.md +4 -0
- package/cjs/mysql-maintainer.js +12 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -99,6 +99,10 @@ operator resolves the duplicates, a later write retries the preflight.
|
|
|
99
99
|
|
|
100
100
|
## Persistent model requirements
|
|
101
101
|
|
|
102
|
+
Date and datetime columns use `NOT NULL` and zero dates for empty values. When maintenance changes a legacy nullable
|
|
103
|
+
date column, it replaces existing null values with the matching zero date before executing the `ALTER TABLE`.
|
|
104
|
+
Already populated dates are preserved.
|
|
105
|
+
|
|
102
106
|
Automatic maintenance derives database structure from business classes and their reflection metadata. Those classes
|
|
103
107
|
must follow the it.rocks persistent object conventions, including the decorators and metadata used by its ORM packages.
|
|
104
108
|
|
package/cjs/mysql-maintainer.js
CHANGED
|
@@ -5,6 +5,7 @@ const class_type_1 = require("@itrocks/class-type");
|
|
|
5
5
|
const mysql_1 = require("@itrocks/mysql");
|
|
6
6
|
const mysql_to_schema_1 = require("@itrocks/mysql-to-schema");
|
|
7
7
|
const reflect_to_schema_1 = require("@itrocks/reflect-to-schema");
|
|
8
|
+
const schema_1 = require("@itrocks/schema");
|
|
8
9
|
const schema_diff_1 = require("@itrocks/schema-diff");
|
|
9
10
|
const schema_diff_mysql_1 = require("@itrocks/schema-diff-mysql");
|
|
10
11
|
const schema_to_mysql_1 = require("@itrocks/schema-to-mysql");
|
|
@@ -105,6 +106,17 @@ CONSTRAINT \`${joinTable}.${table2}_id\` FOREIGN KEY (${table2}_id) REFERENCES \
|
|
|
105
106
|
}
|
|
106
107
|
const schemaDiffMysql = new schema_diff_mysql_1.SchemaDiffMysql();
|
|
107
108
|
const sql = schemaDiffMysql.sql(schemaDiff, DELETION);
|
|
109
|
+
for (const change of schemaDiff.changes) {
|
|
110
|
+
const source = change.source;
|
|
111
|
+
const target = change.target;
|
|
112
|
+
if (!(source instanceof schema_1.Column) || !(target instanceof schema_1.Column) || !source.canBeNull
|
|
113
|
+
|| !['date', 'datetime'].includes(target.type.name))
|
|
114
|
+
continue;
|
|
115
|
+
const column = '`' + source.name.replaceAll('`', '``') + '`';
|
|
116
|
+
const empty = (target.type.name === 'date') ? '0000-00-00' : '0000-00-00 00:00:00';
|
|
117
|
+
const table = '`' + tableName.replaceAll('`', '``') + '`';
|
|
118
|
+
await this.connection.query(`UPDATE ${table} SET ${column} = ? WHERE ${column} <=> NULL`, [empty]);
|
|
119
|
+
}
|
|
108
120
|
await this.connection.query(sql);
|
|
109
121
|
return true;
|
|
110
122
|
}
|
package/package.json
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"@itrocks/mysql-to-schema": "latest",
|
|
10
10
|
"@itrocks/reflect": "latest",
|
|
11
11
|
"@itrocks/reflect-to-schema": "latest",
|
|
12
|
+
"@itrocks/schema": "latest",
|
|
12
13
|
"@itrocks/schema-diff": "latest",
|
|
13
14
|
"@itrocks/schema-diff-mysql": "latest",
|
|
14
15
|
"@itrocks/schema-to-mysql": "latest",
|
|
@@ -60,5 +61,5 @@
|
|
|
60
61
|
"test": "npm run build && node --test \"test/**/*.test.mjs\"",
|
|
61
62
|
"test:integration": "npm run build && node --test \"test/**/*.integration.mjs\""
|
|
62
63
|
},
|
|
63
|
-
"version": "0.4.
|
|
64
|
+
"version": "0.4.2"
|
|
64
65
|
}
|