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.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Relations } from 'drizzle-orm
|
|
1
|
+
import { Relations } from 'drizzle-orm';
|
|
2
2
|
import type { MySqlColumn, MySqlSchema } from 'drizzle-orm/mysql-core';
|
|
3
3
|
import { MySqlDatabase, MySqlTable } from 'drizzle-orm/mysql-core';
|
|
4
4
|
import type { PgColumn, PgSchema } from 'drizzle-orm/pg-core';
|
|
@@ -9,9 +9,9 @@ import { generatorsFuncs, generatorsFuncsV2 } from './services/GeneratorFuncs.js
|
|
|
9
9
|
import type { AbstractGenerator } from './services/Generators.js';
|
|
10
10
|
import type { DrizzleStudioObjectType, DrizzleStudioRelationType } from './types/drizzleStudio.js';
|
|
11
11
|
import type { RefinementsType } from './types/seedService.js';
|
|
12
|
-
type InferCallbackType<DB extends PgDatabase<any, any
|
|
12
|
+
type InferCallbackType<DB extends PgDatabase<any, any> | MySqlDatabase<any, any> | BaseSQLiteDatabase<any, any>, SCHEMA extends {
|
|
13
13
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations;
|
|
14
|
-
}> = DB extends PgDatabase<any, any
|
|
14
|
+
}> = DB extends PgDatabase<any, any> ? SCHEMA extends {
|
|
15
15
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations;
|
|
16
16
|
} ? {
|
|
17
17
|
[table in keyof SCHEMA as SCHEMA[table] extends PgTable ? table : never]?: {
|
|
@@ -26,7 +26,7 @@ type InferCallbackType<DB extends PgDatabase<any, any, any, any, any> | MySqlDat
|
|
|
26
26
|
}[];
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
|
-
} : {} : DB extends MySqlDatabase<any, any
|
|
29
|
+
} : {} : DB extends MySqlDatabase<any, any> ? SCHEMA extends {
|
|
30
30
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations;
|
|
31
31
|
} ? {
|
|
32
32
|
[table in keyof SCHEMA as SCHEMA[table] extends MySqlTable ? table : never]?: {
|
|
@@ -41,7 +41,7 @@ type InferCallbackType<DB extends PgDatabase<any, any, any, any, any> | MySqlDat
|
|
|
41
41
|
}[];
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
|
-
} : {} : DB extends BaseSQLiteDatabase<any, any
|
|
44
|
+
} : {} : DB extends BaseSQLiteDatabase<any, any> ? SCHEMA extends {
|
|
45
45
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations;
|
|
46
46
|
} ? {
|
|
47
47
|
[table in keyof SCHEMA as SCHEMA[table] extends SQLiteTable ? table : never]?: {
|
|
@@ -57,7 +57,7 @@ type InferCallbackType<DB extends PgDatabase<any, any, any, any, any> | MySqlDat
|
|
|
57
57
|
};
|
|
58
58
|
};
|
|
59
59
|
} : {} : {};
|
|
60
|
-
declare class SeedPromise<DB extends PgDatabase<any, any
|
|
60
|
+
declare class SeedPromise<DB extends PgDatabase<any, any> | MySqlDatabase<any, any> | BaseSQLiteDatabase<any, any>, SCHEMA extends {
|
|
61
61
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations;
|
|
62
62
|
}, VERSION extends string | undefined> implements Promise<void> {
|
|
63
63
|
private db;
|
|
@@ -278,7 +278,7 @@ export declare function seedForDrizzleStudio({ sqlDialect, drizzleStudioObject,
|
|
|
278
278
|
*
|
|
279
279
|
* ```
|
|
280
280
|
*/
|
|
281
|
-
export declare function seed<DB extends PgDatabase<any, any
|
|
281
|
+
export declare function seed<DB extends PgDatabase<any, any> | MySqlDatabase<any, any, any, any> | BaseSQLiteDatabase<any, any>, SCHEMA extends {
|
|
282
282
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations | any;
|
|
283
283
|
}, VERSION extends '2' | '1' | undefined>(db: DB, schema: SCHEMA, options?: {
|
|
284
284
|
count?: number;
|
|
@@ -325,7 +325,7 @@ export declare function seed<DB extends PgDatabase<any, any, any, any, any> | My
|
|
|
325
325
|
* await reset(db, schema);
|
|
326
326
|
* ```
|
|
327
327
|
*/
|
|
328
|
-
export declare function reset<DB extends PgDatabase<any, any
|
|
328
|
+
export declare function reset<DB extends PgDatabase<any, any> | MySqlDatabase<any, any, any, any> | BaseSQLiteDatabase<any, any>, SCHEMA extends {
|
|
329
329
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | any;
|
|
330
330
|
}>(db: DB, schema: SCHEMA): Promise<void>;
|
|
331
331
|
export { default as cities } from './datasets/cityNames.js';
|
package/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Relations } from 'drizzle-orm
|
|
1
|
+
import { Relations } from 'drizzle-orm';
|
|
2
2
|
import type { MySqlColumn, MySqlSchema } from 'drizzle-orm/mysql-core';
|
|
3
3
|
import { MySqlDatabase, MySqlTable } from 'drizzle-orm/mysql-core';
|
|
4
4
|
import type { PgColumn, PgSchema } from 'drizzle-orm/pg-core';
|
|
@@ -9,9 +9,9 @@ import { generatorsFuncs, generatorsFuncsV2 } from './services/GeneratorFuncs.js
|
|
|
9
9
|
import type { AbstractGenerator } from './services/Generators.js';
|
|
10
10
|
import type { DrizzleStudioObjectType, DrizzleStudioRelationType } from './types/drizzleStudio.js';
|
|
11
11
|
import type { RefinementsType } from './types/seedService.js';
|
|
12
|
-
type InferCallbackType<DB extends PgDatabase<any, any
|
|
12
|
+
type InferCallbackType<DB extends PgDatabase<any, any> | MySqlDatabase<any, any> | BaseSQLiteDatabase<any, any>, SCHEMA extends {
|
|
13
13
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations;
|
|
14
|
-
}> = DB extends PgDatabase<any, any
|
|
14
|
+
}> = DB extends PgDatabase<any, any> ? SCHEMA extends {
|
|
15
15
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations;
|
|
16
16
|
} ? {
|
|
17
17
|
[table in keyof SCHEMA as SCHEMA[table] extends PgTable ? table : never]?: {
|
|
@@ -26,7 +26,7 @@ type InferCallbackType<DB extends PgDatabase<any, any, any, any, any> | MySqlDat
|
|
|
26
26
|
}[];
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
|
-
} : {} : DB extends MySqlDatabase<any, any
|
|
29
|
+
} : {} : DB extends MySqlDatabase<any, any> ? SCHEMA extends {
|
|
30
30
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations;
|
|
31
31
|
} ? {
|
|
32
32
|
[table in keyof SCHEMA as SCHEMA[table] extends MySqlTable ? table : never]?: {
|
|
@@ -41,7 +41,7 @@ type InferCallbackType<DB extends PgDatabase<any, any, any, any, any> | MySqlDat
|
|
|
41
41
|
}[];
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
|
-
} : {} : DB extends BaseSQLiteDatabase<any, any
|
|
44
|
+
} : {} : DB extends BaseSQLiteDatabase<any, any> ? SCHEMA extends {
|
|
45
45
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations;
|
|
46
46
|
} ? {
|
|
47
47
|
[table in keyof SCHEMA as SCHEMA[table] extends SQLiteTable ? table : never]?: {
|
|
@@ -57,7 +57,7 @@ type InferCallbackType<DB extends PgDatabase<any, any, any, any, any> | MySqlDat
|
|
|
57
57
|
};
|
|
58
58
|
};
|
|
59
59
|
} : {} : {};
|
|
60
|
-
declare class SeedPromise<DB extends PgDatabase<any, any
|
|
60
|
+
declare class SeedPromise<DB extends PgDatabase<any, any> | MySqlDatabase<any, any> | BaseSQLiteDatabase<any, any>, SCHEMA extends {
|
|
61
61
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations;
|
|
62
62
|
}, VERSION extends string | undefined> implements Promise<void> {
|
|
63
63
|
private db;
|
|
@@ -278,7 +278,7 @@ export declare function seedForDrizzleStudio({ sqlDialect, drizzleStudioObject,
|
|
|
278
278
|
*
|
|
279
279
|
* ```
|
|
280
280
|
*/
|
|
281
|
-
export declare function seed<DB extends PgDatabase<any, any
|
|
281
|
+
export declare function seed<DB extends PgDatabase<any, any> | MySqlDatabase<any, any, any, any> | BaseSQLiteDatabase<any, any>, SCHEMA extends {
|
|
282
282
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations | any;
|
|
283
283
|
}, VERSION extends '2' | '1' | undefined>(db: DB, schema: SCHEMA, options?: {
|
|
284
284
|
count?: number;
|
|
@@ -325,7 +325,7 @@ export declare function seed<DB extends PgDatabase<any, any, any, any, any> | My
|
|
|
325
325
|
* await reset(db, schema);
|
|
326
326
|
* ```
|
|
327
327
|
*/
|
|
328
|
-
export declare function reset<DB extends PgDatabase<any, any
|
|
328
|
+
export declare function reset<DB extends PgDatabase<any, any> | MySqlDatabase<any, any, any, any> | BaseSQLiteDatabase<any, any>, SCHEMA extends {
|
|
329
329
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | any;
|
|
330
330
|
}>(db: DB, schema: SCHEMA): Promise<void>;
|
|
331
331
|
export { default as cities } from './datasets/cityNames.js';
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Relations } from 'drizzle-orm
|
|
1
|
+
import { Relations } from 'drizzle-orm';
|
|
2
2
|
import type { MySqlColumn, MySqlSchema } from 'drizzle-orm/mysql-core';
|
|
3
3
|
import { MySqlDatabase, MySqlTable } from 'drizzle-orm/mysql-core';
|
|
4
4
|
import type { PgColumn, PgSchema } from 'drizzle-orm/pg-core';
|
|
@@ -9,9 +9,9 @@ import { generatorsFuncs, generatorsFuncsV2 } from './services/GeneratorFuncs.js
|
|
|
9
9
|
import type { AbstractGenerator } from './services/Generators.js';
|
|
10
10
|
import type { DrizzleStudioObjectType, DrizzleStudioRelationType } from './types/drizzleStudio.js';
|
|
11
11
|
import type { RefinementsType } from './types/seedService.js';
|
|
12
|
-
type InferCallbackType<DB extends PgDatabase<any, any
|
|
12
|
+
type InferCallbackType<DB extends PgDatabase<any, any> | MySqlDatabase<any, any> | BaseSQLiteDatabase<any, any>, SCHEMA extends {
|
|
13
13
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations;
|
|
14
|
-
}> = DB extends PgDatabase<any, any
|
|
14
|
+
}> = DB extends PgDatabase<any, any> ? SCHEMA extends {
|
|
15
15
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations;
|
|
16
16
|
} ? {
|
|
17
17
|
[table in keyof SCHEMA as SCHEMA[table] extends PgTable ? table : never]?: {
|
|
@@ -26,7 +26,7 @@ type InferCallbackType<DB extends PgDatabase<any, any, any, any, any> | MySqlDat
|
|
|
26
26
|
}[];
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
|
-
} : {} : DB extends MySqlDatabase<any, any
|
|
29
|
+
} : {} : DB extends MySqlDatabase<any, any> ? SCHEMA extends {
|
|
30
30
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations;
|
|
31
31
|
} ? {
|
|
32
32
|
[table in keyof SCHEMA as SCHEMA[table] extends MySqlTable ? table : never]?: {
|
|
@@ -41,7 +41,7 @@ type InferCallbackType<DB extends PgDatabase<any, any, any, any, any> | MySqlDat
|
|
|
41
41
|
}[];
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
|
-
} : {} : DB extends BaseSQLiteDatabase<any, any
|
|
44
|
+
} : {} : DB extends BaseSQLiteDatabase<any, any> ? SCHEMA extends {
|
|
45
45
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations;
|
|
46
46
|
} ? {
|
|
47
47
|
[table in keyof SCHEMA as SCHEMA[table] extends SQLiteTable ? table : never]?: {
|
|
@@ -57,7 +57,7 @@ type InferCallbackType<DB extends PgDatabase<any, any, any, any, any> | MySqlDat
|
|
|
57
57
|
};
|
|
58
58
|
};
|
|
59
59
|
} : {} : {};
|
|
60
|
-
declare class SeedPromise<DB extends PgDatabase<any, any
|
|
60
|
+
declare class SeedPromise<DB extends PgDatabase<any, any> | MySqlDatabase<any, any> | BaseSQLiteDatabase<any, any>, SCHEMA extends {
|
|
61
61
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations;
|
|
62
62
|
}, VERSION extends string | undefined> implements Promise<void> {
|
|
63
63
|
private db;
|
|
@@ -278,7 +278,7 @@ export declare function seedForDrizzleStudio({ sqlDialect, drizzleStudioObject,
|
|
|
278
278
|
*
|
|
279
279
|
* ```
|
|
280
280
|
*/
|
|
281
|
-
export declare function seed<DB extends PgDatabase<any, any
|
|
281
|
+
export declare function seed<DB extends PgDatabase<any, any> | MySqlDatabase<any, any, any, any> | BaseSQLiteDatabase<any, any>, SCHEMA extends {
|
|
282
282
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations | any;
|
|
283
283
|
}, VERSION extends '2' | '1' | undefined>(db: DB, schema: SCHEMA, options?: {
|
|
284
284
|
count?: number;
|
|
@@ -325,7 +325,7 @@ export declare function seed<DB extends PgDatabase<any, any, any, any, any> | My
|
|
|
325
325
|
* await reset(db, schema);
|
|
326
326
|
* ```
|
|
327
327
|
*/
|
|
328
|
-
export declare function reset<DB extends PgDatabase<any, any
|
|
328
|
+
export declare function reset<DB extends PgDatabase<any, any> | MySqlDatabase<any, any, any, any> | BaseSQLiteDatabase<any, any>, SCHEMA extends {
|
|
329
329
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | any;
|
|
330
330
|
}>(db: DB, schema: SCHEMA): Promise<void>;
|
|
331
331
|
export { default as cities } from './datasets/cityNames.js';
|
package/index.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { is, entityKind, eq, sql, getTableName } from 'drizzle-orm';
|
|
2
|
-
import { Relations, extractTablesRelationalConfig, createTableRelationsHelpers, One } from 'drizzle-orm/_relations';
|
|
1
|
+
import { is, entityKind, eq, sql, Relations, getTableName, extractTablesRelationalConfig, createTableRelationsHelpers, One } from 'drizzle-orm';
|
|
3
2
|
import { MySqlDatabase, MySqlTable, getTableConfig as getTableConfig$1 } from 'drizzle-orm/mysql-core';
|
|
4
3
|
import { PgDatabase, getTableConfig, PgTable } from 'drizzle-orm/pg-core';
|
|
5
4
|
import { BaseSQLiteDatabase, SQLiteTable, getTableConfig as getTableConfig$2 } from 'drizzle-orm/sqlite-core';
|
|
@@ -134482,7 +134481,7 @@ class SeedService {
|
|
|
134482
134481
|
orderedTablesNames.push(parent);
|
|
134483
134482
|
}
|
|
134484
134483
|
else {
|
|
134485
|
-
leafTablesNames.push(parent);
|
|
134484
|
+
leafTablesNames.push(...tablesInOutRelations[parent].requiredTableNames, parent);
|
|
134486
134485
|
continue;
|
|
134487
134486
|
}
|
|
134488
134487
|
children = [...tablesInOutRelations[parent].dependantTableNames];
|
|
@@ -135213,7 +135212,7 @@ class SeedService {
|
|
|
135213
135212
|
maxParametersNumber = this.mysqlMaxParametersNumber;
|
|
135214
135213
|
}
|
|
135215
135214
|
else {
|
|
135216
|
-
// is(db, BaseSQLiteDatabase<any, any
|
|
135215
|
+
// is(db, BaseSQLiteDatabase<any, any>)
|
|
135217
135216
|
maxParametersNumber = this.sqliteMaxParametersNumber;
|
|
135218
135217
|
}
|
|
135219
135218
|
const maxBatchSize = Math.floor(maxParametersNumber / columnsNumber);
|
|
@@ -135579,39 +135578,47 @@ const getPostgresInfo = (pgSchema, pgTables) => {
|
|
|
135579
135578
|
const schemaConfig = extractTablesRelationalConfig(schema, createTableRelationsHelpers);
|
|
135580
135579
|
const relations = [];
|
|
135581
135580
|
for (const table of Object.values(schemaConfig.tables)) {
|
|
135582
|
-
if (table.relations
|
|
135583
|
-
|
|
135584
|
-
|
|
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
|
-
|
|
135581
|
+
if (table.relations === undefined)
|
|
135582
|
+
continue;
|
|
135583
|
+
for (const drizzleRel of Object.values(table.relations)) {
|
|
135584
|
+
if (!is(drizzleRel, One))
|
|
135585
|
+
continue;
|
|
135586
|
+
const tableConfig = getTableConfig(drizzleRel.sourceTable);
|
|
135587
|
+
const tableDbSchema = tableConfig.schema ?? 'public';
|
|
135588
|
+
const tableDbName = tableConfig.name;
|
|
135589
|
+
const tableTsName = schemaConfig.tableNamesMap[`${tableDbSchema}.${tableDbName}`] ?? tableDbName;
|
|
135590
|
+
const dbToTsColumnNamesMap = getDbToTsColumnNamesMap(drizzleRel.sourceTable);
|
|
135591
|
+
const columns = drizzleRel.config?.fields.map((field) => dbToTsColumnNamesMap[field.name])
|
|
135592
|
+
?? [];
|
|
135593
|
+
const refTableConfig = getTableConfig(drizzleRel.referencedTable);
|
|
135594
|
+
const refTableDbSchema = refTableConfig.schema ?? 'public';
|
|
135595
|
+
const refTableDbName = refTableConfig.name;
|
|
135596
|
+
const refTableTsName = schemaConfig.tableNamesMap[`${refTableDbSchema}.${refTableDbName}`]
|
|
135597
|
+
?? refTableDbName;
|
|
135598
|
+
const dbToTsColumnNamesMapForRefTable = getDbToTsColumnNamesMap(drizzleRel.referencedTable);
|
|
135599
|
+
const refColumns = drizzleRel.config?.references.map((ref) => dbToTsColumnNamesMapForRefTable[ref.name])
|
|
135600
|
+
?? [];
|
|
135601
|
+
if (tableRelations[refTableTsName] === undefined) {
|
|
135602
|
+
tableRelations[refTableTsName] = [];
|
|
135603
|
+
}
|
|
135604
|
+
const relation = {
|
|
135605
|
+
table: tableTsName,
|
|
135606
|
+
columns,
|
|
135607
|
+
refTable: refTableTsName,
|
|
135608
|
+
refColumns,
|
|
135609
|
+
refTableRels: tableRelations[refTableTsName],
|
|
135610
|
+
type: 'one',
|
|
135611
|
+
};
|
|
135612
|
+
// do not add duplicate relation
|
|
135613
|
+
if (tableRelations[tableTsName]?.some((rel) => rel.table === relation.table
|
|
135614
|
+
&& rel.refTable === relation.refTable)) {
|
|
135615
|
+
console.warn(`You are providing a one-to-many relation between the '${relation.refTable}' and '${relation.table}' tables,\n`
|
|
135616
|
+
+ `while the '${relation.table}' table object already has foreign key constraint in the schema referencing '${relation.refTable}' table.\n`
|
|
135617
|
+
+ `In this case, the foreign key constraint will be used.\n`);
|
|
135618
|
+
continue;
|
|
135614
135619
|
}
|
|
135620
|
+
relations.push(relation);
|
|
135621
|
+
tableRelations[tableTsName].push(relation);
|
|
135615
135622
|
}
|
|
135616
135623
|
}
|
|
135617
135624
|
return relations;
|
|
@@ -135821,39 +135828,47 @@ const getMySqlInfo = (mysqlSchema, mysqlTables) => {
|
|
|
135821
135828
|
const schemaConfig = extractTablesRelationalConfig(schema, createTableRelationsHelpers);
|
|
135822
135829
|
const relations = [];
|
|
135823
135830
|
for (const table of Object.values(schemaConfig.tables)) {
|
|
135824
|
-
if (table.relations
|
|
135825
|
-
|
|
135826
|
-
|
|
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
|
-
|
|
135831
|
+
if (table.relations === undefined)
|
|
135832
|
+
continue;
|
|
135833
|
+
for (const drizzleRel of Object.values(table.relations)) {
|
|
135834
|
+
if (!is(drizzleRel, One))
|
|
135835
|
+
continue;
|
|
135836
|
+
const tableConfig = getTableConfig$1(drizzleRel.sourceTable);
|
|
135837
|
+
const tableDbSchema = tableConfig.schema ?? 'public';
|
|
135838
|
+
const tableDbName = tableConfig.name;
|
|
135839
|
+
const tableTsName = schemaConfig.tableNamesMap[`${tableDbSchema}.${tableDbName}`] ?? tableDbName;
|
|
135840
|
+
const dbToTsColumnNamesMap = getDbToTsColumnNamesMap(drizzleRel.sourceTable);
|
|
135841
|
+
const columns = drizzleRel.config?.fields.map((field) => dbToTsColumnNamesMap[field.name])
|
|
135842
|
+
?? [];
|
|
135843
|
+
const refTableConfig = getTableConfig$1(drizzleRel.referencedTable);
|
|
135844
|
+
const refTableDbSchema = refTableConfig.schema ?? 'public';
|
|
135845
|
+
const refTableDbName = refTableConfig.name;
|
|
135846
|
+
const refTableTsName = schemaConfig.tableNamesMap[`${refTableDbSchema}.${refTableDbName}`]
|
|
135847
|
+
?? refTableDbName;
|
|
135848
|
+
const dbToTsColumnNamesMapForRefTable = getDbToTsColumnNamesMap(drizzleRel.referencedTable);
|
|
135849
|
+
const refColumns = drizzleRel.config?.references.map((ref) => dbToTsColumnNamesMapForRefTable[ref.name])
|
|
135850
|
+
?? [];
|
|
135851
|
+
if (tableRelations[refTableTsName] === undefined) {
|
|
135852
|
+
tableRelations[refTableTsName] = [];
|
|
135853
|
+
}
|
|
135854
|
+
const relation = {
|
|
135855
|
+
table: tableTsName,
|
|
135856
|
+
columns,
|
|
135857
|
+
refTable: refTableTsName,
|
|
135858
|
+
refColumns,
|
|
135859
|
+
refTableRels: tableRelations[refTableTsName],
|
|
135860
|
+
type: 'one',
|
|
135861
|
+
};
|
|
135862
|
+
// do not add duplicate relation
|
|
135863
|
+
if (tableRelations[tableTsName]?.some((rel) => rel.table === relation.table
|
|
135864
|
+
&& rel.refTable === relation.refTable)) {
|
|
135865
|
+
console.warn(`You are providing a one-to-many relation between the '${relation.refTable}' and '${relation.table}' tables,\n`
|
|
135866
|
+
+ `while the '${relation.table}' table object already has foreign key constraint in the schema referencing '${relation.refTable}' table.\n`
|
|
135867
|
+
+ `In this case, the foreign key constraint will be used.\n`);
|
|
135868
|
+
continue;
|
|
135856
135869
|
}
|
|
135870
|
+
relations.push(relation);
|
|
135871
|
+
tableRelations[tableTsName].push(relation);
|
|
135857
135872
|
}
|
|
135858
135873
|
}
|
|
135859
135874
|
return relations;
|
|
@@ -135999,38 +136014,46 @@ const getSqliteInfo = (sqliteSchema, sqliteTables) => {
|
|
|
135999
136014
|
const schemaConfig = extractTablesRelationalConfig(schema, createTableRelationsHelpers);
|
|
136000
136015
|
const relations = [];
|
|
136001
136016
|
for (const table of Object.values(schemaConfig.tables)) {
|
|
136002
|
-
if (table.relations
|
|
136003
|
-
|
|
136004
|
-
|
|
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
|
-
|
|
136017
|
+
if (table.relations === undefined)
|
|
136018
|
+
continue;
|
|
136019
|
+
for (const drizzleRel of Object.values(table.relations)) {
|
|
136020
|
+
if (!is(drizzleRel, One))
|
|
136021
|
+
continue;
|
|
136022
|
+
const tableConfig = getTableConfig$2(drizzleRel.sourceTable);
|
|
136023
|
+
const tableDbName = tableConfig.name;
|
|
136024
|
+
// TODO: tableNamesMap: have {public.customer: 'customer'} structure in sqlite
|
|
136025
|
+
const tableTsName = schemaConfig.tableNamesMap[`public.${tableDbName}`] ?? tableDbName;
|
|
136026
|
+
const dbToTsColumnNamesMap = getDbToTsColumnNamesMap(drizzleRel.sourceTable);
|
|
136027
|
+
const columns = drizzleRel.config?.fields.map((field) => dbToTsColumnNamesMap[field.name])
|
|
136028
|
+
?? [];
|
|
136029
|
+
const refTableConfig = getTableConfig$2(drizzleRel.referencedTable);
|
|
136030
|
+
const refTableDbName = refTableConfig.name;
|
|
136031
|
+
const refTableTsName = schemaConfig.tableNamesMap[`public.${refTableDbName}`]
|
|
136032
|
+
?? refTableDbName;
|
|
136033
|
+
const dbToTsColumnNamesMapForRefTable = getDbToTsColumnNamesMap(drizzleRel.referencedTable);
|
|
136034
|
+
const refColumns = drizzleRel.config?.references.map((ref) => dbToTsColumnNamesMapForRefTable[ref.name])
|
|
136035
|
+
?? [];
|
|
136036
|
+
if (tableRelations[refTableTsName] === undefined) {
|
|
136037
|
+
tableRelations[refTableTsName] = [];
|
|
136038
|
+
}
|
|
136039
|
+
const relation = {
|
|
136040
|
+
table: tableTsName,
|
|
136041
|
+
columns,
|
|
136042
|
+
refTable: refTableTsName,
|
|
136043
|
+
refColumns,
|
|
136044
|
+
refTableRels: tableRelations[refTableTsName],
|
|
136045
|
+
type: 'one',
|
|
136046
|
+
};
|
|
136047
|
+
// do not add duplicate relation
|
|
136048
|
+
if (tableRelations[tableTsName]?.some((rel) => rel.table === relation.table
|
|
136049
|
+
&& rel.refTable === relation.refTable)) {
|
|
136050
|
+
console.warn(`You are providing a one-to-many relation between the '${relation.refTable}' and '${relation.table}' tables,\n`
|
|
136051
|
+
+ `while the '${relation.table}' table object already has foreign key constraint in the schema referencing '${relation.refTable}' table.\n`
|
|
136052
|
+
+ `In this case, the foreign key constraint will be used.\n`);
|
|
136053
|
+
continue;
|
|
136033
136054
|
}
|
|
136055
|
+
relations.push(relation);
|
|
136056
|
+
tableRelations[tableTsName].push(relation);
|
|
136034
136057
|
}
|
|
136035
136058
|
}
|
|
136036
136059
|
return relations;
|