@payloadcms/drizzle 3.17.1 → 3.18.0-canary.030d28e
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/package.json +3 -3
- package/dist/postgres/createMigration.d.ts +0 -3
- package/dist/postgres/createMigration.d.ts.map +0 -1
- package/dist/postgres/createMigration.js +0 -91
- package/dist/postgres/createMigration.js.map +0 -1
- package/dist/postgres/getMigrationTemplate.d.ts +0 -4
- package/dist/postgres/getMigrationTemplate.d.ts.map +0 -1
- package/dist/postgres/getMigrationTemplate.js +0 -13
- package/dist/postgres/getMigrationTemplate.js.map +0 -1
- package/dist/postgres/schema/build.d.ts +0 -42
- package/dist/postgres/schema/build.d.ts.map +0 -1
- package/dist/postgres/schema/build.js +0 -404
- package/dist/postgres/schema/build.js.map +0 -1
- package/dist/postgres/schema/createIndex.d.ts +0 -11
- package/dist/postgres/schema/createIndex.d.ts.map +0 -1
- package/dist/postgres/schema/createIndex.js +0 -20
- package/dist/postgres/schema/createIndex.js.map +0 -1
- package/dist/postgres/schema/idToUUID.d.ts +0 -3
- package/dist/postgres/schema/idToUUID.d.ts.map +0 -1
- package/dist/postgres/schema/idToUUID.js +0 -11
- package/dist/postgres/schema/idToUUID.js.map +0 -1
- package/dist/postgres/schema/parentIDColumnMap.d.ts +0 -4
- package/dist/postgres/schema/parentIDColumnMap.d.ts.map +0 -1
- package/dist/postgres/schema/parentIDColumnMap.js +0 -9
- package/dist/postgres/schema/parentIDColumnMap.js.map +0 -1
- package/dist/postgres/schema/traverseFields.d.ts +0 -42
- package/dist/postgres/schema/traverseFields.d.ts.map +0 -1
- package/dist/postgres/schema/traverseFields.js +0 -599
- package/dist/postgres/schema/traverseFields.js.map +0 -1
- package/dist/postgres/schema/withDefault.d.ts +0 -4
- package/dist/postgres/schema/withDefault.d.ts.map +0 -1
- package/dist/postgres/schema/withDefault.js +0 -15
- package/dist/postgres/schema/withDefault.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/drizzle",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.18.0-canary.030d28e",
|
|
4
4
|
"description": "A library of shared functions used by different payload database adapters",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
"@types/pg": "8.10.2",
|
|
54
54
|
"@types/to-snake-case": "1.0.0",
|
|
55
55
|
"@payloadcms/eslint-config": "3.9.0",
|
|
56
|
-
"payload": "3.
|
|
56
|
+
"payload": "3.18.0-canary.030d28e"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"payload": "3.
|
|
59
|
+
"payload": "3.18.0-canary.030d28e"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"build": "pnpm build:swc && pnpm build:types",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createMigration.d.ts","sourceRoot":"","sources":["../../src/postgres/createMigration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAc9C,eAAO,MAAM,eAAe,EAAE,eA2G7B,CAAA"}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import { createRequire } from 'module';
|
|
3
|
-
import { getPredefinedMigration, writeMigrationIndex } from 'payload';
|
|
4
|
-
import prompts from 'prompts';
|
|
5
|
-
import { defaultDrizzleSnapshot } from './defaultSnapshot.js';
|
|
6
|
-
import { getMigrationTemplate } from './getMigrationTemplate.js';
|
|
7
|
-
const require = createRequire(import.meta.url);
|
|
8
|
-
export const createMigration = async function createMigration({ dirname, file, forceAcceptWarning, migrationName, payload, skipEmpty }) {
|
|
9
|
-
const dir = payload.db.migrationDir;
|
|
10
|
-
if (!fs.existsSync(dir)) {
|
|
11
|
-
fs.mkdirSync(dir);
|
|
12
|
-
}
|
|
13
|
-
const { generateDrizzleJson, generateMigration, upPgSnapshot } = require('drizzle-kit/api');
|
|
14
|
-
const drizzleJsonAfter = generateDrizzleJson(this.schema);
|
|
15
|
-
const [yyymmdd, hhmmss] = new Date().toISOString().split('T');
|
|
16
|
-
const formattedDate = yyymmdd.replace(/\D/g, '');
|
|
17
|
-
const formattedTime = hhmmss.split('.')[0].replace(/\D/g, '');
|
|
18
|
-
let imports = '';
|
|
19
|
-
let downSQL;
|
|
20
|
-
let upSQL;
|
|
21
|
-
({ downSQL, imports, upSQL } = await getPredefinedMigration({
|
|
22
|
-
dirname,
|
|
23
|
-
file,
|
|
24
|
-
migrationName,
|
|
25
|
-
payload
|
|
26
|
-
}));
|
|
27
|
-
const timestamp = `${formattedDate}_${formattedTime}`;
|
|
28
|
-
const name = migrationName || file?.split('/').slice(2).join('/');
|
|
29
|
-
const fileName = `${timestamp}${name ? `_${name.replace(/\W/g, '_')}` : ''}`;
|
|
30
|
-
const filePath = `${dir}/${fileName}`;
|
|
31
|
-
let drizzleJsonBefore = defaultDrizzleSnapshot;
|
|
32
|
-
if (this.schemaName) {
|
|
33
|
-
drizzleJsonBefore.schemas = {
|
|
34
|
-
[this.schemaName]: this.schemaName
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
if (!upSQL) {
|
|
38
|
-
// Get latest migration snapshot
|
|
39
|
-
const latestSnapshot = fs.readdirSync(dir).filter((file)=>file.endsWith('.json')).sort().reverse()?.[0];
|
|
40
|
-
if (latestSnapshot) {
|
|
41
|
-
drizzleJsonBefore = JSON.parse(fs.readFileSync(`${dir}/${latestSnapshot}`, 'utf8'));
|
|
42
|
-
if (drizzleJsonBefore.version < drizzleJsonAfter.version) {
|
|
43
|
-
drizzleJsonBefore = upPgSnapshot(drizzleJsonBefore);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
const sqlStatementsUp = await generateMigration(drizzleJsonBefore, drizzleJsonAfter);
|
|
47
|
-
const sqlStatementsDown = await generateMigration(drizzleJsonAfter, drizzleJsonBefore);
|
|
48
|
-
const sqlExecute = 'await payload.db.drizzle.execute(sql`';
|
|
49
|
-
if (sqlStatementsUp?.length) {
|
|
50
|
-
upSQL = `${sqlExecute}\n ${sqlStatementsUp?.join('\n')}\`)`;
|
|
51
|
-
}
|
|
52
|
-
if (sqlStatementsDown?.length) {
|
|
53
|
-
downSQL = `${sqlExecute}\n ${sqlStatementsDown?.join('\n')}\`)`;
|
|
54
|
-
}
|
|
55
|
-
if (!upSQL?.length && !downSQL?.length && !forceAcceptWarning) {
|
|
56
|
-
if (skipEmpty) {
|
|
57
|
-
process.exit(0);
|
|
58
|
-
}
|
|
59
|
-
const { confirm: shouldCreateBlankMigration } = await prompts({
|
|
60
|
-
name: 'confirm',
|
|
61
|
-
type: 'confirm',
|
|
62
|
-
initial: false,
|
|
63
|
-
message: 'No schema changes detected. Would you like to create a blank migration file?'
|
|
64
|
-
}, {
|
|
65
|
-
onCancel: ()=>{
|
|
66
|
-
process.exit(0);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
if (!shouldCreateBlankMigration) {
|
|
70
|
-
process.exit(0);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
// write schema
|
|
74
|
-
fs.writeFileSync(`${filePath}.json`, JSON.stringify(drizzleJsonAfter, null, 2));
|
|
75
|
-
}
|
|
76
|
-
// write migration
|
|
77
|
-
fs.writeFileSync(`${filePath}.ts`, getMigrationTemplate({
|
|
78
|
-
downSQL: downSQL || ` // Migration code`,
|
|
79
|
-
imports,
|
|
80
|
-
packageName: payload.db.packageName,
|
|
81
|
-
upSQL: upSQL || ` // Migration code`
|
|
82
|
-
}));
|
|
83
|
-
writeMigrationIndex({
|
|
84
|
-
migrationsDir: payload.db.migrationDir
|
|
85
|
-
});
|
|
86
|
-
payload.logger.info({
|
|
87
|
-
msg: `Migration created at ${filePath}.ts`
|
|
88
|
-
});
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
//# sourceMappingURL=createMigration.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/postgres/createMigration.ts"],"sourcesContent":["import type { CreateMigration } from 'payload'\n\nimport fs from 'fs'\nimport { createRequire } from 'module'\nimport { getPredefinedMigration, writeMigrationIndex } from 'payload'\nimport prompts from 'prompts'\n\nimport type { BasePostgresAdapter } from './types.js'\n\nimport { defaultDrizzleSnapshot } from './defaultSnapshot.js'\nimport { getMigrationTemplate } from './getMigrationTemplate.js'\n\nconst require = createRequire(import.meta.url)\n\nexport const createMigration: CreateMigration = async function createMigration(\n this: BasePostgresAdapter,\n { dirname, file, forceAcceptWarning, migrationName, payload, skipEmpty },\n) {\n const dir = payload.db.migrationDir\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir)\n }\n const { generateDrizzleJson, generateMigration, upPgSnapshot } = require('drizzle-kit/api')\n const drizzleJsonAfter = generateDrizzleJson(this.schema)\n const [yyymmdd, hhmmss] = new Date().toISOString().split('T')\n const formattedDate = yyymmdd.replace(/\\D/g, '')\n const formattedTime = hhmmss.split('.')[0].replace(/\\D/g, '')\n let imports: string = ''\n let downSQL: string\n let upSQL: string\n ;({ downSQL, imports, upSQL } = await getPredefinedMigration({\n dirname,\n file,\n migrationName,\n payload,\n }))\n\n const timestamp = `${formattedDate}_${formattedTime}`\n\n const name = migrationName || file?.split('/').slice(2).join('/')\n const fileName = `${timestamp}${name ? `_${name.replace(/\\W/g, '_')}` : ''}`\n\n const filePath = `${dir}/${fileName}`\n\n let drizzleJsonBefore = defaultDrizzleSnapshot\n\n if (this.schemaName) {\n drizzleJsonBefore.schemas = {\n [this.schemaName]: this.schemaName,\n }\n }\n\n if (!upSQL) {\n // Get latest migration snapshot\n const latestSnapshot = fs\n .readdirSync(dir)\n .filter((file) => file.endsWith('.json'))\n .sort()\n .reverse()?.[0]\n\n if (latestSnapshot) {\n drizzleJsonBefore = JSON.parse(fs.readFileSync(`${dir}/${latestSnapshot}`, 'utf8'))\n\n if (drizzleJsonBefore.version < drizzleJsonAfter.version) {\n drizzleJsonBefore = upPgSnapshot(drizzleJsonBefore)\n }\n }\n\n const sqlStatementsUp = await generateMigration(drizzleJsonBefore, drizzleJsonAfter)\n const sqlStatementsDown = await generateMigration(drizzleJsonAfter, drizzleJsonBefore)\n const sqlExecute = 'await payload.db.drizzle.execute(sql`'\n\n if (sqlStatementsUp?.length) {\n upSQL = `${sqlExecute}\\n ${sqlStatementsUp?.join('\\n')}\\`)`\n }\n if (sqlStatementsDown?.length) {\n downSQL = `${sqlExecute}\\n ${sqlStatementsDown?.join('\\n')}\\`)`\n }\n\n if (!upSQL?.length && !downSQL?.length && !forceAcceptWarning) {\n if (skipEmpty) {\n process.exit(0)\n }\n\n const { confirm: shouldCreateBlankMigration } = await prompts(\n {\n name: 'confirm',\n type: 'confirm',\n initial: false,\n message: 'No schema changes detected. Would you like to create a blank migration file?',\n },\n {\n onCancel: () => {\n process.exit(0)\n },\n },\n )\n\n if (!shouldCreateBlankMigration) {\n process.exit(0)\n }\n }\n\n // write schema\n fs.writeFileSync(`${filePath}.json`, JSON.stringify(drizzleJsonAfter, null, 2))\n }\n\n // write migration\n fs.writeFileSync(\n `${filePath}.ts`,\n getMigrationTemplate({\n downSQL: downSQL || ` // Migration code`,\n imports,\n packageName: payload.db.packageName,\n upSQL: upSQL || ` // Migration code`,\n }),\n )\n\n writeMigrationIndex({ migrationsDir: payload.db.migrationDir })\n\n payload.logger.info({ msg: `Migration created at ${filePath}.ts` })\n}\n"],"names":["fs","createRequire","getPredefinedMigration","writeMigrationIndex","prompts","defaultDrizzleSnapshot","getMigrationTemplate","require","url","createMigration","dirname","file","forceAcceptWarning","migrationName","payload","skipEmpty","dir","db","migrationDir","existsSync","mkdirSync","generateDrizzleJson","generateMigration","upPgSnapshot","drizzleJsonAfter","schema","yyymmdd","hhmmss","Date","toISOString","split","formattedDate","replace","formattedTime","imports","downSQL","upSQL","timestamp","name","slice","join","fileName","filePath","drizzleJsonBefore","schemaName","schemas","latestSnapshot","readdirSync","filter","endsWith","sort","reverse","JSON","parse","readFileSync","version","sqlStatementsUp","sqlStatementsDown","sqlExecute","length","process","exit","confirm","shouldCreateBlankMigration","type","initial","message","onCancel","writeFileSync","stringify","packageName","migrationsDir","logger","info","msg"],"mappings":"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"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { MigrationTemplateArgs } from 'payload';
|
|
2
|
-
export declare const indent: (text: string) => string;
|
|
3
|
-
export declare const getMigrationTemplate: ({ downSQL, imports, packageName, upSQL, }: MigrationTemplateArgs) => string;
|
|
4
|
-
//# sourceMappingURL=getMigrationTemplate.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getMigrationTemplate.d.ts","sourceRoot":"","sources":["../../src/postgres/getMigrationTemplate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEpD,eAAO,MAAM,MAAM,SAAU,MAAM,WAIpB,CAAA;AAEf,eAAO,MAAM,oBAAoB,8CAK9B,qBAAqB,KAAG,MAS1B,CAAA"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export const indent = (text)=>text.split('\n').map((line)=>` ${line}`).join('\n');
|
|
2
|
-
export const getMigrationTemplate = ({ downSQL, imports, packageName, upSQL })=>`import { MigrateUpArgs, MigrateDownArgs, sql } from '${packageName}'
|
|
3
|
-
${imports ? `${imports}\n` : ''}
|
|
4
|
-
export async function up({ payload, req }: MigrateUpArgs): Promise<void> {
|
|
5
|
-
${indent(upSQL)}
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export async function down({ payload, req }: MigrateDownArgs): Promise<void> {
|
|
9
|
-
${indent(downSQL)}
|
|
10
|
-
}
|
|
11
|
-
`;
|
|
12
|
-
|
|
13
|
-
//# sourceMappingURL=getMigrationTemplate.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/postgres/getMigrationTemplate.ts"],"sourcesContent":["import type { MigrationTemplateArgs } from 'payload'\n\nexport const indent = (text: string) =>\n text\n .split('\\n')\n .map((line) => ` ${line}`)\n .join('\\n')\n\nexport const getMigrationTemplate = ({\n downSQL,\n imports,\n packageName,\n upSQL,\n}: MigrationTemplateArgs): string => `import { MigrateUpArgs, MigrateDownArgs, sql } from '${packageName}'\n${imports ? `${imports}\\n` : ''}\nexport async function up({ payload, req }: MigrateUpArgs): Promise<void> {\n${indent(upSQL)}\n}\n\nexport async function down({ payload, req }: MigrateDownArgs): Promise<void> {\n${indent(downSQL)}\n}\n`\n"],"names":["indent","text","split","map","line","join","getMigrationTemplate","downSQL","imports","packageName","upSQL"],"mappings":"AAEA,OAAO,MAAMA,SAAS,CAACC,OACrBA,KACGC,KAAK,CAAC,MACNC,GAAG,CAAC,CAACC,OAAS,CAAC,EAAE,EAAEA,MAAM,EACzBC,IAAI,CAAC,MAAK;AAEf,OAAO,MAAMC,uBAAuB,CAAC,EACnCC,OAAO,EACPC,OAAO,EACPC,WAAW,EACXC,KAAK,EACiB,GAAa,CAAC,qDAAqD,EAAED,YAAY;AACzG,EAAED,UAAU,GAAGA,QAAQ,EAAE,CAAC,GAAG,GAAG;;AAEhC,EAAER,OAAOU,OAAO;;;;AAIhB,EAAEV,OAAOO,SAAS;;AAElB,CAAC,CAAA"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { PgColumnBuilder } from 'drizzle-orm/pg-core';
|
|
2
|
-
import type { FlattenedField } from 'payload';
|
|
3
|
-
import type { BaseExtraConfig, BasePostgresAdapter, RelationMap } from '../types.js';
|
|
4
|
-
type Args = {
|
|
5
|
-
adapter: BasePostgresAdapter;
|
|
6
|
-
baseColumns?: Record<string, PgColumnBuilder>;
|
|
7
|
-
/**
|
|
8
|
-
* After table is created, run these functions to add extra config to the table
|
|
9
|
-
* ie. indexes, multiple columns, etc
|
|
10
|
-
*/
|
|
11
|
-
baseExtraConfig?: BaseExtraConfig;
|
|
12
|
-
buildNumbers?: boolean;
|
|
13
|
-
buildRelationships?: boolean;
|
|
14
|
-
disableNotNull: boolean;
|
|
15
|
-
disableRelsTableUnique?: boolean;
|
|
16
|
-
disableUnique: boolean;
|
|
17
|
-
fields: FlattenedField[];
|
|
18
|
-
rootRelationships?: Set<string>;
|
|
19
|
-
rootRelationsToBuild?: RelationMap;
|
|
20
|
-
rootTableIDColType?: string;
|
|
21
|
-
rootTableName?: string;
|
|
22
|
-
rootUniqueRelationships?: Set<string>;
|
|
23
|
-
tableName: string;
|
|
24
|
-
timestamps?: boolean;
|
|
25
|
-
versions: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Tracks whether or not this table is built
|
|
28
|
-
* from the result of a localized array or block field at some point
|
|
29
|
-
*/
|
|
30
|
-
withinLocalizedArrayOrBlock?: boolean;
|
|
31
|
-
};
|
|
32
|
-
type Result = {
|
|
33
|
-
hasLocalizedManyNumberField: boolean;
|
|
34
|
-
hasLocalizedManyTextField: boolean;
|
|
35
|
-
hasLocalizedRelationshipField: boolean;
|
|
36
|
-
hasManyNumberField: 'index' | boolean;
|
|
37
|
-
hasManyTextField: 'index' | boolean;
|
|
38
|
-
relationsToBuild: RelationMap;
|
|
39
|
-
};
|
|
40
|
-
export declare const buildTable: ({ adapter, baseColumns, baseExtraConfig, disableNotNull, disableRelsTableUnique, disableUnique, fields, rootRelationships, rootRelationsToBuild, rootTableIDColType, rootTableName: incomingRootTableName, rootUniqueRelationships, tableName, timestamps, versions, withinLocalizedArrayOrBlock, }: Args) => Result;
|
|
41
|
-
export {};
|
|
42
|
-
//# sourceMappingURL=build.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/postgres/schema/build.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGV,eAAe,EAEhB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAe7C,OAAO,KAAK,EACV,eAAe,EACf,mBAAmB,EAInB,WAAW,EACZ,MAAM,aAAa,CAAA;AASpB,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,mBAAmB,CAAA;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;IAC7C;;;OAGG;IACH,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,cAAc,EAAE,OAAO,CAAA;IACvB,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC,aAAa,EAAE,OAAO,CAAA;IACtB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,iBAAiB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAC/B,oBAAoB,CAAC,EAAE,WAAW,CAAA;IAClC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,uBAAuB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACrC,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,QAAQ,EAAE,OAAO,CAAA;IACjB;;;OAGG;IACH,2BAA2B,CAAC,EAAE,OAAO,CAAA;CACtC,CAAA;AAED,KAAK,MAAM,GAAG;IACZ,2BAA2B,EAAE,OAAO,CAAA;IACpC,yBAAyB,EAAE,OAAO,CAAA;IAClC,6BAA6B,EAAE,OAAO,CAAA;IACtC,kBAAkB,EAAE,OAAO,GAAG,OAAO,CAAA;IACrC,gBAAgB,EAAE,OAAO,GAAG,OAAO,CAAA;IACnC,gBAAgB,EAAE,WAAW,CAAA;CAC9B,CAAA;AAED,eAAO,MAAM,UAAU,wSAiBpB,IAAI,KAAG,MA4aT,CAAA"}
|
|
@@ -1,404 +0,0 @@
|
|
|
1
|
-
import { relations } from 'drizzle-orm';
|
|
2
|
-
import { foreignKey, index, integer, numeric, serial, timestamp, unique, varchar } from 'drizzle-orm/pg-core';
|
|
3
|
-
import toSnakeCase from 'to-snake-case';
|
|
4
|
-
import { createTableName } from '../../createTableName.js';
|
|
5
|
-
import { buildIndexName } from '../../utilities/buildIndexName.js';
|
|
6
|
-
import { createIndex } from './createIndex.js';
|
|
7
|
-
import { parentIDColumnMap } from './parentIDColumnMap.js';
|
|
8
|
-
import { setColumnID } from './setColumnID.js';
|
|
9
|
-
import { traverseFields } from './traverseFields.js';
|
|
10
|
-
export const buildTable = ({ adapter, baseColumns = {}, baseExtraConfig = {}, disableNotNull, disableRelsTableUnique = false, disableUnique = false, fields, rootRelationships, rootRelationsToBuild, rootTableIDColType, rootTableName: incomingRootTableName, rootUniqueRelationships, tableName, timestamps, versions, withinLocalizedArrayOrBlock })=>{
|
|
11
|
-
const isRoot = !incomingRootTableName;
|
|
12
|
-
const rootTableName = incomingRootTableName || tableName;
|
|
13
|
-
const columns = baseColumns;
|
|
14
|
-
const indexes = {};
|
|
15
|
-
const localesColumns = {};
|
|
16
|
-
const localesIndexes = {};
|
|
17
|
-
let localesTable;
|
|
18
|
-
let textsTable;
|
|
19
|
-
let numbersTable;
|
|
20
|
-
// Relationships to the base collection
|
|
21
|
-
const relationships = rootRelationships || new Set();
|
|
22
|
-
// Unique relationships to the base collection
|
|
23
|
-
const uniqueRelationships = rootUniqueRelationships || new Set();
|
|
24
|
-
let relationshipsTable;
|
|
25
|
-
// Drizzle relations
|
|
26
|
-
const relationsToBuild = new Map();
|
|
27
|
-
const idColType = setColumnID({
|
|
28
|
-
adapter,
|
|
29
|
-
columns,
|
|
30
|
-
fields
|
|
31
|
-
});
|
|
32
|
-
const { hasLocalizedField, hasLocalizedManyNumberField, hasLocalizedManyTextField, hasLocalizedRelationshipField, hasManyNumberField, hasManyTextField } = traverseFields({
|
|
33
|
-
adapter,
|
|
34
|
-
columns,
|
|
35
|
-
disableNotNull,
|
|
36
|
-
disableRelsTableUnique,
|
|
37
|
-
disableUnique,
|
|
38
|
-
fields,
|
|
39
|
-
indexes,
|
|
40
|
-
localesColumns,
|
|
41
|
-
localesIndexes,
|
|
42
|
-
newTableName: tableName,
|
|
43
|
-
parentTableName: tableName,
|
|
44
|
-
relationships,
|
|
45
|
-
relationsToBuild,
|
|
46
|
-
rootRelationsToBuild: rootRelationsToBuild || relationsToBuild,
|
|
47
|
-
rootTableIDColType: rootTableIDColType || idColType,
|
|
48
|
-
rootTableName,
|
|
49
|
-
uniqueRelationships,
|
|
50
|
-
versions,
|
|
51
|
-
withinLocalizedArrayOrBlock
|
|
52
|
-
});
|
|
53
|
-
// split the relationsToBuild by localized and non-localized
|
|
54
|
-
const localizedRelations = new Map();
|
|
55
|
-
const nonLocalizedRelations = new Map();
|
|
56
|
-
relationsToBuild.forEach(({ type, localized, relationName, target }, key)=>{
|
|
57
|
-
const map = localized ? localizedRelations : nonLocalizedRelations;
|
|
58
|
-
map.set(key, {
|
|
59
|
-
type,
|
|
60
|
-
relationName,
|
|
61
|
-
target
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
if (timestamps) {
|
|
65
|
-
columns.createdAt = timestamp('created_at', {
|
|
66
|
-
mode: 'string',
|
|
67
|
-
precision: 3,
|
|
68
|
-
withTimezone: true
|
|
69
|
-
}).defaultNow().notNull();
|
|
70
|
-
columns.updatedAt = timestamp('updated_at', {
|
|
71
|
-
mode: 'string',
|
|
72
|
-
precision: 3,
|
|
73
|
-
withTimezone: true
|
|
74
|
-
}).defaultNow().notNull();
|
|
75
|
-
}
|
|
76
|
-
const table = adapter.pgSchema.table(tableName, columns, (cols)=>{
|
|
77
|
-
const extraConfig = Object.entries(baseExtraConfig).reduce((config, [key, func])=>{
|
|
78
|
-
config[key] = func(cols);
|
|
79
|
-
return config;
|
|
80
|
-
}, {});
|
|
81
|
-
const result = Object.entries(indexes).reduce((acc, [colName, func])=>{
|
|
82
|
-
acc[colName] = func(cols);
|
|
83
|
-
return acc;
|
|
84
|
-
}, extraConfig);
|
|
85
|
-
return result;
|
|
86
|
-
});
|
|
87
|
-
adapter.tables[tableName] = table;
|
|
88
|
-
if (hasLocalizedField || localizedRelations.size) {
|
|
89
|
-
const localeTableName = `${tableName}${adapter.localesSuffix}`;
|
|
90
|
-
localesColumns.id = serial('id').primaryKey();
|
|
91
|
-
localesColumns._locale = adapter.enums.enum__locales('_locale').notNull();
|
|
92
|
-
localesColumns._parentID = parentIDColumnMap[idColType]('_parent_id').notNull();
|
|
93
|
-
localesTable = adapter.pgSchema.table(localeTableName, localesColumns, (cols)=>{
|
|
94
|
-
return Object.entries(localesIndexes).reduce((acc, [colName, func])=>{
|
|
95
|
-
acc[colName] = func(cols);
|
|
96
|
-
return acc;
|
|
97
|
-
}, {
|
|
98
|
-
_localeParent: unique(`${localeTableName}_locale_parent_id_unique`).on(cols._locale, cols._parentID),
|
|
99
|
-
_parentIdFk: foreignKey({
|
|
100
|
-
name: `${localeTableName}_parent_id_fk`,
|
|
101
|
-
columns: [
|
|
102
|
-
cols._parentID
|
|
103
|
-
],
|
|
104
|
-
foreignColumns: [
|
|
105
|
-
table.id
|
|
106
|
-
]
|
|
107
|
-
}).onDelete('cascade')
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
adapter.tables[localeTableName] = localesTable;
|
|
111
|
-
adapter.relations[`relations_${localeTableName}`] = relations(localesTable, ({ many, one })=>{
|
|
112
|
-
const result = {};
|
|
113
|
-
result._parentID = one(table, {
|
|
114
|
-
fields: [
|
|
115
|
-
localesTable._parentID
|
|
116
|
-
],
|
|
117
|
-
references: [
|
|
118
|
-
table.id
|
|
119
|
-
],
|
|
120
|
-
// name the relationship by what the many() relationName is
|
|
121
|
-
relationName: '_locales'
|
|
122
|
-
});
|
|
123
|
-
localizedRelations.forEach(({ type, target }, key)=>{
|
|
124
|
-
if (type === 'one') {
|
|
125
|
-
result[key] = one(adapter.tables[target], {
|
|
126
|
-
fields: [
|
|
127
|
-
localesTable[key]
|
|
128
|
-
],
|
|
129
|
-
references: [
|
|
130
|
-
adapter.tables[target].id
|
|
131
|
-
],
|
|
132
|
-
relationName: key
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
if (type === 'many') {
|
|
136
|
-
result[key] = many(adapter.tables[target], {
|
|
137
|
-
relationName: key
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
return result;
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
if (isRoot) {
|
|
145
|
-
if (hasManyTextField) {
|
|
146
|
-
const textsTableName = `${rootTableName}_texts`;
|
|
147
|
-
const columns = {
|
|
148
|
-
id: serial('id').primaryKey(),
|
|
149
|
-
order: integer('order').notNull(),
|
|
150
|
-
parent: parentIDColumnMap[idColType]('parent_id').notNull(),
|
|
151
|
-
path: varchar('path').notNull(),
|
|
152
|
-
text: varchar('text')
|
|
153
|
-
};
|
|
154
|
-
if (hasLocalizedManyTextField) {
|
|
155
|
-
columns.locale = adapter.enums.enum__locales('locale');
|
|
156
|
-
}
|
|
157
|
-
textsTable = adapter.pgSchema.table(textsTableName, columns, (cols)=>{
|
|
158
|
-
const config = {
|
|
159
|
-
orderParentIdx: index(`${textsTableName}_order_parent_idx`).on(cols.order, cols.parent),
|
|
160
|
-
parentFk: foreignKey({
|
|
161
|
-
name: `${textsTableName}_parent_fk`,
|
|
162
|
-
columns: [
|
|
163
|
-
cols.parent
|
|
164
|
-
],
|
|
165
|
-
foreignColumns: [
|
|
166
|
-
table.id
|
|
167
|
-
]
|
|
168
|
-
}).onDelete('cascade')
|
|
169
|
-
};
|
|
170
|
-
if (hasManyTextField === 'index') {
|
|
171
|
-
config.text_idx = index(`${textsTableName}_text_idx`).on(cols.text);
|
|
172
|
-
}
|
|
173
|
-
if (hasLocalizedManyTextField) {
|
|
174
|
-
config.localeParent = index(`${textsTableName}_locale_parent`).on(cols.locale, cols.parent);
|
|
175
|
-
}
|
|
176
|
-
return config;
|
|
177
|
-
});
|
|
178
|
-
adapter.tables[textsTableName] = textsTable;
|
|
179
|
-
adapter.relations[`relations_${textsTableName}`] = relations(textsTable, ({ one })=>({
|
|
180
|
-
parent: one(table, {
|
|
181
|
-
fields: [
|
|
182
|
-
textsTable.parent
|
|
183
|
-
],
|
|
184
|
-
references: [
|
|
185
|
-
table.id
|
|
186
|
-
],
|
|
187
|
-
relationName: '_texts'
|
|
188
|
-
})
|
|
189
|
-
}));
|
|
190
|
-
}
|
|
191
|
-
if (hasManyNumberField) {
|
|
192
|
-
const numbersTableName = `${rootTableName}_numbers`;
|
|
193
|
-
const columns = {
|
|
194
|
-
id: serial('id').primaryKey(),
|
|
195
|
-
number: numeric('number'),
|
|
196
|
-
order: integer('order').notNull(),
|
|
197
|
-
parent: parentIDColumnMap[idColType]('parent_id').notNull(),
|
|
198
|
-
path: varchar('path').notNull()
|
|
199
|
-
};
|
|
200
|
-
if (hasLocalizedManyNumberField) {
|
|
201
|
-
columns.locale = adapter.enums.enum__locales('locale');
|
|
202
|
-
}
|
|
203
|
-
numbersTable = adapter.pgSchema.table(numbersTableName, columns, (cols)=>{
|
|
204
|
-
const config = {
|
|
205
|
-
orderParentIdx: index(`${numbersTableName}_order_parent_idx`).on(cols.order, cols.parent),
|
|
206
|
-
parentFk: foreignKey({
|
|
207
|
-
name: `${numbersTableName}_parent_fk`,
|
|
208
|
-
columns: [
|
|
209
|
-
cols.parent
|
|
210
|
-
],
|
|
211
|
-
foreignColumns: [
|
|
212
|
-
table.id
|
|
213
|
-
]
|
|
214
|
-
}).onDelete('cascade')
|
|
215
|
-
};
|
|
216
|
-
if (hasManyNumberField === 'index') {
|
|
217
|
-
config.numberIdx = index(`${numbersTableName}_number_idx`).on(cols.number);
|
|
218
|
-
}
|
|
219
|
-
if (hasLocalizedManyNumberField) {
|
|
220
|
-
config.localeParent = index(`${numbersTableName}_locale_parent`).on(cols.locale, cols.parent);
|
|
221
|
-
}
|
|
222
|
-
return config;
|
|
223
|
-
});
|
|
224
|
-
adapter.tables[numbersTableName] = numbersTable;
|
|
225
|
-
adapter.relations[`relations_${numbersTableName}`] = relations(numbersTable, ({ one })=>({
|
|
226
|
-
parent: one(table, {
|
|
227
|
-
fields: [
|
|
228
|
-
numbersTable.parent
|
|
229
|
-
],
|
|
230
|
-
references: [
|
|
231
|
-
table.id
|
|
232
|
-
],
|
|
233
|
-
relationName: '_numbers'
|
|
234
|
-
})
|
|
235
|
-
}));
|
|
236
|
-
}
|
|
237
|
-
if (relationships.size) {
|
|
238
|
-
const relationshipColumns = {
|
|
239
|
-
id: serial('id').primaryKey(),
|
|
240
|
-
order: integer('order'),
|
|
241
|
-
parent: parentIDColumnMap[idColType]('parent_id').notNull(),
|
|
242
|
-
path: varchar('path').notNull()
|
|
243
|
-
};
|
|
244
|
-
if (hasLocalizedRelationshipField) {
|
|
245
|
-
relationshipColumns.locale = adapter.enums.enum__locales('locale');
|
|
246
|
-
}
|
|
247
|
-
const relationExtraConfig = {};
|
|
248
|
-
const relationshipsTableName = `${tableName}${adapter.relationshipsSuffix}`;
|
|
249
|
-
relationships.forEach((relationTo)=>{
|
|
250
|
-
const relationshipConfig = adapter.payload.collections[relationTo].config;
|
|
251
|
-
const formattedRelationTo = createTableName({
|
|
252
|
-
adapter,
|
|
253
|
-
config: relationshipConfig,
|
|
254
|
-
throwValidationError: true
|
|
255
|
-
});
|
|
256
|
-
let colType = adapter.idType === 'uuid' ? 'uuid' : 'integer';
|
|
257
|
-
const relatedCollectionCustomIDType = adapter.payload.collections[relationshipConfig.slug]?.customIDType;
|
|
258
|
-
if (relatedCollectionCustomIDType === 'number') {
|
|
259
|
-
colType = 'numeric';
|
|
260
|
-
}
|
|
261
|
-
if (relatedCollectionCustomIDType === 'text') {
|
|
262
|
-
colType = 'varchar';
|
|
263
|
-
}
|
|
264
|
-
const colName = `${relationTo}ID`;
|
|
265
|
-
relationshipColumns[colName] = parentIDColumnMap[colType](`${formattedRelationTo}_id`);
|
|
266
|
-
relationExtraConfig[`${relationTo}IdFk`] = (cols)=>foreignKey({
|
|
267
|
-
name: `${relationshipsTableName}_${toSnakeCase(relationTo)}_fk`,
|
|
268
|
-
columns: [
|
|
269
|
-
cols[colName]
|
|
270
|
-
],
|
|
271
|
-
foreignColumns: [
|
|
272
|
-
adapter.tables[formattedRelationTo].id
|
|
273
|
-
]
|
|
274
|
-
}).onDelete('cascade');
|
|
275
|
-
const indexColumns = [
|
|
276
|
-
colName
|
|
277
|
-
];
|
|
278
|
-
const unique = !disableUnique && uniqueRelationships.has(relationTo);
|
|
279
|
-
if (unique) {
|
|
280
|
-
indexColumns.push('path');
|
|
281
|
-
}
|
|
282
|
-
if (hasLocalizedRelationshipField) {
|
|
283
|
-
indexColumns.push('locale');
|
|
284
|
-
}
|
|
285
|
-
const indexName = buildIndexName({
|
|
286
|
-
name: `${relationshipsTableName}_${formattedRelationTo}_id`,
|
|
287
|
-
adapter
|
|
288
|
-
});
|
|
289
|
-
relationExtraConfig[indexName] = createIndex({
|
|
290
|
-
name: indexColumns,
|
|
291
|
-
indexName,
|
|
292
|
-
unique
|
|
293
|
-
});
|
|
294
|
-
});
|
|
295
|
-
relationshipsTable = adapter.pgSchema.table(relationshipsTableName, relationshipColumns, (cols)=>{
|
|
296
|
-
const result = Object.entries(relationExtraConfig).reduce((config, [key, func])=>{
|
|
297
|
-
config[key] = func(cols);
|
|
298
|
-
return config;
|
|
299
|
-
}, {
|
|
300
|
-
order: index(`${relationshipsTableName}_order_idx`).on(cols.order),
|
|
301
|
-
parentFk: foreignKey({
|
|
302
|
-
name: `${relationshipsTableName}_parent_fk`,
|
|
303
|
-
columns: [
|
|
304
|
-
cols.parent
|
|
305
|
-
],
|
|
306
|
-
foreignColumns: [
|
|
307
|
-
table.id
|
|
308
|
-
]
|
|
309
|
-
}).onDelete('cascade'),
|
|
310
|
-
parentIdx: index(`${relationshipsTableName}_parent_idx`).on(cols.parent),
|
|
311
|
-
pathIdx: index(`${relationshipsTableName}_path_idx`).on(cols.path)
|
|
312
|
-
});
|
|
313
|
-
if (hasLocalizedRelationshipField) {
|
|
314
|
-
result.localeIdx = index(`${relationshipsTableName}_locale_idx`).on(cols.locale);
|
|
315
|
-
}
|
|
316
|
-
return result;
|
|
317
|
-
});
|
|
318
|
-
adapter.tables[relationshipsTableName] = relationshipsTable;
|
|
319
|
-
adapter.relations[`relations_${relationshipsTableName}`] = relations(relationshipsTable, ({ one })=>{
|
|
320
|
-
const result = {
|
|
321
|
-
parent: one(table, {
|
|
322
|
-
fields: [
|
|
323
|
-
relationshipsTable.parent
|
|
324
|
-
],
|
|
325
|
-
references: [
|
|
326
|
-
table.id
|
|
327
|
-
],
|
|
328
|
-
relationName: '_rels'
|
|
329
|
-
})
|
|
330
|
-
};
|
|
331
|
-
relationships.forEach((relationTo)=>{
|
|
332
|
-
const relatedTableName = createTableName({
|
|
333
|
-
adapter,
|
|
334
|
-
config: adapter.payload.collections[relationTo].config,
|
|
335
|
-
throwValidationError: true
|
|
336
|
-
});
|
|
337
|
-
const idColumnName = `${relationTo}ID`;
|
|
338
|
-
result[idColumnName] = one(adapter.tables[relatedTableName], {
|
|
339
|
-
fields: [
|
|
340
|
-
relationshipsTable[idColumnName]
|
|
341
|
-
],
|
|
342
|
-
references: [
|
|
343
|
-
adapter.tables[relatedTableName].id
|
|
344
|
-
],
|
|
345
|
-
relationName: relationTo
|
|
346
|
-
});
|
|
347
|
-
});
|
|
348
|
-
return result;
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
adapter.relations[`relations_${tableName}`] = relations(table, ({ many, one })=>{
|
|
353
|
-
const result = {};
|
|
354
|
-
nonLocalizedRelations.forEach(({ type, relationName, target }, key)=>{
|
|
355
|
-
if (type === 'one') {
|
|
356
|
-
result[key] = one(adapter.tables[target], {
|
|
357
|
-
fields: [
|
|
358
|
-
table[key]
|
|
359
|
-
],
|
|
360
|
-
references: [
|
|
361
|
-
adapter.tables[target].id
|
|
362
|
-
],
|
|
363
|
-
relationName: key
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
if (type === 'many') {
|
|
367
|
-
result[key] = many(adapter.tables[target], {
|
|
368
|
-
relationName: relationName || key
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
});
|
|
372
|
-
if (hasLocalizedField) {
|
|
373
|
-
result._locales = many(localesTable, {
|
|
374
|
-
relationName: '_locales'
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
if (hasManyTextField) {
|
|
378
|
-
result._texts = many(textsTable, {
|
|
379
|
-
relationName: '_texts'
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
if (hasManyNumberField) {
|
|
383
|
-
result._numbers = many(numbersTable, {
|
|
384
|
-
relationName: '_numbers'
|
|
385
|
-
});
|
|
386
|
-
}
|
|
387
|
-
if (relationships.size && relationshipsTable) {
|
|
388
|
-
result._rels = many(relationshipsTable, {
|
|
389
|
-
relationName: '_rels'
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
return result;
|
|
393
|
-
});
|
|
394
|
-
return {
|
|
395
|
-
hasLocalizedManyNumberField,
|
|
396
|
-
hasLocalizedManyTextField,
|
|
397
|
-
hasLocalizedRelationshipField,
|
|
398
|
-
hasManyNumberField,
|
|
399
|
-
hasManyTextField,
|
|
400
|
-
relationsToBuild
|
|
401
|
-
};
|
|
402
|
-
};
|
|
403
|
-
|
|
404
|
-
//# sourceMappingURL=build.js.map
|