From 24628ec5a3cd167dc44a50017450d0dedec2c9ce Mon Sep 17 00:00:00 2001 From: killa Date: Fri, 22 Mar 2024 10:10:51 +0800 Subject: [PATCH] fix: set column canNull default to false (#195) ## Summary by CodeRabbit - **New Features** - Enhanced SQL query logging for table creation to aid in debugging. - **Bug Fixes** - Adjusted default `canNull` behavior in column definitions to enhance data integrity. - Updated various column definitions to include `NOT NULL` constraints, ensuring stricter data validation. - **Refactor** - Removed unused code and comments to clean up the codebase. - Improved flexibility in the data access layer by allowing reassignment of a key property. - **Tests** - Added and modified tests to reflect changes in SQL generation logic and column nullability. --- core/dal-decorator/src/model/ColumnModel.ts | 3 +- core/dal-decorator/src/model/TableModel.ts | 1 - core/dal-runtime/test/DataSource.test.ts | 1 + core/dal-runtime/test/SqlGenerator.test.ts | 76 +++++++++--------- .../test/fixtures/modules/dal/Foo.ts | 2 + .../generate_codes/dal/structure/Foo.json | 78 +++++++++---------- .../generate_codes/dal/structure/Foo.sql | 78 +++++++++---------- .../dal/structure/MultiPrimaryKey.json | 2 +- .../dal/structure/MultiPrimaryKey.sql | 2 +- plugin/dal/app.ts | 4 +- 10 files changed, 124 insertions(+), 123 deletions(-) diff --git a/core/dal-decorator/src/model/ColumnModel.ts b/core/dal-decorator/src/model/ColumnModel.ts index ec82b7e1..b3215410 100644 --- a/core/dal-decorator/src/model/ColumnModel.ts +++ b/core/dal-decorator/src/model/ColumnModel.ts @@ -52,8 +52,7 @@ export class ColumnModel { static build(property: string, type: ColumnTypeParams, params?: ColumnParams) { const columnName = params?.name ?? snakecase(property); - // TODO can null default should be false - let canNull = params?.canNull ?? true; + let canNull = params?.canNull ?? false; if (params?.primaryKey) { canNull = false; } diff --git a/core/dal-decorator/src/model/TableModel.ts b/core/dal-decorator/src/model/TableModel.ts index 7e5ed6df..a5fa73dc 100644 --- a/core/dal-decorator/src/model/TableModel.ts +++ b/core/dal-decorator/src/model/TableModel.ts @@ -104,7 +104,6 @@ export class TableModel { const name = params?.name ?? snakecase(pluralize(clazz.name)); const columnInfoMap = ColumnInfoUtil.getColumnInfoMap(clazz as EggProtoImplClass); const columnTypeMap = ColumnInfoUtil.getColumnTypeMap(clazz as EggProtoImplClass); - // TODO set to default name const dataSourceName = params?.dataSourceName ?? 'default'; assert(TableInfoUtil.getIsTable(clazz as EggProtoImplClass), `${name} is not Table`); assert(columnTypeMap, `${name} has no columns`); diff --git a/core/dal-runtime/test/DataSource.test.ts b/core/dal-runtime/test/DataSource.test.ts index 2a6ab357..1c4c81c1 100644 --- a/core/dal-runtime/test/DataSource.test.ts +++ b/core/dal-runtime/test/DataSource.test.ts @@ -29,6 +29,7 @@ describe('test/Datasource.test.ts', () => { const sqlGenerator = new SqlGenerator(); const createTableSql = sqlGenerator.generate(tableModel); + console.log('create table: ', createTableSql); await mysql.query(createTableSql); diff --git a/core/dal-runtime/test/SqlGenerator.test.ts b/core/dal-runtime/test/SqlGenerator.test.ts index 44e0bfa4..4d3ccc9a 100644 --- a/core/dal-runtime/test/SqlGenerator.test.ts +++ b/core/dal-runtime/test/SqlGenerator.test.ts @@ -10,45 +10,45 @@ describe('test/SqlGenerator.test.ts', () => { const sql = generator.generate(fooModel); assert.equal(sql, 'CREATE TABLE IF NOT EXISTS egg_foo (\n' + ' id INT NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT \'the primary key\',\n' + - ' name VARCHAR(100) NULL UNIQUE KEY,\n' + - ' col1 VARCHAR(100) NULL,\n' + - ' bit_column BIT(10) NULL,\n' + - ' bool_column BOOL NULL,\n' + - ' tiny_int_column TINYINT(5) UNSIGNED ZEROFILL NULL,\n' + - ' small_int_column SMALLINT(5) UNSIGNED ZEROFILL NULL,\n' + - ' medium_int_column MEDIUMINT(5) UNSIGNED ZEROFILL NULL,\n' + - ' int_column INT(5) UNSIGNED ZEROFILL NULL,\n' + - ' big_int_column BIGINT(5) UNSIGNED ZEROFILL NULL,\n' + - ' decimal_column DECIMAL(10,5) UNSIGNED ZEROFILL NULL,\n' + - ' float_column FLOAT(10,5) UNSIGNED ZEROFILL NULL,\n' + - ' double_column DOUBLE(10,5) UNSIGNED ZEROFILL NULL,\n' + - ' date_column DATE NULL,\n' + - ' date_time_column DATETIME(3) NULL,\n' + + ' name VARCHAR(100) NOT NULL UNIQUE KEY,\n' + + ' col1 VARCHAR(100) NOT NULL,\n' + + ' bit_column BIT(10) NOT NULL,\n' + + ' bool_column BOOL NOT NULL,\n' + + ' tiny_int_column TINYINT(5) UNSIGNED ZEROFILL NOT NULL,\n' + + ' small_int_column SMALLINT(5) UNSIGNED ZEROFILL NOT NULL,\n' + + ' medium_int_column MEDIUMINT(5) UNSIGNED ZEROFILL NOT NULL,\n' + + ' int_column INT(5) UNSIGNED ZEROFILL NOT NULL,\n' + + ' big_int_column BIGINT(5) UNSIGNED ZEROFILL NOT NULL,\n' + + ' decimal_column DECIMAL(10,5) UNSIGNED ZEROFILL NOT NULL,\n' + + ' float_column FLOAT(10,5) UNSIGNED ZEROFILL NOT NULL,\n' + + ' double_column DOUBLE(10,5) UNSIGNED ZEROFILL NOT NULL,\n' + + ' date_column DATE NOT NULL,\n' + + ' date_time_column DATETIME(3) NOT NULL,\n' + ' timestamp_column TIMESTAMP(3) NULL,\n' + - ' time_column TIME(3) NULL,\n' + - ' year_column YEAR NULL,\n' + - ' var_char_column VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL,\n' + - ' binary_column BINARY NULL,\n' + - ' var_binary_column VARBINARY(100) NULL,\n' + - ' tiny_blob_column TINYBLOB NULL,\n' + - ' tiny_text_column TINYTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL,\n' + - ' blob_column BLOB(100) NULL,\n' + - ' text_column TEXT(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL,\n' + - ' medium_blob_column MEDIUMBLOB NULL,\n' + - ' long_blob_column LONGBLOB NULL,\n' + - ' medium_text_column MEDIUMTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL,\n' + - ' long_text_column LONGTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL,\n' + - ' enum_column ENUM(\'A\',\'B\') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL,\n' + - ' set_column SET(\'A\',\'B\') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL,\n' + - ' geometry_column GEOMETRY NULL,\n' + - ' point_column POINT NULL,\n' + - ' line_string_column LINESTRING NULL,\n' + - ' polygon_column POLYGON NULL,\n' + - ' multipoint_column MULTIPOINT NULL,\n' + - ' multi_line_string_column MULTILINESTRING NULL,\n' + - ' multi_polygon_column MULTIPOLYGON NULL,\n' + - ' geometry_collection_column GEOMETRYCOLLECTION NULL,\n' + - ' json_column JSON NULL,\n' + + ' time_column TIME(3) NOT NULL,\n' + + ' year_column YEAR NOT NULL,\n' + + ' var_char_column VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,\n' + + ' binary_column BINARY NOT NULL,\n' + + ' var_binary_column VARBINARY(100) NOT NULL,\n' + + ' tiny_blob_column TINYBLOB NOT NULL,\n' + + ' tiny_text_column TINYTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,\n' + + ' blob_column BLOB(100) NOT NULL,\n' + + ' text_column TEXT(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,\n' + + ' medium_blob_column MEDIUMBLOB NOT NULL,\n' + + ' long_blob_column LONGBLOB NOT NULL,\n' + + ' medium_text_column MEDIUMTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,\n' + + ' long_text_column LONGTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,\n' + + ' enum_column ENUM(\'A\',\'B\') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,\n' + + ' set_column SET(\'A\',\'B\') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,\n' + + ' geometry_column GEOMETRY NOT NULL,\n' + + ' point_column POINT NOT NULL,\n' + + ' line_string_column LINESTRING NOT NULL,\n' + + ' polygon_column POLYGON NOT NULL,\n' + + ' multipoint_column MULTIPOINT NOT NULL,\n' + + ' multi_line_string_column MULTILINESTRING NOT NULL,\n' + + ' multi_polygon_column MULTIPOLYGON NOT NULL,\n' + + ' geometry_collection_column GEOMETRYCOLLECTION NOT NULL,\n' + + ' json_column JSON NOT NULL,\n' + ' FULLTEXT KEY idx_col1 (col1) COMMENT \'index comment\\n\',\n' + ' UNIQUE KEY uk_name_col1 (name,col1) USING BTREE COMMENT \'index comment\\n\'\n' + ') DEFAULT CHARACTER SET utf8mb4, DEFAULT COLLATE utf8mb4_unicode_ci, COMMENT=\'foo table\';'); diff --git a/core/dal-runtime/test/fixtures/modules/dal/Foo.ts b/core/dal-runtime/test/fixtures/modules/dal/Foo.ts index cbf4cad8..2afdaab7 100644 --- a/core/dal-runtime/test/fixtures/modules/dal/Foo.ts +++ b/core/dal-runtime/test/fixtures/modules/dal/Foo.ts @@ -163,6 +163,8 @@ export class Foo { @Column({ type: ColumnType.TIMESTAMP, precision: 3, + }, { + canNull: true, }) timestampColumn: Date; diff --git a/core/dal-runtime/test/fixtures/modules/generate_codes/dal/structure/Foo.json b/core/dal-runtime/test/fixtures/modules/generate_codes/dal/structure/Foo.json index 1edd9fff..69b3b69c 100644 --- a/core/dal-runtime/test/fixtures/modules/generate_codes/dal/structure/Foo.json +++ b/core/dal-runtime/test/fixtures/modules/generate_codes/dal/structure/Foo.json @@ -20,7 +20,7 @@ "type": "VARCHAR", "length": 100 }, - "canNull": true, + "canNull": false, "uniqueKey": true }, { @@ -30,7 +30,7 @@ "type": "VARCHAR", "length": 100 }, - "canNull": true + "canNull": false }, { "columnName": "bit_column", @@ -39,7 +39,7 @@ "type": "BIT", "length": 10 }, - "canNull": true + "canNull": false }, { "columnName": "bool_column", @@ -47,7 +47,7 @@ "type": { "type": "BOOL" }, - "canNull": true + "canNull": false }, { "columnName": "tiny_int_column", @@ -58,7 +58,7 @@ "unsigned": true, "zeroFill": true }, - "canNull": true + "canNull": false }, { "columnName": "small_int_column", @@ -69,7 +69,7 @@ "unsigned": true, "zeroFill": true }, - "canNull": true + "canNull": false }, { "columnName": "medium_int_column", @@ -80,7 +80,7 @@ "unsigned": true, "zeroFill": true }, - "canNull": true + "canNull": false }, { "columnName": "int_column", @@ -91,7 +91,7 @@ "unsigned": true, "zeroFill": true }, - "canNull": true + "canNull": false }, { "columnName": "big_int_column", @@ -102,7 +102,7 @@ "unsigned": true, "zeroFill": true }, - "canNull": true + "canNull": false }, { "columnName": "decimal_column", @@ -114,7 +114,7 @@ "unsigned": true, "zeroFill": true }, - "canNull": true + "canNull": false }, { "columnName": "float_column", @@ -126,7 +126,7 @@ "unsigned": true, "zeroFill": true }, - "canNull": true + "canNull": false }, { "columnName": "double_column", @@ -138,7 +138,7 @@ "unsigned": true, "zeroFill": true }, - "canNull": true + "canNull": false }, { "columnName": "date_column", @@ -146,7 +146,7 @@ "type": { "type": "DATE" }, - "canNull": true + "canNull": false }, { "columnName": "date_time_column", @@ -155,7 +155,7 @@ "type": "DATETIME", "precision": 3 }, - "canNull": true + "canNull": false }, { "columnName": "timestamp_column", @@ -164,7 +164,7 @@ "type": "TIMESTAMP", "precision": 3 }, - "canNull": true + "canNull": false }, { "columnName": "time_column", @@ -173,7 +173,7 @@ "type": "TIME", "precision": 3 }, - "canNull": true + "canNull": false }, { "columnName": "year_column", @@ -181,7 +181,7 @@ "type": { "type": "YEAR" }, - "canNull": true + "canNull": false }, { "columnName": "var_char_column", @@ -192,7 +192,7 @@ "characterSet": "utf8mb4", "collate": "utf8mb4_unicode_ci" }, - "canNull": true + "canNull": false }, { "columnName": "binary_column", @@ -200,7 +200,7 @@ "type": { "type": "BINARY" }, - "canNull": true + "canNull": false }, { "columnName": "var_binary_column", @@ -209,7 +209,7 @@ "type": "VARBINARY", "length": 100 }, - "canNull": true + "canNull": false }, { "columnName": "tiny_blob_column", @@ -217,7 +217,7 @@ "type": { "type": "TINYBLOB" }, - "canNull": true + "canNull": false }, { "columnName": "tiny_text_column", @@ -227,7 +227,7 @@ "characterSet": "utf8mb4", "collate": "utf8mb4_unicode_ci" }, - "canNull": true + "canNull": false }, { "columnName": "blob_column", @@ -236,7 +236,7 @@ "type": "BLOB", "length": 100 }, - "canNull": true + "canNull": false }, { "columnName": "text_column", @@ -247,7 +247,7 @@ "characterSet": "utf8mb4", "collate": "utf8mb4_unicode_ci" }, - "canNull": true + "canNull": false }, { "columnName": "medium_blob_column", @@ -255,7 +255,7 @@ "type": { "type": "MEDIUMBLOB" }, - "canNull": true + "canNull": false }, { "columnName": "long_blob_column", @@ -263,7 +263,7 @@ "type": { "type": "LONGBLOB" }, - "canNull": true + "canNull": false }, { "columnName": "medium_text_column", @@ -273,7 +273,7 @@ "characterSet": "utf8mb4", "collate": "utf8mb4_unicode_ci" }, - "canNull": true + "canNull": false }, { "columnName": "long_text_column", @@ -283,7 +283,7 @@ "characterSet": "utf8mb4", "collate": "utf8mb4_unicode_ci" }, - "canNull": true + "canNull": false }, { "columnName": "enum_column", @@ -297,7 +297,7 @@ "characterSet": "utf8mb4", "collate": "utf8mb4_unicode_ci" }, - "canNull": true + "canNull": false }, { "columnName": "set_column", @@ -311,7 +311,7 @@ "characterSet": "utf8mb4", "collate": "utf8mb4_unicode_ci" }, - "canNull": true + "canNull": false }, { "columnName": "geometry_column", @@ -319,7 +319,7 @@ "type": { "type": "GEOMETRY" }, - "canNull": true + "canNull": false }, { "columnName": "point_column", @@ -327,7 +327,7 @@ "type": { "type": "POINT" }, - "canNull": true + "canNull": false }, { "columnName": "line_string_column", @@ -335,7 +335,7 @@ "type": { "type": "LINESTRING" }, - "canNull": true + "canNull": false }, { "columnName": "polygon_column", @@ -343,7 +343,7 @@ "type": { "type": "POLYGON" }, - "canNull": true + "canNull": false }, { "columnName": "multipoint_column", @@ -351,7 +351,7 @@ "type": { "type": "MULTIPOINT" }, - "canNull": true + "canNull": false }, { "columnName": "multi_line_string_column", @@ -359,7 +359,7 @@ "type": { "type": "MULTILINESTRING" }, - "canNull": true + "canNull": false }, { "columnName": "multi_polygon_column", @@ -367,7 +367,7 @@ "type": { "type": "MULTIPOLYGON" }, - "canNull": true + "canNull": false }, { "columnName": "geometry_collection_column", @@ -375,7 +375,7 @@ "type": { "type": "GEOMETRYCOLLECTION" }, - "canNull": true + "canNull": false }, { "columnName": "json_column", @@ -383,7 +383,7 @@ "type": { "type": "JSON" }, - "canNull": true + "canNull": false } ], "indices": [ diff --git a/core/dal-runtime/test/fixtures/modules/generate_codes/dal/structure/Foo.sql b/core/dal-runtime/test/fixtures/modules/generate_codes/dal/structure/Foo.sql index 104f7260..096b2848 100644 --- a/core/dal-runtime/test/fixtures/modules/generate_codes/dal/structure/Foo.sql +++ b/core/dal-runtime/test/fixtures/modules/generate_codes/dal/structure/Foo.sql @@ -1,44 +1,44 @@ CREATE TABLE IF NOT EXISTS egg_foo ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'the primary key', - name VARCHAR(100) NULL UNIQUE KEY, - col1 VARCHAR(100) NULL, - bit_column BIT(10) NULL, - bool_column BOOL NULL, - tiny_int_column TINYINT(5) UNSIGNED ZEROFILL NULL, - small_int_column SMALLINT(5) UNSIGNED ZEROFILL NULL, - medium_int_column MEDIUMINT(5) UNSIGNED ZEROFILL NULL, - int_column INT(5) UNSIGNED ZEROFILL NULL, - big_int_column BIGINT(5) UNSIGNED ZEROFILL NULL, - decimal_column DECIMAL(10,5) UNSIGNED ZEROFILL NULL, - float_column FLOAT(10,5) UNSIGNED ZEROFILL NULL, - double_column DOUBLE(10,5) UNSIGNED ZEROFILL NULL, - date_column DATE NULL, - date_time_column DATETIME(3) NULL, - timestamp_column TIMESTAMP(3) NULL, - time_column TIME(3) NULL, - year_column YEAR NULL, - var_char_column VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL, - binary_column BINARY NULL, - var_binary_column VARBINARY(100) NULL, - tiny_blob_column TINYBLOB NULL, - tiny_text_column TINYTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL, - blob_column BLOB(100) NULL, - text_column TEXT(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL, - medium_blob_column MEDIUMBLOB NULL, - long_blob_column LONGBLOB NULL, - medium_text_column MEDIUMTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL, - long_text_column LONGTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL, - enum_column ENUM('A','B') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL, - set_column SET('A','B') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL, - geometry_column GEOMETRY NULL, - point_column POINT NULL, - line_string_column LINESTRING NULL, - polygon_column POLYGON NULL, - multipoint_column MULTIPOINT NULL, - multi_line_string_column MULTILINESTRING NULL, - multi_polygon_column MULTIPOLYGON NULL, - geometry_collection_column GEOMETRYCOLLECTION NULL, - json_column JSON NULL, + name VARCHAR(100) NOT NULL UNIQUE KEY, + col1 VARCHAR(100) NOT NULL, + bit_column BIT(10) NOT NULL, + bool_column BOOL NOT NULL, + tiny_int_column TINYINT(5) UNSIGNED ZEROFILL NOT NULL, + small_int_column SMALLINT(5) UNSIGNED ZEROFILL NOT NULL, + medium_int_column MEDIUMINT(5) UNSIGNED ZEROFILL NOT NULL, + int_column INT(5) UNSIGNED ZEROFILL NOT NULL, + big_int_column BIGINT(5) UNSIGNED ZEROFILL NOT NULL, + decimal_column DECIMAL(10,5) UNSIGNED ZEROFILL NOT NULL, + float_column FLOAT(10,5) UNSIGNED ZEROFILL NOT NULL, + double_column DOUBLE(10,5) UNSIGNED ZEROFILL NOT NULL, + date_column DATE NOT NULL, + date_time_column DATETIME(3) NOT NULL, + timestamp_column TIMESTAMP(3) NOT NULL, + time_column TIME(3) NOT NULL, + year_column YEAR NOT NULL, + var_char_column VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, + binary_column BINARY NOT NULL, + var_binary_column VARBINARY(100) NOT NULL, + tiny_blob_column TINYBLOB NOT NULL, + tiny_text_column TINYTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, + blob_column BLOB(100) NOT NULL, + text_column TEXT(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, + medium_blob_column MEDIUMBLOB NOT NULL, + long_blob_column LONGBLOB NOT NULL, + medium_text_column MEDIUMTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, + long_text_column LONGTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, + enum_column ENUM('A','B') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, + set_column SET('A','B') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, + geometry_column GEOMETRY NOT NULL, + point_column POINT NOT NULL, + line_string_column LINESTRING NOT NULL, + polygon_column POLYGON NOT NULL, + multipoint_column MULTIPOINT NOT NULL, + multi_line_string_column MULTILINESTRING NOT NULL, + multi_polygon_column MULTIPOLYGON NOT NULL, + geometry_collection_column GEOMETRYCOLLECTION NOT NULL, + json_column JSON NOT NULL, FULLTEXT KEY idx_col1 (col1) COMMENT 'index comment\n', UNIQUE KEY uk_name_col1 (name,col1) USING BTREE COMMENT 'index comment\n' ) DEFAULT CHARACTER SET utf8mb4, DEFAULT COLLATE utf8mb4_unicode_ci, COMMENT='foo table'; \ No newline at end of file diff --git a/core/dal-runtime/test/fixtures/modules/generate_codes/dal/structure/MultiPrimaryKey.json b/core/dal-runtime/test/fixtures/modules/generate_codes/dal/structure/MultiPrimaryKey.json index 8d4e19e7..17c32eef 100644 --- a/core/dal-runtime/test/fixtures/modules/generate_codes/dal/structure/MultiPrimaryKey.json +++ b/core/dal-runtime/test/fixtures/modules/generate_codes/dal/structure/MultiPrimaryKey.json @@ -31,7 +31,7 @@ "type": "VARCHAR", "length": 100 }, - "canNull": true, + "canNull": false, "uniqueKey": true } ], diff --git a/core/dal-runtime/test/fixtures/modules/generate_codes/dal/structure/MultiPrimaryKey.sql b/core/dal-runtime/test/fixtures/modules/generate_codes/dal/structure/MultiPrimaryKey.sql index 4cbfedf3..5fe4a711 100644 --- a/core/dal-runtime/test/fixtures/modules/generate_codes/dal/structure/MultiPrimaryKey.sql +++ b/core/dal-runtime/test/fixtures/modules/generate_codes/dal/structure/MultiPrimaryKey.sql @@ -1,5 +1,5 @@ CREATE TABLE IF NOT EXISTS multi_primary_key_table ( id_1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'the primary key', id_2 INT NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'the primary key', - name VARCHAR(100) NULL UNIQUE KEY + name VARCHAR(100) NOT NULL UNIQUE KEY ) COMMENT='multi primary key table'; \ No newline at end of file diff --git a/plugin/dal/app.ts b/plugin/dal/app.ts index be0c50ef..45e2e65e 100644 --- a/plugin/dal/app.ts +++ b/plugin/dal/app.ts @@ -7,16 +7,16 @@ import { DalModuleLoadUnitHook } from './lib/DalModuleLoadUnitHook'; export default class ControllerAppBootHook { private readonly app: Application; - private readonly dalTableEggPrototypeHook: DalTableEggPrototypeHook; + private dalTableEggPrototypeHook: DalTableEggPrototypeHook; private dalModuleLoadUnitHook: DalModuleLoadUnitHook; constructor(app: Application) { this.app = app; - this.dalTableEggPrototypeHook = new DalTableEggPrototypeHook(this.app.logger); } configWillLoad() { this.dalModuleLoadUnitHook = new DalModuleLoadUnitHook(this.app.moduleConfigs); + this.dalTableEggPrototypeHook = new DalTableEggPrototypeHook(this.app.logger); this.app.eggPrototypeLifecycleUtil.registerLifecycle(this.dalTableEggPrototypeHook); this.app.loadUnitLifecycleUtil.registerLifecycle(this.dalModuleLoadUnitHook); }