drizzle-seed 0.3.1-b06bbcd → 0.3.1-ffb171d
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.cjs +127 -104
- package/index.cjs.map +1 -1
- package/index.d.cts +8 -8
- package/index.d.mts +8 -8
- package/index.d.ts +8 -8
- package/index.mjs +122 -99
- package/index.mjs.map +1 -1
- package/package.json +1 -1
- package/services/SeedService.d.cts +4 -4
- package/services/SeedService.d.mts +4 -4
- package/services/SeedService.d.ts +4 -4
package/index.cjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var drizzleOrm = require('drizzle-orm');
|
|
4
|
-
var _relations = require('drizzle-orm/_relations');
|
|
5
4
|
var mysqlCore = require('drizzle-orm/mysql-core');
|
|
6
5
|
var pgCore = require('drizzle-orm/pg-core');
|
|
7
6
|
var sqliteCore = require('drizzle-orm/sqlite-core');
|
|
@@ -134484,7 +134483,7 @@ class SeedService {
|
|
|
134484
134483
|
orderedTablesNames.push(parent);
|
|
134485
134484
|
}
|
|
134486
134485
|
else {
|
|
134487
|
-
leafTablesNames.push(parent);
|
|
134486
|
+
leafTablesNames.push(...tablesInOutRelations[parent].requiredTableNames, parent);
|
|
134488
134487
|
continue;
|
|
134489
134488
|
}
|
|
134490
134489
|
children = [...tablesInOutRelations[parent].dependantTableNames];
|
|
@@ -135215,7 +135214,7 @@ class SeedService {
|
|
|
135215
135214
|
maxParametersNumber = this.mysqlMaxParametersNumber;
|
|
135216
135215
|
}
|
|
135217
135216
|
else {
|
|
135218
|
-
// is(db, BaseSQLiteDatabase<any, any
|
|
135217
|
+
// is(db, BaseSQLiteDatabase<any, any>)
|
|
135219
135218
|
maxParametersNumber = this.sqliteMaxParametersNumber;
|
|
135220
135219
|
}
|
|
135221
135220
|
const maxBatchSize = Math.floor(maxParametersNumber / columnsNumber);
|
|
@@ -135540,7 +135539,7 @@ const resetPostgres = async (db, pgTables) => {
|
|
|
135540
135539
|
await db.execute(drizzleOrm.sql.raw(`truncate ${tablesToTruncate.join(',')} cascade;`));
|
|
135541
135540
|
};
|
|
135542
135541
|
const filterPgSchema = (schema) => {
|
|
135543
|
-
const pgSchema = Object.fromEntries(Object.entries(schema).filter((keyValue) => drizzleOrm.is(keyValue[1], pgCore.PgTable) || drizzleOrm.is(keyValue[1],
|
|
135542
|
+
const pgSchema = Object.fromEntries(Object.entries(schema).filter((keyValue) => drizzleOrm.is(keyValue[1], pgCore.PgTable) || drizzleOrm.is(keyValue[1], drizzleOrm.Relations)));
|
|
135544
135543
|
const pgTables = Object.fromEntries(Object.entries(schema).filter((keyValue) => drizzleOrm.is(keyValue[1], pgCore.PgTable)));
|
|
135545
135544
|
return { pgSchema, pgTables };
|
|
135546
135545
|
};
|
|
@@ -135578,42 +135577,50 @@ const getPostgresInfo = (pgSchema, pgTables) => {
|
|
|
135578
135577
|
return dbToTsColumnNamesMap;
|
|
135579
135578
|
};
|
|
135580
135579
|
const transformFromDrizzleRelation = (schema, getDbToTsColumnNamesMap, tableRelations) => {
|
|
135581
|
-
const schemaConfig =
|
|
135580
|
+
const schemaConfig = drizzleOrm.extractTablesRelationalConfig(schema, drizzleOrm.createTableRelationsHelpers);
|
|
135582
135581
|
const relations = [];
|
|
135583
135582
|
for (const table of Object.values(schemaConfig.tables)) {
|
|
135584
|
-
if (table.relations
|
|
135585
|
-
|
|
135586
|
-
|
|
135587
|
-
|
|
135588
|
-
|
|
135589
|
-
|
|
135590
|
-
|
|
135591
|
-
|
|
135592
|
-
|
|
135593
|
-
|
|
135594
|
-
|
|
135595
|
-
|
|
135596
|
-
|
|
135597
|
-
|
|
135598
|
-
|
|
135599
|
-
|
|
135600
|
-
|
|
135601
|
-
|
|
135602
|
-
|
|
135603
|
-
|
|
135604
|
-
|
|
135605
|
-
|
|
135606
|
-
|
|
135607
|
-
|
|
135608
|
-
|
|
135609
|
-
|
|
135610
|
-
|
|
135611
|
-
|
|
135612
|
-
|
|
135613
|
-
|
|
135614
|
-
|
|
135615
|
-
|
|
135583
|
+
if (table.relations === undefined)
|
|
135584
|
+
continue;
|
|
135585
|
+
for (const drizzleRel of Object.values(table.relations)) {
|
|
135586
|
+
if (!drizzleOrm.is(drizzleRel, drizzleOrm.One))
|
|
135587
|
+
continue;
|
|
135588
|
+
const tableConfig = pgCore.getTableConfig(drizzleRel.sourceTable);
|
|
135589
|
+
const tableDbSchema = tableConfig.schema ?? 'public';
|
|
135590
|
+
const tableDbName = tableConfig.name;
|
|
135591
|
+
const tableTsName = schemaConfig.tableNamesMap[`${tableDbSchema}.${tableDbName}`] ?? tableDbName;
|
|
135592
|
+
const dbToTsColumnNamesMap = getDbToTsColumnNamesMap(drizzleRel.sourceTable);
|
|
135593
|
+
const columns = drizzleRel.config?.fields.map((field) => dbToTsColumnNamesMap[field.name])
|
|
135594
|
+
?? [];
|
|
135595
|
+
const refTableConfig = pgCore.getTableConfig(drizzleRel.referencedTable);
|
|
135596
|
+
const refTableDbSchema = refTableConfig.schema ?? 'public';
|
|
135597
|
+
const refTableDbName = refTableConfig.name;
|
|
135598
|
+
const refTableTsName = schemaConfig.tableNamesMap[`${refTableDbSchema}.${refTableDbName}`]
|
|
135599
|
+
?? refTableDbName;
|
|
135600
|
+
const dbToTsColumnNamesMapForRefTable = getDbToTsColumnNamesMap(drizzleRel.referencedTable);
|
|
135601
|
+
const refColumns = drizzleRel.config?.references.map((ref) => dbToTsColumnNamesMapForRefTable[ref.name])
|
|
135602
|
+
?? [];
|
|
135603
|
+
if (tableRelations[refTableTsName] === undefined) {
|
|
135604
|
+
tableRelations[refTableTsName] = [];
|
|
135605
|
+
}
|
|
135606
|
+
const relation = {
|
|
135607
|
+
table: tableTsName,
|
|
135608
|
+
columns,
|
|
135609
|
+
refTable: refTableTsName,
|
|
135610
|
+
refColumns,
|
|
135611
|
+
refTableRels: tableRelations[refTableTsName],
|
|
135612
|
+
type: 'one',
|
|
135613
|
+
};
|
|
135614
|
+
// do not add duplicate relation
|
|
135615
|
+
if (tableRelations[tableTsName]?.some((rel) => rel.table === relation.table
|
|
135616
|
+
&& rel.refTable === relation.refTable)) {
|
|
135617
|
+
console.warn(`You are providing a one-to-many relation between the '${relation.refTable}' and '${relation.table}' tables,\n`
|
|
135618
|
+
+ `while the '${relation.table}' table object already has foreign key constraint in the schema referencing '${relation.refTable}' table.\n`
|
|
135619
|
+
+ `In this case, the foreign key constraint will be used.\n`);
|
|
135620
|
+
continue;
|
|
135616
135621
|
}
|
|
135622
|
+
relations.push(relation);
|
|
135623
|
+
tableRelations[tableTsName].push(relation);
|
|
135617
135624
|
}
|
|
135618
135625
|
}
|
|
135619
135626
|
return relations;
|
|
@@ -135782,7 +135789,7 @@ const resetMySql = async (db, schema) => {
|
|
|
135782
135789
|
await db.execute(drizzleOrm.sql.raw('SET FOREIGN_KEY_CHECKS = 1;'));
|
|
135783
135790
|
};
|
|
135784
135791
|
const filterMysqlTables = (schema) => {
|
|
135785
|
-
const mysqlSchema = Object.fromEntries(Object.entries(schema).filter((keyValue) => drizzleOrm.is(keyValue[1], mysqlCore.MySqlTable) || drizzleOrm.is(keyValue[1],
|
|
135792
|
+
const mysqlSchema = Object.fromEntries(Object.entries(schema).filter((keyValue) => drizzleOrm.is(keyValue[1], mysqlCore.MySqlTable) || drizzleOrm.is(keyValue[1], drizzleOrm.Relations)));
|
|
135786
135793
|
const mysqlTables = Object.fromEntries(Object.entries(schema).filter((keyValue) => drizzleOrm.is(keyValue[1], mysqlCore.MySqlTable)));
|
|
135787
135794
|
return { mysqlSchema, mysqlTables };
|
|
135788
135795
|
};
|
|
@@ -135820,42 +135827,50 @@ const getMySqlInfo = (mysqlSchema, mysqlTables) => {
|
|
|
135820
135827
|
return dbToTsColumnNamesMap;
|
|
135821
135828
|
};
|
|
135822
135829
|
const transformFromDrizzleRelation = (schema, getDbToTsColumnNamesMap, tableRelations) => {
|
|
135823
|
-
const schemaConfig =
|
|
135830
|
+
const schemaConfig = drizzleOrm.extractTablesRelationalConfig(schema, drizzleOrm.createTableRelationsHelpers);
|
|
135824
135831
|
const relations = [];
|
|
135825
135832
|
for (const table of Object.values(schemaConfig.tables)) {
|
|
135826
|
-
if (table.relations
|
|
135827
|
-
|
|
135828
|
-
|
|
135829
|
-
|
|
135830
|
-
|
|
135831
|
-
|
|
135832
|
-
|
|
135833
|
-
|
|
135834
|
-
|
|
135835
|
-
|
|
135836
|
-
|
|
135837
|
-
|
|
135838
|
-
|
|
135839
|
-
|
|
135840
|
-
|
|
135841
|
-
|
|
135842
|
-
|
|
135843
|
-
|
|
135844
|
-
|
|
135845
|
-
|
|
135846
|
-
|
|
135847
|
-
|
|
135848
|
-
|
|
135849
|
-
|
|
135850
|
-
|
|
135851
|
-
|
|
135852
|
-
|
|
135853
|
-
|
|
135854
|
-
|
|
135855
|
-
|
|
135856
|
-
|
|
135857
|
-
|
|
135833
|
+
if (table.relations === undefined)
|
|
135834
|
+
continue;
|
|
135835
|
+
for (const drizzleRel of Object.values(table.relations)) {
|
|
135836
|
+
if (!drizzleOrm.is(drizzleRel, drizzleOrm.One))
|
|
135837
|
+
continue;
|
|
135838
|
+
const tableConfig = mysqlCore.getTableConfig(drizzleRel.sourceTable);
|
|
135839
|
+
const tableDbSchema = tableConfig.schema ?? 'public';
|
|
135840
|
+
const tableDbName = tableConfig.name;
|
|
135841
|
+
const tableTsName = schemaConfig.tableNamesMap[`${tableDbSchema}.${tableDbName}`] ?? tableDbName;
|
|
135842
|
+
const dbToTsColumnNamesMap = getDbToTsColumnNamesMap(drizzleRel.sourceTable);
|
|
135843
|
+
const columns = drizzleRel.config?.fields.map((field) => dbToTsColumnNamesMap[field.name])
|
|
135844
|
+
?? [];
|
|
135845
|
+
const refTableConfig = mysqlCore.getTableConfig(drizzleRel.referencedTable);
|
|
135846
|
+
const refTableDbSchema = refTableConfig.schema ?? 'public';
|
|
135847
|
+
const refTableDbName = refTableConfig.name;
|
|
135848
|
+
const refTableTsName = schemaConfig.tableNamesMap[`${refTableDbSchema}.${refTableDbName}`]
|
|
135849
|
+
?? refTableDbName;
|
|
135850
|
+
const dbToTsColumnNamesMapForRefTable = getDbToTsColumnNamesMap(drizzleRel.referencedTable);
|
|
135851
|
+
const refColumns = drizzleRel.config?.references.map((ref) => dbToTsColumnNamesMapForRefTable[ref.name])
|
|
135852
|
+
?? [];
|
|
135853
|
+
if (tableRelations[refTableTsName] === undefined) {
|
|
135854
|
+
tableRelations[refTableTsName] = [];
|
|
135855
|
+
}
|
|
135856
|
+
const relation = {
|
|
135857
|
+
table: tableTsName,
|
|
135858
|
+
columns,
|
|
135859
|
+
refTable: refTableTsName,
|
|
135860
|
+
refColumns,
|
|
135861
|
+
refTableRels: tableRelations[refTableTsName],
|
|
135862
|
+
type: 'one',
|
|
135863
|
+
};
|
|
135864
|
+
// do not add duplicate relation
|
|
135865
|
+
if (tableRelations[tableTsName]?.some((rel) => rel.table === relation.table
|
|
135866
|
+
&& rel.refTable === relation.refTable)) {
|
|
135867
|
+
console.warn(`You are providing a one-to-many relation between the '${relation.refTable}' and '${relation.table}' tables,\n`
|
|
135868
|
+
+ `while the '${relation.table}' table object already has foreign key constraint in the schema referencing '${relation.refTable}' table.\n`
|
|
135869
|
+
+ `In this case, the foreign key constraint will be used.\n`);
|
|
135870
|
+
continue;
|
|
135858
135871
|
}
|
|
135872
|
+
relations.push(relation);
|
|
135873
|
+
tableRelations[tableTsName].push(relation);
|
|
135859
135874
|
}
|
|
135860
135875
|
}
|
|
135861
135876
|
return relations;
|
|
@@ -135960,7 +135975,7 @@ const resetSqlite = async (db, schema) => {
|
|
|
135960
135975
|
await db.run(drizzleOrm.sql.raw('PRAGMA foreign_keys = ON'));
|
|
135961
135976
|
};
|
|
135962
135977
|
const filterSqliteTables = (schema) => {
|
|
135963
|
-
const sqliteSchema = Object.fromEntries(Object.entries(schema).filter((keyValue) => drizzleOrm.is(keyValue[1], sqliteCore.SQLiteTable) || drizzleOrm.is(keyValue[1],
|
|
135978
|
+
const sqliteSchema = Object.fromEntries(Object.entries(schema).filter((keyValue) => drizzleOrm.is(keyValue[1], sqliteCore.SQLiteTable) || drizzleOrm.is(keyValue[1], drizzleOrm.Relations)));
|
|
135964
135979
|
const sqliteTables = Object.fromEntries(Object.entries(schema).filter((keyValue) => drizzleOrm.is(keyValue[1], sqliteCore.SQLiteTable)));
|
|
135965
135980
|
return { sqliteSchema, sqliteTables };
|
|
135966
135981
|
};
|
|
@@ -135998,41 +136013,49 @@ const getSqliteInfo = (sqliteSchema, sqliteTables) => {
|
|
|
135998
136013
|
return dbToTsColumnNamesMap;
|
|
135999
136014
|
};
|
|
136000
136015
|
const transformFromDrizzleRelation = (schema, getDbToTsColumnNamesMap, tableRelations) => {
|
|
136001
|
-
const schemaConfig =
|
|
136016
|
+
const schemaConfig = drizzleOrm.extractTablesRelationalConfig(schema, drizzleOrm.createTableRelationsHelpers);
|
|
136002
136017
|
const relations = [];
|
|
136003
136018
|
for (const table of Object.values(schemaConfig.tables)) {
|
|
136004
|
-
if (table.relations
|
|
136005
|
-
|
|
136006
|
-
|
|
136007
|
-
|
|
136008
|
-
|
|
136009
|
-
|
|
136010
|
-
|
|
136011
|
-
|
|
136012
|
-
|
|
136013
|
-
|
|
136014
|
-
|
|
136015
|
-
|
|
136016
|
-
|
|
136017
|
-
|
|
136018
|
-
|
|
136019
|
-
|
|
136020
|
-
|
|
136021
|
-
|
|
136022
|
-
|
|
136023
|
-
|
|
136024
|
-
|
|
136025
|
-
|
|
136026
|
-
|
|
136027
|
-
|
|
136028
|
-
|
|
136029
|
-
|
|
136030
|
-
|
|
136031
|
-
|
|
136032
|
-
|
|
136033
|
-
|
|
136034
|
-
|
|
136019
|
+
if (table.relations === undefined)
|
|
136020
|
+
continue;
|
|
136021
|
+
for (const drizzleRel of Object.values(table.relations)) {
|
|
136022
|
+
if (!drizzleOrm.is(drizzleRel, drizzleOrm.One))
|
|
136023
|
+
continue;
|
|
136024
|
+
const tableConfig = sqliteCore.getTableConfig(drizzleRel.sourceTable);
|
|
136025
|
+
const tableDbName = tableConfig.name;
|
|
136026
|
+
// TODO: tableNamesMap: have {public.customer: 'customer'} structure in sqlite
|
|
136027
|
+
const tableTsName = schemaConfig.tableNamesMap[`public.${tableDbName}`] ?? tableDbName;
|
|
136028
|
+
const dbToTsColumnNamesMap = getDbToTsColumnNamesMap(drizzleRel.sourceTable);
|
|
136029
|
+
const columns = drizzleRel.config?.fields.map((field) => dbToTsColumnNamesMap[field.name])
|
|
136030
|
+
?? [];
|
|
136031
|
+
const refTableConfig = sqliteCore.getTableConfig(drizzleRel.referencedTable);
|
|
136032
|
+
const refTableDbName = refTableConfig.name;
|
|
136033
|
+
const refTableTsName = schemaConfig.tableNamesMap[`public.${refTableDbName}`]
|
|
136034
|
+
?? refTableDbName;
|
|
136035
|
+
const dbToTsColumnNamesMapForRefTable = getDbToTsColumnNamesMap(drizzleRel.referencedTable);
|
|
136036
|
+
const refColumns = drizzleRel.config?.references.map((ref) => dbToTsColumnNamesMapForRefTable[ref.name])
|
|
136037
|
+
?? [];
|
|
136038
|
+
if (tableRelations[refTableTsName] === undefined) {
|
|
136039
|
+
tableRelations[refTableTsName] = [];
|
|
136040
|
+
}
|
|
136041
|
+
const relation = {
|
|
136042
|
+
table: tableTsName,
|
|
136043
|
+
columns,
|
|
136044
|
+
refTable: refTableTsName,
|
|
136045
|
+
refColumns,
|
|
136046
|
+
refTableRels: tableRelations[refTableTsName],
|
|
136047
|
+
type: 'one',
|
|
136048
|
+
};
|
|
136049
|
+
// do not add duplicate relation
|
|
136050
|
+
if (tableRelations[tableTsName]?.some((rel) => rel.table === relation.table
|
|
136051
|
+
&& rel.refTable === relation.refTable)) {
|
|
136052
|
+
console.warn(`You are providing a one-to-many relation between the '${relation.refTable}' and '${relation.table}' tables,\n`
|
|
136053
|
+
+ `while the '${relation.table}' table object already has foreign key constraint in the schema referencing '${relation.refTable}' table.\n`
|
|
136054
|
+
+ `In this case, the foreign key constraint will be used.\n`);
|
|
136055
|
+
continue;
|
|
136035
136056
|
}
|
|
136057
|
+
relations.push(relation);
|
|
136058
|
+
tableRelations[tableTsName].push(relation);
|
|
136036
136059
|
}
|
|
136037
136060
|
}
|
|
136038
136061
|
return relations;
|