drizzle-kit 0.14.8 → 0.15.1
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/index.js +51 -41
- package/package.json +5 -5
- package/readme.md +9 -0
package/index.js
CHANGED
|
@@ -10901,10 +10901,11 @@ var init_pgSerializer = __esm({
|
|
|
10901
10901
|
const result = {};
|
|
10902
10902
|
for (const table4 of tables) {
|
|
10903
10903
|
const tableName = (0, import_table.getTableName)(table4);
|
|
10904
|
+
const { columns, indexes, foreignKeys, checks } = (0, import_utils.getTableConfig)(table4);
|
|
10904
10905
|
const columnsObject = {};
|
|
10905
10906
|
const indexesObject = {};
|
|
10906
10907
|
const foreignKeysObject = {};
|
|
10907
|
-
|
|
10908
|
+
columns.forEach((column5) => {
|
|
10908
10909
|
const notNull = column5.notNull;
|
|
10909
10910
|
const primaryKey = column5.primary;
|
|
10910
10911
|
const sqlTypeLowered = column5.getSQLType().toLowerCase();
|
|
@@ -10940,7 +10941,7 @@ var init_pgSerializer = __esm({
|
|
|
10940
10941
|
}
|
|
10941
10942
|
columnsObject[column5.name] = columnToSet;
|
|
10942
10943
|
});
|
|
10943
|
-
const
|
|
10944
|
+
const fks = foreignKeys.map((fk4) => {
|
|
10944
10945
|
const name = fk4.getName();
|
|
10945
10946
|
const tableFrom = tableName;
|
|
10946
10947
|
const onDelete = fk4.onDelete;
|
|
@@ -10959,18 +10960,18 @@ var init_pgSerializer = __esm({
|
|
|
10959
10960
|
onUpdate
|
|
10960
10961
|
};
|
|
10961
10962
|
});
|
|
10962
|
-
|
|
10963
|
+
fks.forEach((it) => {
|
|
10963
10964
|
foreignKeysObject[it.name] = it;
|
|
10964
10965
|
});
|
|
10965
|
-
|
|
10966
|
+
indexes.forEach((value) => {
|
|
10966
10967
|
var _a;
|
|
10967
|
-
const
|
|
10968
|
+
const columns2 = value.config.columns;
|
|
10968
10969
|
let name = value.config.name;
|
|
10969
10970
|
name = name ? name : indexName(
|
|
10970
10971
|
tableName,
|
|
10971
|
-
|
|
10972
|
+
columns2.map((it) => it.name)
|
|
10972
10973
|
);
|
|
10973
|
-
let indexColumns =
|
|
10974
|
+
let indexColumns = columns2.map((it) => {
|
|
10974
10975
|
if (it instanceof import_sql.SQL) {
|
|
10975
10976
|
return dialect4.sqlToQuery(it).sql;
|
|
10976
10977
|
} else {
|
|
@@ -20570,6 +20571,29 @@ var init_migrate = __esm({
|
|
|
20570
20571
|
}
|
|
20571
20572
|
});
|
|
20572
20573
|
|
|
20574
|
+
// src/@types/utils.ts
|
|
20575
|
+
var init_utils = __esm({
|
|
20576
|
+
"src/@types/utils.ts"() {
|
|
20577
|
+
String.prototype.trimChar = function(char) {
|
|
20578
|
+
let start = 0;
|
|
20579
|
+
let end = this.length;
|
|
20580
|
+
while (start < end && this[start] === char)
|
|
20581
|
+
++start;
|
|
20582
|
+
while (end > start && this[end - 1] === char)
|
|
20583
|
+
--end;
|
|
20584
|
+
return start > 0 || end < this.length ? this.substring(start, end) : this.toString();
|
|
20585
|
+
};
|
|
20586
|
+
String.prototype.squashSpaces = function() {
|
|
20587
|
+
return this.replace(/ +/g, " ").trim();
|
|
20588
|
+
};
|
|
20589
|
+
String.prototype.camelCase = function() {
|
|
20590
|
+
return this.toLowerCase().replace(/([-_ ][a-z0-9])/g, (group) => {
|
|
20591
|
+
return group.toUpperCase().replace("-", "").replace("_", "").replace(" ", "");
|
|
20592
|
+
});
|
|
20593
|
+
};
|
|
20594
|
+
}
|
|
20595
|
+
});
|
|
20596
|
+
|
|
20573
20597
|
// node_modules/.pnpm/postgres-array@2.0.0/node_modules/postgres-array/index.js
|
|
20574
20598
|
var require_postgres_array = __commonJS({
|
|
20575
20599
|
"node_modules/.pnpm/postgres-array@2.0.0/node_modules/postgres-array/index.js"(exports) {
|
|
@@ -25001,29 +25025,6 @@ var require_lib3 = __commonJS({
|
|
|
25001
25025
|
}
|
|
25002
25026
|
});
|
|
25003
25027
|
|
|
25004
|
-
// src/@types/utils.ts
|
|
25005
|
-
var init_utils = __esm({
|
|
25006
|
-
"src/@types/utils.ts"() {
|
|
25007
|
-
String.prototype.trimChar = function(char) {
|
|
25008
|
-
let start = 0;
|
|
25009
|
-
let end = this.length;
|
|
25010
|
-
while (start < end && this[start] === char)
|
|
25011
|
-
++start;
|
|
25012
|
-
while (end > start && this[end - 1] === char)
|
|
25013
|
-
--end;
|
|
25014
|
-
return start > 0 || end < this.length ? this.substring(start, end) : this.toString();
|
|
25015
|
-
};
|
|
25016
|
-
String.prototype.squashSpaces = function() {
|
|
25017
|
-
return this.replace(/ +/g, " ").trim();
|
|
25018
|
-
};
|
|
25019
|
-
String.prototype.camelCase = function() {
|
|
25020
|
-
return this.toLowerCase().replace(/([-_ ][a-z0-9])/g, (group) => {
|
|
25021
|
-
return group.toUpperCase().replace("-", "").replace("_", "").replace(" ", "");
|
|
25022
|
-
});
|
|
25023
|
-
};
|
|
25024
|
-
}
|
|
25025
|
-
});
|
|
25026
|
-
|
|
25027
25028
|
// src/introspect.ts
|
|
25028
25029
|
var pgImportsList, objToStatement, objToStatement2, timeConfig, importsPatch, relations, schemaToTypeScript, isCyclic, isSelf, column4, createTableColumns, createTableIndexes, createTableFKs;
|
|
25029
25030
|
var init_introspect = __esm({
|
|
@@ -25134,7 +25135,7 @@ var init_introspect = __esm({
|
|
|
25134
25135
|
);
|
|
25135
25136
|
statement += "}";
|
|
25136
25137
|
const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
|
|
25137
|
-
return it.columnsFrom.length > 1 || isSelf(it)
|
|
25138
|
+
return it.columnsFrom.length > 1 || isSelf(it);
|
|
25138
25139
|
});
|
|
25139
25140
|
if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0) {
|
|
25140
25141
|
statement += ",\n";
|
|
@@ -25148,7 +25149,12 @@ var init_introspect = __esm({
|
|
|
25148
25149
|
statement += ");";
|
|
25149
25150
|
return statement;
|
|
25150
25151
|
});
|
|
25151
|
-
const uniquePgImports = [
|
|
25152
|
+
const uniquePgImports = [
|
|
25153
|
+
"pgTable",
|
|
25154
|
+
"pgEnum",
|
|
25155
|
+
"AnyPgColumn",
|
|
25156
|
+
...new Set(imports.pg)
|
|
25157
|
+
];
|
|
25152
25158
|
let result = `import { ${uniquePgImports.join(
|
|
25153
25159
|
", "
|
|
25154
25160
|
)} } from "drizzle-orm-pg"
|
|
@@ -25293,7 +25299,7 @@ var init_introspect = __esm({
|
|
|
25293
25299
|
createTableColumns = (columns, fks, enumTypes) => {
|
|
25294
25300
|
let statement = "";
|
|
25295
25301
|
const oneColumnsFKs = Object.values(fks).filter((it) => {
|
|
25296
|
-
return !isSelf(it)
|
|
25302
|
+
return !isSelf(it);
|
|
25297
25303
|
}).filter((it) => it.columnsFrom.length === 1);
|
|
25298
25304
|
const fkByColumnName = oneColumnsFKs.reduce((res, it) => {
|
|
25299
25305
|
const arr = res[it.columnsFrom[0]] || [];
|
|
@@ -25312,11 +25318,12 @@ var init_introspect = __esm({
|
|
|
25312
25318
|
const onDelete = it2.onDelete && it2.onDelete !== "no action" ? it2.onDelete : null;
|
|
25313
25319
|
const onUpdate = it2.onUpdate && it2.onUpdate !== "no action" ? it2.onUpdate : null;
|
|
25314
25320
|
const params = { onDelete, onUpdate };
|
|
25321
|
+
const typeSuffix = isCyclic(it2) ? ": AnyPgColumn" : "";
|
|
25315
25322
|
const paramsStr = objToStatement2(params);
|
|
25316
25323
|
if (paramsStr) {
|
|
25317
|
-
return `.references(() => ${it2.tableTo.camelCase()}.${it2.columnsTo[0].camelCase()}, ${paramsStr} )`;
|
|
25324
|
+
return `.references(()${typeSuffix} => ${it2.tableTo.camelCase()}.${it2.columnsTo[0].camelCase()}, ${paramsStr} )`;
|
|
25318
25325
|
}
|
|
25319
|
-
return `.references(() => ${it2.tableTo.camelCase()}.${it2.columnsTo[0].camelCase()})`;
|
|
25326
|
+
return `.references(()${typeSuffix} => ${it2.tableTo.camelCase()}.${it2.columnsTo[0].camelCase()})`;
|
|
25320
25327
|
}).join("");
|
|
25321
25328
|
statement += fksStatement;
|
|
25322
25329
|
}
|
|
@@ -25344,11 +25351,13 @@ var init_introspect = __esm({
|
|
|
25344
25351
|
createTableFKs = (fks) => {
|
|
25345
25352
|
let statement = "";
|
|
25346
25353
|
fks.forEach((it) => {
|
|
25354
|
+
const isSelf2 = it.tableTo === it.tableFrom;
|
|
25355
|
+
const tableTo = isSelf2 ? "table" : `${it.tableTo.camelCase()}`;
|
|
25347
25356
|
statement += ` ${it.name.camelCase()}: foreignKey({
|
|
25348
25357
|
`;
|
|
25349
25358
|
statement += ` columns: [${it.columnsFrom.map((i) => `table.${i.camelCase()}`).join(", ")}],
|
|
25350
25359
|
`;
|
|
25351
|
-
statement += ` foreignColumns: [${it.columnsTo.map((i) => `${
|
|
25360
|
+
statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${i.camelCase()}`).join(", ")}]
|
|
25352
25361
|
`;
|
|
25353
25362
|
statement += ` })`;
|
|
25354
25363
|
statement += it.onUpdate && it.onUpdate !== "no action" ? `.onUpdate("${it.onUpdate}")` : "";
|
|
@@ -25672,7 +25681,7 @@ init_source();
|
|
|
25672
25681
|
// package.json
|
|
25673
25682
|
var package_default = {
|
|
25674
25683
|
name: "drizzle-kit",
|
|
25675
|
-
version: "0.
|
|
25684
|
+
version: "0.15.1",
|
|
25676
25685
|
repository: "https://github.com/drizzle-team/drizzle-kit-mirror",
|
|
25677
25686
|
author: "Alex Blokh <aleksandrblokh@gmail.com>",
|
|
25678
25687
|
license: "MIT",
|
|
@@ -25725,10 +25734,10 @@ var package_default = {
|
|
|
25725
25734
|
"@typescript-eslint/parser": "^5.46.1",
|
|
25726
25735
|
ava: "^5.1.0",
|
|
25727
25736
|
dockerode: "^3.3.4",
|
|
25728
|
-
"drizzle-orm": "0.15.0-
|
|
25729
|
-
"drizzle-orm-mysql": "0.15.0-
|
|
25730
|
-
"drizzle-orm-pg": "0.15.0-
|
|
25731
|
-
"drizzle-orm-sqlite": "0.15.0-
|
|
25737
|
+
"drizzle-orm": "0.15.0-60954a3",
|
|
25738
|
+
"drizzle-orm-mysql": "0.15.0-60954a3",
|
|
25739
|
+
"drizzle-orm-pg": "0.15.0-60954a3",
|
|
25740
|
+
"drizzle-orm-sqlite": "0.15.0-60954a3",
|
|
25732
25741
|
esbuild: "^0.15.7",
|
|
25733
25742
|
"esbuild-register": "^3.3.3",
|
|
25734
25743
|
eslint: "^8.29.0",
|
|
@@ -25746,6 +25755,7 @@ var package_default = {
|
|
|
25746
25755
|
// src/cli/index.ts
|
|
25747
25756
|
init_migrate();
|
|
25748
25757
|
init_snapshotsDiffer();
|
|
25758
|
+
init_utils();
|
|
25749
25759
|
var printVersions = () => {
|
|
25750
25760
|
console.log(`${source_default.gray(versions())}
|
|
25751
25761
|
`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drizzle-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.1",
|
|
4
4
|
"repository": "https://github.com/drizzle-team/drizzle-kit-mirror",
|
|
5
5
|
"author": "Alex Blokh <aleksandrblokh@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"@typescript-eslint/parser": "^5.46.1",
|
|
36
36
|
"ava": "^5.1.0",
|
|
37
37
|
"dockerode": "^3.3.4",
|
|
38
|
-
"drizzle-orm": "0.15.0-
|
|
39
|
-
"drizzle-orm-mysql": "0.15.0-
|
|
40
|
-
"drizzle-orm-pg": "0.15.0-
|
|
41
|
-
"drizzle-orm-sqlite": "0.15.0-
|
|
38
|
+
"drizzle-orm": "0.15.0-60954a3",
|
|
39
|
+
"drizzle-orm-mysql": "0.15.0-60954a3",
|
|
40
|
+
"drizzle-orm-pg": "0.15.0-60954a3",
|
|
41
|
+
"drizzle-orm-sqlite": "0.15.0-60954a3",
|
|
42
42
|
"esbuild": "^0.15.7",
|
|
43
43
|
"esbuild-register": "^3.3.3",
|
|
44
44
|
"eslint": "^8.29.0",
|
package/readme.md
CHANGED
|
@@ -86,6 +86,15 @@ $ drizzle-kit generate --dialect pg --schema src/schema.ts
|
|
|
86
86
|
$ drizzle-kit generate --dialect .. --schema .. --out ./migration-folder
|
|
87
87
|
## runs generate command and outputs results to ./migration-folder
|
|
88
88
|
```
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
**`$ drizzle-kit introspect:pg`** - generate `schema.ts` file from existing PG database within seconds
|
|
92
|
+
```shell
|
|
93
|
+
drizzle-kit introspect:pg --out=migrations/ --connectionString=postgresql://user:pass@host:port/db_name
|
|
94
|
+
|
|
95
|
+
drizzle-kit introspect:pg --out=migrations/ --host=0.0.0.0 --port=5432 --user=postgres --password=pass --database=db_name --ssl
|
|
96
|
+
```
|
|
97
|
+
|
|
89
98
|
**`$ drizzle-kit up`** - updates stale snapshots
|
|
90
99
|
`--config` [optional defalut=drizzle.config.json] path to an optional config file\
|
|
91
100
|
`--dialect` [optional default=pg] database dialect, one of -> pg, mysql, sqlite\
|