db-modeling-markdown 2.0.1 → 2.1.0
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 +168 -164
- package/dist/dialects/core/dbImportProvider.d.ts +5 -5
- package/dist/dialects/core/dbImportProvider.js +6 -6
- package/dist/dialects/core/dbProvider.d.ts +34 -34
- package/dist/dialects/core/dbProvider.js +119 -119
- package/dist/dialects/core/dbProvider.js.map +1 -1
- package/dist/dialects/core/dbUtils.d.ts +35 -35
- package/dist/dialects/core/dbUtils.js +157 -158
- package/dist/dialects/core/dbUtils.js.map +1 -1
- package/dist/dialects/core/providerFactory.d.ts +7 -7
- package/dist/dialects/core/providerFactory.js +63 -63
- package/dist/dialects/core/providerFactory.js.map +1 -1
- package/dist/dialects/db2/db2Provider.d.ts +19 -19
- package/dist/dialects/db2/db2Provider.js +185 -186
- package/dist/dialects/db2/db2Provider.js.map +1 -1
- package/dist/dialects/mariadb/mariaDbImportProvider.d.ts +19 -19
- package/dist/dialects/mariadb/mariaDbImportProvider.js +260 -253
- package/dist/dialects/mariadb/mariaDbImportProvider.js.map +1 -1
- package/dist/dialects/mariadb/mariaDbProvider.d.ts +18 -18
- package/dist/dialects/mariadb/mariaDbProvider.js +152 -153
- package/dist/dialects/mariadb/mariaDbProvider.js.map +1 -1
- package/dist/dialects/mariadb/mariaDbUtil.d.ts +6 -6
- package/dist/dialects/mariadb/mariaDbUtil.js +22 -22
- package/dist/dialects/mariadb/mariaDbUtil.js.map +1 -1
- package/dist/dialects/mssql/msSqlProvider.d.ts +21 -21
- package/dist/dialects/mssql/msSqlProvider.js +264 -265
- package/dist/dialects/mssql/msSqlProvider.js.map +1 -1
- package/dist/dialects/mysql/mySqlImportProvider.d.ts +3 -3
- package/dist/dialects/mysql/mySqlImportProvider.js +7 -7
- package/dist/dialects/mysql/mySqlProvider.d.ts +3 -3
- package/dist/dialects/mysql/mySqlProvider.js +7 -7
- package/dist/dialects/oracle/oracleProvider.d.ts +35 -35
- package/dist/dialects/oracle/oracleProvider.js +327 -327
- package/dist/dialects/oracle/oracleProvider.js.map +1 -1
- package/dist/dialects/postgresql/postgreSqlProvider.d.ts +19 -19
- package/dist/dialects/postgresql/postgreSqlProvider.js +172 -173
- package/dist/dialects/postgresql/postgreSqlProvider.js.map +1 -1
- package/dist/dialects/sqlite/sqliteSqlProvider.d.ts +23 -23
- package/dist/dialects/sqlite/sqliteSqlProvider.js +147 -148
- package/dist/dialects/sqlite/sqliteSqlProvider.js.map +1 -1
- package/dist/index.d.ts +10 -10
- package/dist/index.js +9 -9
- package/dist/lib/code-flow/codeFlow.d.ts +37 -37
- package/dist/lib/code-flow/codeFlow.js +61 -61
- package/dist/lib/markdown-object/markdownModel.d.ts +14 -14
- package/dist/lib/markdown-object/markdownModel.js +12 -12
- package/dist/lib/markdown-object/markdownModel.js.map +1 -1
- package/dist/lib/markdown-object/markdownReader.d.ts +39 -39
- package/dist/lib/markdown-object/markdownReader.js +261 -258
- package/dist/lib/markdown-object/markdownReader.js.map +1 -1
- package/dist/lib/markdown-object/markdownWriter.d.ts +36 -36
- package/dist/lib/markdown-object/markdownWriter.js +224 -223
- package/dist/lib/markdown-object/markdownWriter.js.map +1 -1
- package/dist/lib/markdown-object/readerContext.d.ts +12 -12
- package/dist/lib/markdown-object/readerContext.js +48 -48
- package/dist/lib/markdown-object/readerContext.js.map +1 -1
- package/dist/lib/utils/fileHelper.d.ts +14 -15
- package/dist/lib/utils/fileHelper.js +58 -57
- package/dist/lib/utils/fileHelper.js.map +1 -1
- package/dist/lib/utils/logger.d.ts +9 -9
- package/dist/lib/utils/logger.js +60 -60
- package/dist/lib/utils/logger.js.map +1 -1
- package/dist/lib/utils/markdownParser.d.ts +22 -22
- package/dist/lib/utils/markdownParser.js +99 -95
- package/dist/lib/utils/markdownParser.js.map +1 -1
- package/dist/lib/utils/sqlHelper.d.ts +3 -3
- package/dist/lib/utils/sqlHelper.js +23 -23
- package/dist/lib/utils/sqlHelper.js.map +1 -1
- package/dist/lib/utils/systemHelper.d.ts +2 -2
- package/dist/lib/utils/systemHelper.js +6 -6
- package/dist/lib/utils/textFileReader.d.ts +25 -25
- package/dist/lib/utils/textFileReader.js +57 -57
- package/dist/lib/utils/textFileReader.js.map +1 -1
- package/dist/lib/utils/textHelper.d.ts +21 -21
- package/dist/lib/utils/textHelper.js +75 -71
- package/dist/lib/utils/textHelper.js.map +1 -1
- package/dist/models/databaseTypes.d.ts +33 -33
- package/dist/models/databaseTypes.js +37 -37
- package/dist/models/databaseTypes.js.map +1 -1
- package/dist/models/dbColumn.d.ts +43 -43
- package/dist/models/dbColumn.js +2 -2
- package/dist/models/dbDiffModel.d.ts +43 -43
- package/dist/models/dbDiffModel.js +2 -2
- package/dist/models/dbForeignKey.d.ts +33 -33
- package/dist/models/dbForeignKey.js +2 -2
- package/dist/models/dbIndex.d.ts +28 -28
- package/dist/models/dbIndex.js +2 -2
- package/dist/models/dbIndexType.d.ts +8 -8
- package/dist/models/dbIndexType.js +12 -12
- package/dist/models/dbIndexType.js.map +1 -1
- package/dist/models/dbModel.d.ts +10 -10
- package/dist/models/dbModel.js +2 -2
- package/dist/models/dbPrimaryKey.d.ts +16 -16
- package/dist/models/dbPrimaryKey.js +2 -2
- package/dist/models/dbTable.d.ts +49 -49
- package/dist/models/dbTable.js +2 -2
- package/dist/models/dbTableMarkdown.d.ts +35 -34
- package/dist/models/dbTableMarkdown.js +2 -2
- package/dist/resources/mariadb/procAppUpgradeDB.sql +164 -0
- package/dist/resources/mariadb/sql-create-table-fk.njk +10 -0
- package/dist/resources/mariadb/sql-create-table.njk +12 -0
- package/dist/resources/mariadb/sql-create-tables.njk +9 -0
- package/dist/resources/mariadb/sql-drop-tables.njk +10 -0
- package/dist/resources/mariadb/sql-drop-then-create-tables.njk +4 -0
- package/dist/resources/mariadb/sql-upgrade-new-table.njk +15 -0
- package/dist/resources/mariadb/sql-upgrade-table-fk.njk +10 -0
- package/dist/resources/mariadb/sql-upgrade-table.njk +41 -0
- package/dist/resources/mariadb/sql-upgrade-tables.njk +19 -0
- package/dist/services/dbOptions.d.ts +35 -35
- package/dist/services/dbOptions.js +17 -17
- package/dist/services/dbmOptions.d.ts +28 -28
- package/dist/services/dbmOptions.js +34 -34
- package/dist/services/dbmService.d.ts +87 -87
- package/dist/services/dbmService.js +244 -246
- package/dist/services/dbmService.js.map +1 -1
- package/package.json +29 -34
- package/CHANGELOG.md +0 -81
- package/CONTRIBUTING.md +0 -82
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DbIndexType = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Describe the table index type
|
|
6
|
-
*/
|
|
7
|
-
var DbIndexType;
|
|
8
|
-
(function (DbIndexType) {
|
|
9
|
-
DbIndexType["FullText"] = "FullText";
|
|
10
|
-
DbIndexType["Index"] = "Index";
|
|
11
|
-
DbIndexType["PrimaryKey"] = "Primary Key";
|
|
12
|
-
})(DbIndexType
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DbIndexType = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Describe the table index type
|
|
6
|
+
*/
|
|
7
|
+
var DbIndexType;
|
|
8
|
+
(function (DbIndexType) {
|
|
9
|
+
DbIndexType["FullText"] = "FullText";
|
|
10
|
+
DbIndexType["Index"] = "Index";
|
|
11
|
+
DbIndexType["PrimaryKey"] = "Primary Key";
|
|
12
|
+
})(DbIndexType || (exports.DbIndexType = DbIndexType = {}));
|
|
13
13
|
//# sourceMappingURL=dbIndexType.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dbIndexType.js","sourceRoot":"","sources":["../../src/models/dbIndexType.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,IAAY,WAIX;AAJD,WAAY,WAAW;IACtB,oCAAqB,CAAA;IACrB,8BAAe,CAAA;IACf,yCAA0B,CAAA;AAC3B,CAAC,EAJW,WAAW,
|
|
1
|
+
{"version":3,"file":"dbIndexType.js","sourceRoot":"","sources":["../../src/models/dbIndexType.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,IAAY,WAIX;AAJD,WAAY,WAAW;IACtB,oCAAqB,CAAA;IACrB,8BAAe,CAAA;IACf,yCAA0B,CAAA;AAC3B,CAAC,EAJW,WAAW,2BAAX,WAAW,QAItB"}
|
package/dist/models/dbModel.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { DbTable } from './dbTable';
|
|
2
|
-
/**
|
|
3
|
-
* Describe a database model
|
|
4
|
-
*/
|
|
5
|
-
export interface DbModel {
|
|
6
|
-
/**
|
|
7
|
-
* The model tables
|
|
8
|
-
*/
|
|
9
|
-
tables: DbTable[];
|
|
10
|
-
}
|
|
1
|
+
import { DbTable } from './dbTable';
|
|
2
|
+
/**
|
|
3
|
+
* Describe a database model
|
|
4
|
+
*/
|
|
5
|
+
export interface DbModel {
|
|
6
|
+
/**
|
|
7
|
+
* The model tables
|
|
8
|
+
*/
|
|
9
|
+
tables: DbTable[];
|
|
10
|
+
}
|
package/dist/models/dbModel.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=dbModel.js.map
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Describe table primary key
|
|
3
|
-
*/
|
|
4
|
-
export interface DbPrimaryKey {
|
|
5
|
-
/**
|
|
6
|
-
* If the primary key is clusterred
|
|
7
|
-
*/
|
|
8
|
-
cluster?: boolean;
|
|
9
|
-
/**
|
|
10
|
-
* The primary key columns.
|
|
11
|
-
*
|
|
12
|
-
* Use comma `,` to split multiple columns.
|
|
13
|
-
* E.g. `column, column2`
|
|
14
|
-
*/
|
|
15
|
-
columns: string;
|
|
16
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Describe table primary key
|
|
3
|
+
*/
|
|
4
|
+
export interface DbPrimaryKey {
|
|
5
|
+
/**
|
|
6
|
+
* If the primary key is clusterred
|
|
7
|
+
*/
|
|
8
|
+
cluster?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* The primary key columns.
|
|
11
|
+
*
|
|
12
|
+
* Use comma `,` to split multiple columns.
|
|
13
|
+
* E.g. `column, column2`
|
|
14
|
+
*/
|
|
15
|
+
columns: string;
|
|
16
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=dbPrimaryKey.js.map
|
package/dist/models/dbTable.d.ts
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import { DbColumn } from './dbColumn';
|
|
2
|
-
import { DbForeignKey } from './dbForeignKey';
|
|
3
|
-
import { DbIndex } from './dbIndex';
|
|
4
|
-
import { DbPrimaryKey } from './dbPrimaryKey';
|
|
5
|
-
/**
|
|
6
|
-
* Describe a table
|
|
7
|
-
*/
|
|
8
|
-
export interface DbTable {
|
|
9
|
-
/**
|
|
10
|
-
* auto increment start
|
|
11
|
-
*/
|
|
12
|
-
autoIncrement?: number;
|
|
13
|
-
/**
|
|
14
|
-
* The character set of the text column
|
|
15
|
-
*/
|
|
16
|
-
characterSet?: string;
|
|
17
|
-
/**
|
|
18
|
-
* the collation of the text column
|
|
19
|
-
*/
|
|
20
|
-
collation?: string;
|
|
21
|
-
/**
|
|
22
|
-
* The table columns
|
|
23
|
-
*/
|
|
24
|
-
columns: DbColumn[];
|
|
25
|
-
/**
|
|
26
|
-
* The table comment
|
|
27
|
-
*/
|
|
28
|
-
comment?: string;
|
|
29
|
-
/**
|
|
30
|
-
* DB Engin
|
|
31
|
-
*/
|
|
32
|
-
engine?: string;
|
|
33
|
-
/**
|
|
34
|
-
* The table foreign keys
|
|
35
|
-
*/
|
|
36
|
-
foreignKeys: DbForeignKey[];
|
|
37
|
-
/**
|
|
38
|
-
* The table indexes
|
|
39
|
-
*/
|
|
40
|
-
indexes: DbIndex[];
|
|
41
|
-
/**
|
|
42
|
-
* The table name
|
|
43
|
-
*/
|
|
44
|
-
name: string;
|
|
45
|
-
/**
|
|
46
|
-
* The table primary key
|
|
47
|
-
*/
|
|
48
|
-
primaryKey?: DbPrimaryKey;
|
|
49
|
-
}
|
|
1
|
+
import { DbColumn } from './dbColumn';
|
|
2
|
+
import { DbForeignKey } from './dbForeignKey';
|
|
3
|
+
import { DbIndex } from './dbIndex';
|
|
4
|
+
import { DbPrimaryKey } from './dbPrimaryKey';
|
|
5
|
+
/**
|
|
6
|
+
* Describe a table
|
|
7
|
+
*/
|
|
8
|
+
export interface DbTable {
|
|
9
|
+
/**
|
|
10
|
+
* auto increment start
|
|
11
|
+
*/
|
|
12
|
+
autoIncrement?: number;
|
|
13
|
+
/**
|
|
14
|
+
* The character set of the text column
|
|
15
|
+
*/
|
|
16
|
+
characterSet?: string;
|
|
17
|
+
/**
|
|
18
|
+
* the collation of the text column
|
|
19
|
+
*/
|
|
20
|
+
collation?: string;
|
|
21
|
+
/**
|
|
22
|
+
* The table columns
|
|
23
|
+
*/
|
|
24
|
+
columns: DbColumn[];
|
|
25
|
+
/**
|
|
26
|
+
* The table comment
|
|
27
|
+
*/
|
|
28
|
+
comment?: string;
|
|
29
|
+
/**
|
|
30
|
+
* DB Engin
|
|
31
|
+
*/
|
|
32
|
+
engine?: string;
|
|
33
|
+
/**
|
|
34
|
+
* The table foreign keys
|
|
35
|
+
*/
|
|
36
|
+
foreignKeys: DbForeignKey[];
|
|
37
|
+
/**
|
|
38
|
+
* The table indexes
|
|
39
|
+
*/
|
|
40
|
+
indexes: DbIndex[];
|
|
41
|
+
/**
|
|
42
|
+
* The table name
|
|
43
|
+
*/
|
|
44
|
+
name: string;
|
|
45
|
+
/**
|
|
46
|
+
* The table primary key
|
|
47
|
+
*/
|
|
48
|
+
primaryKey?: DbPrimaryKey;
|
|
49
|
+
}
|
package/dist/models/dbTable.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=dbTable.js.map
|
|
@@ -1,34 +1,35 @@
|
|
|
1
|
-
import { DbColumn } from './dbColumn';
|
|
2
|
-
import { DbForeignKey } from './dbForeignKey';
|
|
3
|
-
import { DbIndex } from './dbIndex';
|
|
4
|
-
import { DbPrimaryKey } from './dbPrimaryKey';
|
|
5
|
-
/**
|
|
6
|
-
* Describe a table
|
|
7
|
-
*/
|
|
8
|
-
export interface DbTableMarkdown {
|
|
9
|
-
/**
|
|
10
|
-
* The table columns
|
|
11
|
-
*/
|
|
12
|
-
columns: DbColumn[];
|
|
13
|
-
/**
|
|
14
|
-
* The table foreign keys
|
|
15
|
-
*/
|
|
16
|
-
foreignKeys: DbForeignKey[];
|
|
17
|
-
/**
|
|
18
|
-
* The table indexes
|
|
19
|
-
*/
|
|
20
|
-
indexes: DbIndex[];
|
|
21
|
-
/**
|
|
22
|
-
* The table primary key
|
|
23
|
-
*/
|
|
24
|
-
primaryKey?: DbPrimaryKey[];
|
|
25
|
-
/**
|
|
26
|
-
* The table header
|
|
27
|
-
*/
|
|
28
|
-
table: {
|
|
29
|
-
characterSet?: string;
|
|
30
|
-
collation?: string;
|
|
31
|
-
comment?: string;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
1
|
+
import { DbColumn } from './dbColumn';
|
|
2
|
+
import { DbForeignKey } from './dbForeignKey';
|
|
3
|
+
import { DbIndex } from './dbIndex';
|
|
4
|
+
import { DbPrimaryKey } from './dbPrimaryKey';
|
|
5
|
+
/**
|
|
6
|
+
* Describe a table
|
|
7
|
+
*/
|
|
8
|
+
export interface DbTableMarkdown {
|
|
9
|
+
/**
|
|
10
|
+
* The table columns
|
|
11
|
+
*/
|
|
12
|
+
columns: DbColumn[];
|
|
13
|
+
/**
|
|
14
|
+
* The table foreign keys
|
|
15
|
+
*/
|
|
16
|
+
foreignKeys: DbForeignKey[];
|
|
17
|
+
/**
|
|
18
|
+
* The table indexes
|
|
19
|
+
*/
|
|
20
|
+
indexes: DbIndex[];
|
|
21
|
+
/**
|
|
22
|
+
* The table primary key
|
|
23
|
+
*/
|
|
24
|
+
primaryKey?: DbPrimaryKey[];
|
|
25
|
+
/**
|
|
26
|
+
* The table header
|
|
27
|
+
*/
|
|
28
|
+
table: {
|
|
29
|
+
characterSet?: string;
|
|
30
|
+
collation?: string;
|
|
31
|
+
comment?: string;
|
|
32
|
+
engine?: string;
|
|
33
|
+
name: string;
|
|
34
|
+
}[];
|
|
35
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=dbTableMarkdown.js.map
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
drop procedure if exists procAppUpgradeDB;
|
|
2
|
+
drop function if exists funcAppTableExists;
|
|
3
|
+
drop function if exists funcAppColumnExists;
|
|
4
|
+
drop function if exists funcAppPrimaryKeyExists;
|
|
5
|
+
drop function if exists funcAppIndexExists;
|
|
6
|
+
drop function if exists funcAppForeignKeyExists;
|
|
7
|
+
|
|
8
|
+
DELIMITER $$
|
|
9
|
+
|
|
10
|
+
create function funcAppTableExists(p_table text)
|
|
11
|
+
returns int
|
|
12
|
+
begin
|
|
13
|
+
declare v_count int;
|
|
14
|
+
|
|
15
|
+
select
|
|
16
|
+
count(*) into v_count
|
|
17
|
+
from
|
|
18
|
+
information_schema.tables t
|
|
19
|
+
where
|
|
20
|
+
t.table_name = p_table
|
|
21
|
+
and t.table_schema = database();
|
|
22
|
+
|
|
23
|
+
return v_count;
|
|
24
|
+
end;
|
|
25
|
+
$$
|
|
26
|
+
|
|
27
|
+
create function funcAppColumnExists(p_table text, p_column text)
|
|
28
|
+
returns int
|
|
29
|
+
begin
|
|
30
|
+
declare v_count int;
|
|
31
|
+
|
|
32
|
+
select
|
|
33
|
+
count(*) into v_count
|
|
34
|
+
from
|
|
35
|
+
information_schema.columns c
|
|
36
|
+
where
|
|
37
|
+
c.table_schema = database()
|
|
38
|
+
and c.table_name = p_table
|
|
39
|
+
and c.column_name = p_column;
|
|
40
|
+
|
|
41
|
+
return v_count;
|
|
42
|
+
end;
|
|
43
|
+
$$
|
|
44
|
+
|
|
45
|
+
create function funcAppPrimaryKeyExists(p_table text, p_columns text)
|
|
46
|
+
returns int
|
|
47
|
+
begin
|
|
48
|
+
declare v_count int;
|
|
49
|
+
|
|
50
|
+
select
|
|
51
|
+
count(*) into v_count
|
|
52
|
+
from
|
|
53
|
+
(
|
|
54
|
+
select
|
|
55
|
+
s.table_name,
|
|
56
|
+
s.index_name,
|
|
57
|
+
group_concat(s.column_name) columns
|
|
58
|
+
from
|
|
59
|
+
information_schema.statistics s
|
|
60
|
+
join information_schema.table_constraints tc
|
|
61
|
+
on
|
|
62
|
+
s.table_schema = tc.table_schema
|
|
63
|
+
and s.table_name = tc.table_name
|
|
64
|
+
and s.index_name = tc.constraint_name
|
|
65
|
+
where
|
|
66
|
+
s.table_schema = database()
|
|
67
|
+
and s.table_name = p_table
|
|
68
|
+
and tc.constraint_type = 'PRIMARY KEY'
|
|
69
|
+
group by s.table_name, s.index_name
|
|
70
|
+
) a
|
|
71
|
+
where
|
|
72
|
+
a.columns = p_columns;
|
|
73
|
+
|
|
74
|
+
return v_count;
|
|
75
|
+
end;
|
|
76
|
+
$$
|
|
77
|
+
|
|
78
|
+
create function funcAppIndexExists(p_table text, p_columns text)
|
|
79
|
+
returns int
|
|
80
|
+
begin
|
|
81
|
+
declare v_count int;
|
|
82
|
+
|
|
83
|
+
select
|
|
84
|
+
count(*) into v_count
|
|
85
|
+
from
|
|
86
|
+
(
|
|
87
|
+
select
|
|
88
|
+
s.table_name,
|
|
89
|
+
s.index_name,
|
|
90
|
+
group_concat(s.column_name) columns
|
|
91
|
+
from
|
|
92
|
+
information_schema.statistics s
|
|
93
|
+
left join information_schema.table_constraints tc
|
|
94
|
+
on
|
|
95
|
+
s.table_schema = tc.table_schema
|
|
96
|
+
and s.table_name = tc.table_name
|
|
97
|
+
and s.index_name = tc.constraint_name
|
|
98
|
+
where
|
|
99
|
+
s.table_schema = database()
|
|
100
|
+
and s.table_name = p_table
|
|
101
|
+
and tc.constraint_type is null
|
|
102
|
+
group by
|
|
103
|
+
s.table_name, s.index_name
|
|
104
|
+
) a
|
|
105
|
+
where
|
|
106
|
+
a.columns = p_columns;
|
|
107
|
+
|
|
108
|
+
return v_count;
|
|
109
|
+
end;
|
|
110
|
+
$$
|
|
111
|
+
|
|
112
|
+
create function funcAppForeignKeyExists(p_table text, p_columns text, p_reftable text, p_refcolumns text)
|
|
113
|
+
returns int
|
|
114
|
+
begin
|
|
115
|
+
declare v_count int;
|
|
116
|
+
|
|
117
|
+
select
|
|
118
|
+
count(*) into v_count
|
|
119
|
+
from
|
|
120
|
+
(
|
|
121
|
+
select
|
|
122
|
+
k.table_name ,
|
|
123
|
+
k.referenced_table_name ,
|
|
124
|
+
group_concat(k.column_name) columns,
|
|
125
|
+
group_concat(k.referenced_column_name) referenced_columns
|
|
126
|
+
from
|
|
127
|
+
information_schema.referential_constraints r
|
|
128
|
+
join information_schema.key_column_usage k
|
|
129
|
+
on
|
|
130
|
+
r.constraint_schema = k.constraint_schema
|
|
131
|
+
and r.table_name = k.table_name
|
|
132
|
+
and r.constraint_name = k.constraint_name
|
|
133
|
+
where
|
|
134
|
+
k.constraint_schema = database()
|
|
135
|
+
and k.table_name = p_table
|
|
136
|
+
and k.referenced_table_name = p_reftable
|
|
137
|
+
) a
|
|
138
|
+
where
|
|
139
|
+
a.columns = p_columns
|
|
140
|
+
and a.referenced_columns = p_refcolumns;
|
|
141
|
+
|
|
142
|
+
return v_count;
|
|
143
|
+
end;
|
|
144
|
+
$$
|
|
145
|
+
|
|
146
|
+
create procedure procAppUpgradeDB()
|
|
147
|
+
begin
|
|
148
|
+
drop table if exists `temp_app_upgrade_log`;
|
|
149
|
+
create temporary table `temp_app_upgrade_log` (
|
|
150
|
+
`timestamp` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
|
|
151
|
+
`message` varchar(2048)
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
-- $body
|
|
155
|
+
|
|
156
|
+
select * from `temp_app_upgrade_log`;
|
|
157
|
+
drop table `temp_app_upgrade_log`;
|
|
158
|
+
end;
|
|
159
|
+
$$
|
|
160
|
+
|
|
161
|
+
DELIMITER ;
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
call procAppUpgradeDB();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{% if table.foreignKeys.length > 0 %}
|
|
2
|
+
-- Foreign keys for table '{{ table.name }}'
|
|
3
|
+
{% for foreignKey in table.foreignKeys %}
|
|
4
|
+
ALTER TABLE `{{ table.name }}`
|
|
5
|
+
ADD CONSTRAINT {{ foreignKey.name }}
|
|
6
|
+
FOREIGN KEY ({{ foreignKey.columns.replace(r/,\s*/g, ', ') }})
|
|
7
|
+
REFERENCES {{ foreignKey.refTable }}({{ foreignKey.refColumns.replace(r/\s*/g, '').replaceAll(',', ', ') }}){{ " " + foreignKey.options if foreignKey.options }};
|
|
8
|
+
{% endfor %}
|
|
9
|
+
|
|
10
|
+
{% endif %}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
-- Create table '{{ table.name }}'
|
|
2
|
+
CREATE TABLE{{ " IF NOT EXISTS" if ifNotExists }} `{{ table.name }}` (
|
|
3
|
+
{% for column in table.columns %}
|
|
4
|
+
{{ " " if loop.index == 1 else ", " }}`{{ column.name }}` {{ column.type }}{{ " NOT NULL" if not column.nullable }}{{ " DEFAULT " + column.default if column.default }}{{ " COMMENT " + (column | getComment | toSQL) if withComment and (column | getComment) }}
|
|
5
|
+
{% endfor %}
|
|
6
|
+
{% if table.primaryKey %}
|
|
7
|
+
, PRIMARY KEY ({{ table.primaryKey.columns }})
|
|
8
|
+
{% endif %}
|
|
9
|
+
{% for index in table.indexes %}
|
|
10
|
+
, {{ "UNIQUE " if index.unique }}KEY `{{ index.name }}` ({{ index.columns }})
|
|
11
|
+
{% endfor %}
|
|
12
|
+
){{ " ENGINE=" + table.engine if table.engine }}{{ " AUTO_INCREMENT=" + table.autoIncrement if table.autoIncrement and table.autoIncrement !== 1 }}{{ " DEFAULT CHARSET=" + table.characterSet if table.characterSet }}{{ " COMMENT=" + (table.comment | toSQL) if withComment and table.comment }};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
-- Create table '{{ table.name }}'
|
|
2
|
+
if funcAppTableExists('{{ table.name }}') = 0 then
|
|
3
|
+
insert into temp_app_upgrade_log(message) values ('create table: {{ table.name }}');
|
|
4
|
+
CREATE TABLE `{{ table.name }}` (
|
|
5
|
+
{% for column in table.columns %}
|
|
6
|
+
{{ " " if loop.index == 1 else ", " }}`{{ column.name }}` {{ column.type }}{{ " NOT NULL" if not column.nullable }}{{ " DEFAULT " + column.default if column.default }}{{ " COMMENT " + (column | getComment | toSQL) if withComment and (column | getComment) }}
|
|
7
|
+
{% endfor %}
|
|
8
|
+
{% if table.primaryKey %}
|
|
9
|
+
, PRIMARY KEY ({{ table.primaryKey.columns }})
|
|
10
|
+
{% endif %}
|
|
11
|
+
{% for index in table.indexes %}
|
|
12
|
+
, {{ "UNIQUE " if index.unique }}KEY `{{ index.name }}` ({{ index.columns }})
|
|
13
|
+
{% endfor %}
|
|
14
|
+
){{ " ENGINE=" + table.engine if table.engine }}{{ " AUTO_INCREMENT=" + table.autoIncrement if table.autoIncrement and table.autoIncrement !== 1 }}{{ " DEFAULT CHARSET=" + table.characterSet if table.characterSet }}{{ " COMMENT=" + (table.comment | toSQL) if withComment and table.comment }};
|
|
15
|
+
end if;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{% if table.foreignKeys.length > 0 -%}
|
|
2
|
+
{# new foreignKeys #}
|
|
3
|
+
-- Update table foreign keys '{{ table.name }}'
|
|
4
|
+
{% for foreignKey in table.foreignKeys %}
|
|
5
|
+
if funcAppForeignKeyExists('{{ table.name }}', '{{ foreignKey.columns }}', '{{ foreignKey.refTable }}', '{{ foreignKey.refColumns }}') = 0 then
|
|
6
|
+
insert into temp_app_upgrade_log(message) values ('create table foreingn key: {{ table.name }}:{{ foreignKey.columns }}');
|
|
7
|
+
ALTER TABLE {{ table.name }} ADD CONSTRAINT `{{ foreignKey.name }}` FOREIGN KEY ({{ foreignKey.columns }}) REFERENCES {{ foreignKey.refTable }}({{ foreignKey.refColumns }});
|
|
8
|
+
end if;
|
|
9
|
+
{% endfor %}
|
|
10
|
+
{%- endif -%}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
-- Update table '{{ table.name }}'
|
|
3
|
+
{# new columns -#}
|
|
4
|
+
{% for column in table.newColumns %}
|
|
5
|
+
if funcAppColumnExists('{{ table.name }}', '{{ column.name }}') = 0 then
|
|
6
|
+
insert into temp_app_upgrade_log(message) values ('create table column: {{ table.name }}.{{ column.name }}');
|
|
7
|
+
ALTER TABLE {{ table.name }} ADD `{{ column.name }}` {{ column.type }}{{ " NOT NULL" if not column.nullable }}{{ " DEFAULT " + column.default if column.default }}{{ " COMMENT " + (column | getComment | toSQL) if withComment and (column | getComment) }}
|
|
8
|
+
{%- if column.afterColumn -%}
|
|
9
|
+
{{ " AFTER " + "`" + column.afterColumn + "`" }}
|
|
10
|
+
{%- else -%};
|
|
11
|
+
{{ " FIRST" }}
|
|
12
|
+
{%- endif %};
|
|
13
|
+
end if;
|
|
14
|
+
{% endfor -%}
|
|
15
|
+
{# new primary keys -#}
|
|
16
|
+
{% if table.newPrimaryKeys %}
|
|
17
|
+
if funcAppPrimaryKeyExists('{{ table.name }}', '{{ table.newPrimaryKeys.columns }}') = 0 then
|
|
18
|
+
insert into temp_app_upgrade_log(message) values ('create table primary key: {{ table.name }}:{{ table.newPrimaryKeys.columns }}');
|
|
19
|
+
ALTER TABLE {{ table.name }} ADD CONSTRAINT PRIMARY KEY ({{ table.newPrimaryKeys.columns }});
|
|
20
|
+
end if;
|
|
21
|
+
{% endif %}
|
|
22
|
+
{# new indexes -#}
|
|
23
|
+
{% for index in table.newIndexes %}
|
|
24
|
+
{{ ("index: " + index.columns) | log }}
|
|
25
|
+
{%- if index.unique %}
|
|
26
|
+
if funcAppIndexExists('{{ table.name }}', '{{ index.columns }}') = 0 then
|
|
27
|
+
insert into temp_app_upgrade_log(message) values ('create table index: {{ table.name }}:{{ index.columns }}');
|
|
28
|
+
CREATE UNIQUE INDEX `{{ index.name }}` USING BTREE ON {{ table.name }} ({{ index.columns }});
|
|
29
|
+
end if;
|
|
30
|
+
{% elif index.type === "FULLTEXT" %}
|
|
31
|
+
if funcAppIndexExists('{{ table.name }}', '{{ index.columns }}') = 0 then
|
|
32
|
+
insert into temp_app_upgrade_log(message) values ('create table index: {{ table.name }}:{{ index.columns }}');
|
|
33
|
+
CREATE FULLTEXT INDEX `{{ index.name }}` USING BTREE ON {{ table.name }} ({{ index.columns }});
|
|
34
|
+
end if;
|
|
35
|
+
{% else %}
|
|
36
|
+
if funcAppIndexExists('{{ table.name }}', '{{ index.columns }}') = 0 then
|
|
37
|
+
insert into temp_app_upgrade_log(message) values ('create table index: {{ table.name }}:{{ index.columns }}');
|
|
38
|
+
CREATE INDEX `{{ index.name }}` USING BTREE ON {{ table.name }} ({{ index.columns }});
|
|
39
|
+
end if;
|
|
40
|
+
{% endif %}
|
|
41
|
+
{% endfor %}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{#- for new tables #}
|
|
2
|
+
{% for table in newTables %}
|
|
3
|
+
{% include "sql-upgrade-new-table.njk" %}
|
|
4
|
+
{% endfor %}
|
|
5
|
+
|
|
6
|
+
{#- for changes in existing tables #}
|
|
7
|
+
{% for table in diffTables %}
|
|
8
|
+
{% include "sql-upgrade-table.njk" %}
|
|
9
|
+
{% endfor %}
|
|
10
|
+
|
|
11
|
+
{#- for new tables.foreignKeys #}
|
|
12
|
+
{% for table in newTables %}
|
|
13
|
+
{% include "sql-upgrade-table-fk.njk" %}
|
|
14
|
+
{% endfor %}
|
|
15
|
+
|
|
16
|
+
{#- for new foreignKeys #}
|
|
17
|
+
{% for table in diffTables %}
|
|
18
|
+
{% include "sql-upgrade-table-fk.njk" %}
|
|
19
|
+
{% endfor %}
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { DatabaseTypes } from '../models/databaseTypes';
|
|
2
|
-
/**
|
|
3
|
-
* Options for database connection
|
|
4
|
-
*/
|
|
5
|
-
export declare class DbOptions {
|
|
6
|
-
/**
|
|
7
|
-
* The database type
|
|
8
|
-
* Default is `mariadb`
|
|
9
|
-
*/
|
|
10
|
-
databaseType: DatabaseTypes;
|
|
11
|
-
/**
|
|
12
|
-
* The database url
|
|
13
|
-
*/
|
|
14
|
-
databaseUrl?: string;
|
|
15
|
-
/**
|
|
16
|
-
* the user name to access database
|
|
17
|
-
*/
|
|
18
|
-
user?: string;
|
|
19
|
-
/**
|
|
20
|
-
* The user password
|
|
21
|
-
*/
|
|
22
|
-
password?: string;
|
|
23
|
-
/**
|
|
24
|
-
* The database port
|
|
25
|
-
*/
|
|
26
|
-
port?: number;
|
|
27
|
-
/**
|
|
28
|
-
* The database host
|
|
29
|
-
*/
|
|
30
|
-
host?: string;
|
|
31
|
-
/**
|
|
32
|
-
* The database name
|
|
33
|
-
*/
|
|
34
|
-
database?: string;
|
|
35
|
-
}
|
|
1
|
+
import { DatabaseTypes } from '../models/databaseTypes';
|
|
2
|
+
/**
|
|
3
|
+
* Options for database connection
|
|
4
|
+
*/
|
|
5
|
+
export declare class DbOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The database type
|
|
8
|
+
* Default is `mariadb`
|
|
9
|
+
*/
|
|
10
|
+
databaseType: DatabaseTypes;
|
|
11
|
+
/**
|
|
12
|
+
* The database url
|
|
13
|
+
*/
|
|
14
|
+
databaseUrl?: string;
|
|
15
|
+
/**
|
|
16
|
+
* the user name to access database
|
|
17
|
+
*/
|
|
18
|
+
user?: string;
|
|
19
|
+
/**
|
|
20
|
+
* The user password
|
|
21
|
+
*/
|
|
22
|
+
password?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The database port
|
|
25
|
+
*/
|
|
26
|
+
port?: number;
|
|
27
|
+
/**
|
|
28
|
+
* The database host
|
|
29
|
+
*/
|
|
30
|
+
host?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The database name
|
|
33
|
+
*/
|
|
34
|
+
database?: string;
|
|
35
|
+
}
|