@payloadcms/drizzle 3.0.0-canary.f1f97ff → 3.0.0-canary.ff8c8fd
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/dist/exports/postgres.d.ts +14 -0
- package/dist/exports/postgres.d.ts.map +1 -0
- package/dist/exports/postgres.js +15 -0
- package/dist/exports/postgres.js.map +1 -0
- package/dist/find/traverseFields.d.ts.map +1 -1
- package/dist/find/traverseFields.js +2 -2
- package/dist/find/traverseFields.js.map +1 -1
- package/dist/migrate.d.ts +1 -1
- package/dist/migrate.d.ts.map +1 -1
- package/dist/migrate.js +4 -10
- package/dist/migrate.js.map +1 -1
- package/dist/migrateFresh.js.map +1 -1
- package/dist/postgres/countDistinct.d.ts +3 -0
- package/dist/postgres/countDistinct.d.ts.map +1 -0
- package/dist/postgres/countDistinct.js +24 -0
- package/dist/postgres/countDistinct.js.map +1 -0
- package/dist/postgres/createJSONQuery/convertPathToJSONTraversal.d.ts +2 -0
- package/dist/postgres/createJSONQuery/convertPathToJSONTraversal.d.ts.map +1 -0
- package/dist/postgres/createJSONQuery/convertPathToJSONTraversal.js +14 -0
- package/dist/postgres/createJSONQuery/convertPathToJSONTraversal.js.map +1 -0
- package/dist/postgres/createJSONQuery/formatJSONPathSegment.d.ts +2 -0
- package/dist/postgres/createJSONQuery/formatJSONPathSegment.d.ts.map +1 -0
- package/dist/postgres/createJSONQuery/formatJSONPathSegment.js +5 -0
- package/dist/postgres/createJSONQuery/formatJSONPathSegment.js.map +1 -0
- package/dist/postgres/createJSONQuery/index.d.ts +10 -0
- package/dist/postgres/createJSONQuery/index.d.ts.map +1 -0
- package/dist/postgres/createJSONQuery/index.js +54 -0
- package/dist/postgres/createJSONQuery/index.js.map +1 -0
- package/dist/postgres/createMigration.d.ts +3 -0
- package/dist/postgres/createMigration.d.ts.map +1 -0
- package/dist/postgres/createMigration.js +92 -0
- package/dist/postgres/createMigration.js.map +1 -0
- package/dist/postgres/defaultSnapshot.d.ts +3 -0
- package/dist/postgres/defaultSnapshot.d.ts.map +1 -0
- package/dist/postgres/defaultSnapshot.js +17 -0
- package/dist/postgres/defaultSnapshot.js.map +1 -0
- package/dist/postgres/deleteWhere.d.ts +3 -0
- package/dist/postgres/deleteWhere.d.ts.map +1 -0
- package/dist/postgres/deleteWhere.js +6 -0
- package/dist/postgres/deleteWhere.js.map +1 -0
- package/dist/postgres/dropDatabase.d.ts +3 -0
- package/dist/postgres/dropDatabase.d.ts.map +1 -0
- package/dist/postgres/dropDatabase.js +9 -0
- package/dist/postgres/dropDatabase.js.map +1 -0
- package/dist/postgres/execute.d.ts +3 -0
- package/dist/postgres/execute.d.ts.map +1 -0
- package/dist/postgres/execute.js +11 -0
- package/dist/postgres/execute.js.map +1 -0
- package/dist/postgres/getMigrationTemplate.d.ts +4 -0
- package/dist/postgres/getMigrationTemplate.d.ts.map +1 -0
- package/dist/postgres/getMigrationTemplate.js +13 -0
- package/dist/postgres/getMigrationTemplate.js.map +1 -0
- package/dist/postgres/init.d.ts +3 -0
- package/dist/postgres/init.d.ts.map +1 -0
- package/dist/postgres/init.js +95 -0
- package/dist/postgres/init.js.map +1 -0
- package/dist/postgres/insert.d.ts +3 -0
- package/dist/postgres/insert.d.ts.map +1 -0
- package/dist/postgres/insert.js +12 -0
- package/dist/postgres/insert.js.map +1 -0
- package/dist/postgres/requireDrizzleKit.d.ts +3 -0
- package/dist/postgres/requireDrizzleKit.d.ts.map +1 -0
- package/dist/postgres/requireDrizzleKit.js +5 -0
- package/dist/postgres/requireDrizzleKit.js.map +1 -0
- package/dist/postgres/schema/build.d.ts +32 -0
- package/dist/postgres/schema/build.d.ts.map +1 -0
- package/dist/postgres/schema/build.js +369 -0
- package/dist/postgres/schema/build.js.map +1 -0
- package/dist/postgres/schema/createIndex.d.ts +12 -0
- package/dist/postgres/schema/createIndex.d.ts.map +1 -0
- package/dist/postgres/schema/createIndex.js +18 -0
- package/dist/postgres/schema/createIndex.js.map +1 -0
- package/dist/postgres/schema/idToUUID.d.ts +3 -0
- package/dist/postgres/schema/idToUUID.d.ts.map +1 -0
- package/dist/postgres/schema/idToUUID.js +11 -0
- package/dist/postgres/schema/idToUUID.js.map +1 -0
- package/dist/postgres/schema/parentIDColumnMap.d.ts +4 -0
- package/dist/postgres/schema/parentIDColumnMap.d.ts.map +1 -0
- package/dist/postgres/schema/parentIDColumnMap.js +9 -0
- package/dist/postgres/schema/parentIDColumnMap.js.map +1 -0
- package/dist/postgres/schema/setColumnID.d.ts +11 -0
- package/dist/postgres/schema/setColumnID.d.ts.map +1 -0
- package/dist/postgres/schema/setColumnID.js +24 -0
- package/dist/postgres/schema/setColumnID.js.map +1 -0
- package/dist/postgres/schema/traverseFields.d.ts +35 -0
- package/dist/postgres/schema/traverseFields.d.ts.map +1 -0
- package/dist/postgres/schema/traverseFields.js +615 -0
- package/dist/postgres/schema/traverseFields.js.map +1 -0
- package/dist/postgres/schema/withDefault.d.ts +4 -0
- package/dist/postgres/schema/withDefault.d.ts.map +1 -0
- package/dist/postgres/schema/withDefault.js +10 -0
- package/dist/postgres/schema/withDefault.js.map +1 -0
- package/dist/postgres/types.d.ts +112 -0
- package/dist/postgres/types.d.ts.map +1 -0
- package/dist/postgres/types.js +3 -0
- package/dist/postgres/types.js.map +1 -0
- package/dist/queries/getTableColumnFromPath.js +1 -1
- package/dist/queries/getTableColumnFromPath.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/upsertRow/index.d.ts.map +1 -1
- package/dist/upsertRow/index.js +1 -0
- package/dist/upsertRow/index.js.map +1 -1
- package/dist/utilities/hasLocalesTable.d.ts.map +1 -1
- package/dist/utilities/hasLocalesTable.js +3 -1
- package/dist/utilities/hasLocalesTable.js.map +1 -1
- package/package.json +12 -5
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { countDistinct } from '../postgres/countDistinct.js';
|
|
2
|
+
export { convertPathToJSONTraversal } from '../postgres/createJSONQuery/convertPathToJSONTraversal.js';
|
|
3
|
+
export { createJSONQuery } from '../postgres/createJSONQuery/index.js';
|
|
4
|
+
export { createMigration } from '../postgres/createMigration.js';
|
|
5
|
+
export { defaultDrizzleSnapshot } from '../postgres/defaultSnapshot.js';
|
|
6
|
+
export { deleteWhere } from '../postgres/deleteWhere.js';
|
|
7
|
+
export { dropDatabase } from '../postgres/dropDatabase.js';
|
|
8
|
+
export { execute } from '../postgres/execute.js';
|
|
9
|
+
export { getMigrationTemplate } from '../postgres/getMigrationTemplate.js';
|
|
10
|
+
export { init } from '../postgres/init.js';
|
|
11
|
+
export { insert } from '../postgres/insert.js';
|
|
12
|
+
export { requireDrizzleKit } from '../postgres/requireDrizzleKit.js';
|
|
13
|
+
export * from '../postgres/types.js';
|
|
14
|
+
//# sourceMappingURL=postgres.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../src/exports/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAC5D,OAAO,EAAE,0BAA0B,EAAE,MAAM,2DAA2D,CAAA;AACtG,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAA;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAA;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAA;AAC1E,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AACpE,cAAc,sBAAsB,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { countDistinct } from '../postgres/countDistinct.js';
|
|
2
|
+
export { convertPathToJSONTraversal } from '../postgres/createJSONQuery/convertPathToJSONTraversal.js';
|
|
3
|
+
export { createJSONQuery } from '../postgres/createJSONQuery/index.js';
|
|
4
|
+
export { createMigration } from '../postgres/createMigration.js';
|
|
5
|
+
export { defaultDrizzleSnapshot } from '../postgres/defaultSnapshot.js';
|
|
6
|
+
export { deleteWhere } from '../postgres/deleteWhere.js';
|
|
7
|
+
export { dropDatabase } from '../postgres/dropDatabase.js';
|
|
8
|
+
export { execute } from '../postgres/execute.js';
|
|
9
|
+
export { getMigrationTemplate } from '../postgres/getMigrationTemplate.js';
|
|
10
|
+
export { init } from '../postgres/init.js';
|
|
11
|
+
export { insert } from '../postgres/insert.js';
|
|
12
|
+
export { requireDrizzleKit } from '../postgres/requireDrizzleKit.js';
|
|
13
|
+
export * from '../postgres/types.js';
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=postgres.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/exports/postgres.ts"],"sourcesContent":["export { countDistinct } from '../postgres/countDistinct.js'\nexport { convertPathToJSONTraversal } from '../postgres/createJSONQuery/convertPathToJSONTraversal.js'\nexport { createJSONQuery } from '../postgres/createJSONQuery/index.js'\nexport { createMigration } from '../postgres/createMigration.js'\nexport { defaultDrizzleSnapshot } from '../postgres/defaultSnapshot.js'\nexport { deleteWhere } from '../postgres/deleteWhere.js'\nexport { dropDatabase } from '../postgres/dropDatabase.js'\nexport { execute } from '../postgres/execute.js'\nexport { getMigrationTemplate } from '../postgres/getMigrationTemplate.js'\nexport { init } from '../postgres/init.js'\nexport { insert } from '../postgres/insert.js'\nexport { requireDrizzleKit } from '../postgres/requireDrizzleKit.js'\nexport * from '../postgres/types.js'\n"],"names":["countDistinct","convertPathToJSONTraversal","createJSONQuery","createMigration","defaultDrizzleSnapshot","deleteWhere","dropDatabase","execute","getMigrationTemplate","init","insert","requireDrizzleKit"],"mappings":"AAAA,SAASA,aAAa,QAAQ,+BAA8B;AAC5D,SAASC,0BAA0B,QAAQ,4DAA2D;AACtG,SAASC,eAAe,QAAQ,uCAAsC;AACtE,SAASC,eAAe,QAAQ,iCAAgC;AAChE,SAASC,sBAAsB,QAAQ,iCAAgC;AACvE,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,YAAY,QAAQ,8BAA6B;AAC1D,SAASC,OAAO,QAAQ,yBAAwB;AAChD,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,IAAI,QAAQ,sBAAqB;AAC1C,SAASC,MAAM,QAAQ,wBAAuB;AAC9C,SAASC,iBAAiB,QAAQ,mCAAkC;AACpE,cAAc,uBAAsB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../src/find/traverseFields.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../src/find/traverseFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAKpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAEpD,KAAK,iBAAiB,GAAG;IACvB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,cAAc,CAAA;IACvB,WAAW,EAAE,MAAM,CAAA;IACnB,gBAAgB,EAAE,MAAM,CAAA;IACxB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACrC,iBAAiB,EAAE,MAAM,CAAA;CAC1B,CAAA;AAED,eAAO,MAAM,cAAc,gHAUxB,iBAAiB,4BA+KnB,CAAA"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { fieldAffectsData, tabHasName } from 'payload/shared';
|
|
2
2
|
import toSnakeCase from 'to-snake-case';
|
|
3
3
|
export const traverseFields = ({ _locales, adapter, currentArgs, currentTableName, depth, fields, path, topLevelArgs, topLevelTableName })=>{
|
|
4
4
|
fields.forEach((field)=>{
|
|
5
5
|
// handle simple relationship
|
|
6
|
-
if (depth > 0 && (field.type === 'upload' || field.type === 'relationship' && !field.hasMany && typeof field.relationTo === 'string')
|
|
6
|
+
if (depth > 0 && (field.type === 'upload' || field.type === 'relationship') && !field.hasMany && typeof field.relationTo === 'string') {
|
|
7
7
|
if (field.localized) {
|
|
8
8
|
_locales.with[`${path}${field.name}`] = true;
|
|
9
9
|
} else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/find/traverseFields.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../src/find/traverseFields.ts"],"sourcesContent":["import type { Field } from 'payload'\n\nimport { fieldAffectsData, tabHasName } from 'payload/shared'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from '../types.js'\nimport type { Result } from './buildFindManyArgs.js'\n\ntype TraverseFieldArgs = {\n _locales: Result\n adapter: DrizzleAdapter\n currentArgs: Result\n currentTableName: string\n depth?: number\n fields: Field[]\n path: string\n topLevelArgs: Record<string, unknown>\n topLevelTableName: string\n}\n\nexport const traverseFields = ({\n _locales,\n adapter,\n currentArgs,\n currentTableName,\n depth,\n fields,\n path,\n topLevelArgs,\n topLevelTableName,\n}: TraverseFieldArgs) => {\n fields.forEach((field) => {\n // handle simple relationship\n if (\n depth > 0 &&\n (field.type === 'upload' || field.type === 'relationship') &&\n !field.hasMany &&\n typeof field.relationTo === 'string'\n ) {\n if (field.localized) {\n _locales.with[`${path}${field.name}`] = true\n } else {\n currentArgs.with[`${path}${field.name}`] = true\n }\n }\n\n if (field.type === 'collapsible' || field.type === 'row') {\n traverseFields({\n _locales,\n adapter,\n currentArgs,\n currentTableName,\n depth,\n fields: field.fields,\n path,\n topLevelArgs,\n topLevelTableName,\n })\n\n return\n }\n\n if (field.type === 'tabs') {\n field.tabs.forEach((tab) => {\n const tabPath = tabHasName(tab) ? `${path}${tab.name}_` : path\n\n traverseFields({\n _locales,\n adapter,\n currentArgs,\n currentTableName,\n depth,\n fields: tab.fields,\n path: tabPath,\n topLevelArgs,\n topLevelTableName,\n })\n })\n\n return\n }\n\n if (fieldAffectsData(field)) {\n switch (field.type) {\n case 'array': {\n const withArray: Result = {\n columns: {\n _parentID: false,\n },\n orderBy: ({ _order }, { asc }) => [asc(_order)],\n with: {},\n }\n\n const arrayTableName = adapter.tableNameMap.get(\n `${currentTableName}_${path}${toSnakeCase(field.name)}`,\n )\n\n const arrayTableNameWithLocales = `${arrayTableName}${adapter.localesSuffix}`\n\n if (adapter.tables[arrayTableNameWithLocales]) {\n withArray.with._locales = {\n columns: {\n id: false,\n _parentID: false,\n },\n with: {},\n }\n }\n currentArgs.with[`${path}${field.name}`] = withArray\n\n traverseFields({\n _locales: withArray.with._locales,\n adapter,\n currentArgs: withArray,\n currentTableName: arrayTableName,\n depth,\n fields: field.fields,\n path: '',\n topLevelArgs,\n topLevelTableName,\n })\n\n break\n }\n\n case 'select': {\n if (field.hasMany) {\n const withSelect: Result = {\n columns: {\n id: false,\n order: false,\n parent: false,\n },\n orderBy: ({ order }, { asc }) => [asc(order)],\n }\n\n currentArgs.with[`${path}${field.name}`] = withSelect\n }\n\n break\n }\n\n case 'blocks':\n field.blocks.forEach((block) => {\n const blockKey = `_blocks_${block.slug}`\n\n if (!topLevelArgs[blockKey]) {\n const withBlock: Result = {\n columns: {\n _parentID: false,\n },\n orderBy: ({ _order }, { asc }) => [asc(_order)],\n with: {},\n }\n\n const tableName = adapter.tableNameMap.get(\n `${topLevelTableName}_blocks_${toSnakeCase(block.slug)}`,\n )\n\n if (adapter.tables[`${tableName}${adapter.localesSuffix}`]) {\n withBlock.with._locales = {\n with: {},\n }\n }\n topLevelArgs.with[blockKey] = withBlock\n\n traverseFields({\n _locales: withBlock.with._locales,\n adapter,\n currentArgs: withBlock,\n currentTableName: tableName,\n depth,\n fields: block.fields,\n path: '',\n topLevelArgs,\n topLevelTableName,\n })\n }\n })\n\n break\n\n case 'group':\n traverseFields({\n _locales,\n adapter,\n currentArgs,\n currentTableName,\n depth,\n fields: field.fields,\n path: `${path}${field.name}_`,\n topLevelArgs,\n topLevelTableName,\n })\n\n break\n\n default: {\n break\n }\n }\n }\n })\n\n return topLevelArgs\n}\n"],"names":["fieldAffectsData","tabHasName","toSnakeCase","traverseFields","_locales","adapter","currentArgs","currentTableName","depth","fields","path","topLevelArgs","topLevelTableName","forEach","field","type","hasMany","relationTo","localized","with","name","tabs","tab","tabPath","withArray","columns","_parentID","orderBy","_order","asc","arrayTableName","tableNameMap","get","arrayTableNameWithLocales","localesSuffix","tables","id","withSelect","order","parent","blocks","block","blockKey","slug","withBlock","tableName"],"mappings":"AAEA,SAASA,gBAAgB,EAAEC,UAAU,QAAQ,iBAAgB;AAC7D,OAAOC,iBAAiB,gBAAe;AAiBvC,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,QAAQ,EACRC,OAAO,EACPC,WAAW,EACXC,gBAAgB,EAChBC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,YAAY,EACZC,iBAAiB,EACC;IAClBH,OAAOI,OAAO,CAAC,CAACC;QACd,6BAA6B;QAC7B,IACEN,QAAQ,KACPM,CAAAA,MAAMC,IAAI,KAAK,YAAYD,MAAMC,IAAI,KAAK,cAAa,KACxD,CAACD,MAAME,OAAO,IACd,OAAOF,MAAMG,UAAU,KAAK,UAC5B;YACA,IAAIH,MAAMI,SAAS,EAAE;gBACnBd,SAASe,IAAI,CAAC,CAAC,EAAET,KAAK,EAAEI,MAAMM,IAAI,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Q6B,aAAa,CAAC,CAAC,CAAC,EAAE;gCAC1DU,UAAUzB,IAAI,CAACf,QAAQ,GAAG;oCACxBe,MAAM,CAAC;gCACT;4BACF;4BACAR,aAAaQ,IAAI,CAACuB,SAAS,GAAGE;4BAE9BzC,eAAe;gCACbC,UAAUwC,UAAUzB,IAAI,CAACf,QAAQ;gCACjCC;gCACAC,aAAasC;gCACbrC,kBAAkBsC;gCAClBrC;gCACAC,QAAQgC,MAAMhC,MAAM;gCACpBC,MAAM;gCACNC;gCACAC;4BACF;wBACF;oBACF;oBAEA;gBAEF,KAAK;oBACHT,eAAe;wBACbC;wBACAC;wBACAC;wBACAC;wBACAC;wBACAC,QAAQK,MAAML,MAAM;wBACpBC,MAAM,CAAC,EAAEA,KAAK,EAAEI,MAAMM,IAAI,CAAC,CAAC,CAAC;wBAC7BT;wBACAC;oBACF;oBAEA;gBAEF;oBAAS;wBACP;oBACF;YACF;QACF;IACF;IAEA,OAAOD;AACT,EAAC"}
|
package/dist/migrate.d.ts
CHANGED
package/dist/migrate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAa,MAAM,YAAY,CAAA;AAK3D,eAAO,MAAM,OAAO,EAAE,cAAc,CAAC,SAAS,CA+D7C,CAAA"}
|
package/dist/migrate.js
CHANGED
|
@@ -2,9 +2,9 @@ import { commitTransaction, initTransaction, killTransaction, readMigrationFiles
|
|
|
2
2
|
import prompts from 'prompts';
|
|
3
3
|
import { migrationTableExists } from './utilities/migrationTableExists.js';
|
|
4
4
|
import { parseError } from './utilities/parseError.js';
|
|
5
|
-
export async function migrate() {
|
|
5
|
+
export const migrate = async function migrate(args) {
|
|
6
6
|
const { payload } = this;
|
|
7
|
-
const migrationFiles = await readMigrationFiles({
|
|
7
|
+
const migrationFiles = args?.migrations || await readMigrationFiles({
|
|
8
8
|
payload
|
|
9
9
|
});
|
|
10
10
|
if (!migrationFiles.length) {
|
|
@@ -51,10 +51,8 @@ export async function migrate() {
|
|
|
51
51
|
}
|
|
52
52
|
await runMigrationFile(payload, migration, newBatch);
|
|
53
53
|
}
|
|
54
|
-
}
|
|
54
|
+
};
|
|
55
55
|
async function runMigrationFile(payload, migration, batch) {
|
|
56
|
-
const db = payload.db;
|
|
57
|
-
const { generateDrizzleJson } = db.requireDrizzleKit();
|
|
58
56
|
const start = Date.now();
|
|
59
57
|
const req = {
|
|
60
58
|
payload
|
|
@@ -63,9 +61,6 @@ async function runMigrationFile(payload, migration, batch) {
|
|
|
63
61
|
payload.logger.info({
|
|
64
62
|
msg: `Migrating: ${migration.name}`
|
|
65
63
|
});
|
|
66
|
-
const drizzleJSON = await generateDrizzleJson({
|
|
67
|
-
schema: adapter.schema
|
|
68
|
-
});
|
|
69
64
|
try {
|
|
70
65
|
await initTransaction(req);
|
|
71
66
|
const db = adapter?.sessions[await req.transactionID]?.db || adapter.drizzle;
|
|
@@ -81,8 +76,7 @@ async function runMigrationFile(payload, migration, batch) {
|
|
|
81
76
|
collection: 'payload-migrations',
|
|
82
77
|
data: {
|
|
83
78
|
name: migration.name,
|
|
84
|
-
batch
|
|
85
|
-
schema: drizzleJSON
|
|
79
|
+
batch
|
|
86
80
|
},
|
|
87
81
|
req
|
|
88
82
|
});
|
package/dist/migrate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/migrate.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../src/migrate.ts"],"sourcesContent":["import type { Payload, PayloadRequest } from 'payload'\n\nimport { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload'\nimport prompts from 'prompts'\n\nimport type { DrizzleAdapter, Migration } from './types.js'\n\nimport { migrationTableExists } from './utilities/migrationTableExists.js'\nimport { parseError } from './utilities/parseError.js'\n\nexport const migrate: DrizzleAdapter['migrate'] = async function migrate(\n this: DrizzleAdapter,\n args,\n): Promise<void> {\n const { payload } = this\n const migrationFiles = args?.migrations || (await readMigrationFiles({ payload }))\n\n if (!migrationFiles.length) {\n payload.logger.info({ msg: 'No migrations to run.' })\n return\n }\n\n let latestBatch = 0\n let migrationsInDB = []\n\n const hasMigrationTable = await migrationTableExists(this)\n\n if (hasMigrationTable) {\n ;({ docs: migrationsInDB } = await payload.find({\n collection: 'payload-migrations',\n limit: 0,\n sort: '-name',\n }))\n if (Number(migrationsInDB?.[0]?.batch) > 0) {\n latestBatch = Number(migrationsInDB[0]?.batch)\n }\n }\n\n if (migrationsInDB.find((m) => m.batch === -1)) {\n const { confirm: runMigrations } = await prompts(\n {\n name: 'confirm',\n type: 'confirm',\n initial: false,\n message:\n \"It looks like you've run Payload in dev mode, meaning you've dynamically pushed changes to your database.\\n\\n\" +\n \"If you'd like to run migrations, data loss will occur. Would you like to proceed?\",\n },\n {\n onCancel: () => {\n process.exit(0)\n },\n },\n )\n\n if (!runMigrations) {\n process.exit(0)\n }\n }\n\n const newBatch = latestBatch + 1\n\n // Execute 'up' function for each migration sequentially\n for (const migration of migrationFiles) {\n const alreadyRan = migrationsInDB.find((existing) => existing.name === migration.name)\n\n // If already ran, skip\n if (alreadyRan) {\n continue\n }\n\n await runMigrationFile(payload, migration, newBatch)\n }\n}\n\nasync function runMigrationFile(payload: Payload, migration: Migration, batch: number) {\n const start = Date.now()\n const req = { payload } as PayloadRequest\n const adapter = payload.db as DrizzleAdapter\n\n payload.logger.info({ msg: `Migrating: ${migration.name}` })\n\n try {\n await initTransaction(req)\n const db = adapter?.sessions[await req.transactionID]?.db || adapter.drizzle\n await migration.up({ db, payload, req })\n payload.logger.info({ msg: `Migrated: ${migration.name} (${Date.now() - start}ms)` })\n await payload.create({\n collection: 'payload-migrations',\n data: {\n name: migration.name,\n batch,\n },\n req,\n })\n await commitTransaction(req)\n } catch (err: unknown) {\n await killTransaction(req)\n payload.logger.error({\n err,\n msg: parseError(err, `Error running migration ${migration.name}`),\n })\n }\n}\n"],"names":["commitTransaction","initTransaction","killTransaction","readMigrationFiles","prompts","migrationTableExists","parseError","migrate","args","payload","migrationFiles","migrations","length","logger","info","msg","latestBatch","migrationsInDB","hasMigrationTable","docs","find","collection","limit","sort","Number","batch","m","confirm","runMigrations","name","type","initial","message","onCancel","process","exit","newBatch","migration","alreadyRan","existing","runMigrationFile","start","Date","now","req","adapter","db","sessions","transactionID","drizzle","up","create","data","err","error"],"mappings":"AAEA,SAASA,iBAAiB,EAAEC,eAAe,EAAEC,eAAe,EAAEC,kBAAkB,QAAQ,UAAS;AACjG,OAAOC,aAAa,UAAS;AAI7B,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,UAAqC,eAAeA,QAE/DC,IAAI;IAEJ,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IACxB,MAAMC,iBAAiBF,MAAMG,cAAe,MAAMR,mBAAmB;QAAEM;IAAQ;IAE/E,IAAI,CAACC,eAAeE,MAAM,EAAE;QAC1BH,QAAQI,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK;QAAwB;QACnD;IACF;IAEA,IAAIC,cAAc;IAClB,IAAIC,iBAAiB,EAAE;IAEvB,MAAMC,oBAAoB,MAAMb,qBAAqB,IAAI;IAEzD,IAAIa,mBAAmB;QACnB,CAAA,EAAEC,MAAMF,cAAc,EAAE,GAAG,MAAMR,QAAQW,IAAI,CAAC;YAC9CC,YAAY;YACZC,OAAO;YACPC,MAAM;QACR,EAAC;QACD,IAAIC,OAAOP,gBAAgB,CAAC,EAAE,EAAEQ,SAAS,GAAG;YAC1CT,cAAcQ,OAAOP,cAAc,CAAC,EAAE,EAAEQ;QAC1C;IACF;IAEA,IAAIR,eAAeG,IAAI,CAAC,CAACM,IAAMA,EAAED,KAAK,KAAK,CAAC,I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YACAmB;QACF;QACA,MAAM5C,kBAAkB4C;IAC1B,EAAE,OAAOS,KAAc;QACrB,MAAMnD,gBAAgB0C;QACtBnC,QAAQI,MAAM,CAACyC,KAAK,CAAC;YACnBD;YACAtC,KAAKT,WAAW+C,KAAK,CAAC,wBAAwB,EAAEhB,UAAUR,IAAI,CAAC,CAAC;QAClE;IACF;AACF"}
|
package/dist/migrateFresh.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/migrateFresh.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload'\nimport prompts from 'prompts'\n\nimport type { DrizzleAdapter, Migration } from './types.js'\n\nimport { parseError } from './utilities/parseError.js'\n\n/**\n * Drop the current database and run all migrate up functions\n */\nexport async function migrateFresh(\n this: DrizzleAdapter,\n { forceAcceptWarning = false },\n): Promise<void> {\n const { payload } = this\n\n if (forceAcceptWarning === false) {\n const { confirm: acceptWarning } = await prompts(\n {\n name: 'confirm',\n type: 'confirm',\n initial: false,\n message: `WARNING: This will drop your database and run all migrations. Are you sure you want to proceed?`,\n },\n {\n onCancel: () => {\n process.exit(0)\n },\n },\n )\n\n if (!acceptWarning) {\n process.exit(0)\n }\n }\n\n payload.logger.info({\n msg: `Dropping database.`,\n })\n\n await this.dropDatabase({ adapter: this })\n\n const migrationFiles =
|
|
1
|
+
{"version":3,"sources":["../src/migrateFresh.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload'\nimport prompts from 'prompts'\n\nimport type { DrizzleAdapter, Migration } from './types.js'\n\nimport { parseError } from './utilities/parseError.js'\n\n/**\n * Drop the current database and run all migrate up functions\n */\nexport async function migrateFresh(\n this: DrizzleAdapter,\n { forceAcceptWarning = false },\n): Promise<void> {\n const { payload } = this\n\n if (forceAcceptWarning === false) {\n const { confirm: acceptWarning } = await prompts(\n {\n name: 'confirm',\n type: 'confirm',\n initial: false,\n message: `WARNING: This will drop your database and run all migrations. Are you sure you want to proceed?`,\n },\n {\n onCancel: () => {\n process.exit(0)\n },\n },\n )\n\n if (!acceptWarning) {\n process.exit(0)\n }\n }\n\n payload.logger.info({\n msg: `Dropping database.`,\n })\n\n await this.dropDatabase({ adapter: this })\n\n const migrationFiles = await readMigrationFiles({ payload })\n payload.logger.debug({\n msg: `Found ${migrationFiles.length} migration files.`,\n })\n\n const req = { payload } as PayloadRequest\n // Run all migrate up\n for (const migration of migrationFiles) {\n payload.logger.info({ msg: `Migrating: ${migration.name}` })\n try {\n const start = Date.now()\n await initTransaction(req)\n const adapter = payload.db as DrizzleAdapter\n const db = adapter?.sessions[await req.transactionID]?.db || adapter.drizzle\n await migration.up({ db, payload, req })\n await payload.create({\n collection: 'payload-migrations',\n data: {\n name: migration.name,\n batch: 1,\n },\n req,\n })\n await commitTransaction(req)\n\n payload.logger.info({ msg: `Migrated: ${migration.name} (${Date.now() - start}ms)` })\n } catch (err: unknown) {\n await killTransaction(req)\n payload.logger.error({\n err,\n msg: parseError(err, `Error running migration ${migration.name}. Rolling back`),\n })\n }\n }\n}\n"],"names":["commitTransaction","initTransaction","killTransaction","readMigrationFiles","prompts","parseError","migrateFresh","forceAcceptWarning","payload","confirm","acceptWarning","name","type","initial","message","onCancel","process","exit","logger","info","msg","dropDatabase","adapter","migrationFiles","debug","length","req","migration","start","Date","now","db","sessions","transactionID","drizzle","up","create","collection","data","batch","err","error"],"mappings":"AAEA,SAASA,iBAAiB,EAAEC,eAAe,EAAEC,eAAe,EAAEC,kBAAkB,QAAQ,UAAS;AACjG,OAAOC,aAAa,UAAS;AAI7B,SAASC,UAAU,QAAQ,4BAA2B;AAEtD;;CAEC,GACD,OAAO,eAAeC,aAEpB,EAAEC,qBAAqB,KAAK,EAAE;IAE9B,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IAExB,IAAID,uBAAuB,OAAO;QAChC,MAAM,EAAEE,SAASC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C,EAAE,EAAEkB,KAAKC,GAAG,KAAKF,MAAM,GAAG,CAAC;YAAC;QACtF,EAAE,OAAOY,KAAc;YACrB,MAAMtC,gBAAgBwB;YACtBlB,QAAQU,MAAM,CAACuB,KAAK,CAAC;gBACnBD;gBACApB,KAAKf,WAAWmC,KAAK,CAAC,wBAAwB,EAAEb,UAAUhB,IAAI,CAAC,cAAc,CAAC;YAChF;QACF;IACF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"countDistinct.d.ts","sourceRoot":"","sources":["../../src/postgres/countDistinct.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAuB,aAAa,EAAE,MAAM,YAAY,CAAA;AAIpE,eAAO,MAAM,aAAa,EAAE,aAyB3B,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
2
|
+
import { chainMethods } from '../find/chainMethods.js';
|
|
3
|
+
export const countDistinct = async function countDistinct({ db, joins, tableName, where }) {
|
|
4
|
+
const chainedMethods = [];
|
|
5
|
+
joins.forEach(({ condition, table })=>{
|
|
6
|
+
chainedMethods.push({
|
|
7
|
+
args: [
|
|
8
|
+
table,
|
|
9
|
+
condition
|
|
10
|
+
],
|
|
11
|
+
method: 'leftJoin'
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
const countResult = await chainMethods({
|
|
15
|
+
methods: chainedMethods,
|
|
16
|
+
query: db.select({
|
|
17
|
+
count: sql`count
|
|
18
|
+
(DISTINCT ${this.tables[tableName].id})`
|
|
19
|
+
}).from(this.tables[tableName]).where(where)
|
|
20
|
+
});
|
|
21
|
+
return Number(countResult[0].count);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=countDistinct.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/postgres/countDistinct.ts"],"sourcesContent":["import { sql } from 'drizzle-orm'\n\nimport type { ChainedMethods, TransactionPg } from '../types.js'\nimport type { BasePostgresAdapter, CountDistinct } from './types.js'\n\nimport { chainMethods } from '../find/chainMethods.js'\n\nexport const countDistinct: CountDistinct = async function countDistinct(\n this: BasePostgresAdapter,\n { db, joins, tableName, where },\n) {\n const chainedMethods: ChainedMethods = []\n\n joins.forEach(({ condition, table }) => {\n chainedMethods.push({\n args: [table, condition],\n method: 'leftJoin',\n })\n })\n\n const countResult = await chainMethods({\n methods: chainedMethods,\n query: (db as TransactionPg)\n .select({\n count: sql<string>`count\n (DISTINCT ${this.tables[tableName].id})`,\n })\n .from(this.tables[tableName])\n .where(where),\n })\n\n return Number(countResult[0].count)\n}\n"],"names":["sql","chainMethods","countDistinct","db","joins","tableName","where","chainedMethods","forEach","condition","table","push","args","method","countResult","methods","query","select","count","tables","id","from","Number"],"mappings":"AAAA,SAASA,GAAG,QAAQ,cAAa;AAKjC,SAASC,YAAY,QAAQ,0BAAyB;AAEtD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,EAAE,EAAEC,KAAK,EAAEC,SAAS,EAAEC,KAAK,EAAE;IAE/B,MAAMC,iBAAiC,EAAE;IAEzCH,MAAMI,OAAO,CAAC,CAAC,EAAEC,SAAS,EAAEC,KAAK,EAAE;QACjCH,eAAeI,IAAI,CAAC;YAClBC,MAAM;gBAACF;gBAAOD;aAAU;YACxBI,QAAQ;QACV;IACF;IAEA,MAAMC,cAAc,MAAMb,aAAa;QACrCc,SAASR;QACTS,OAAO,AAACb,GACLc,MAAM,CAAC;YACNC,OAAOlB,GAAW,CAAC;sBACL,EAAE,IAAI,CAACmB,MAAM,CAACd,UAAU,CAACe,EAAE,CAAC,CAAC,CAAC;QAC9C,GACCC,IAAI,CAAC,IAAI,CAACF,MAAM,CAACd,UAAU,EAC3BC,KAAK,CAACA;IACX;IAEA,OAAOgB,OAAOR,WAAW,CAAC,EAAE,CAACI,KAAK;AACpC,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertPathToJSONTraversal.d.ts","sourceRoot":"","sources":["../../../src/postgres/createJSONQuery/convertPathToJSONTraversal.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,0BAA0B,qBAAsB,MAAM,EAAE,WAUpE,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { formatJSONPathSegment } from './formatJSONPathSegment.js';
|
|
2
|
+
export const convertPathToJSONTraversal = (incomingSegments)=>{
|
|
3
|
+
const segments = [
|
|
4
|
+
...incomingSegments
|
|
5
|
+
];
|
|
6
|
+
segments.shift();
|
|
7
|
+
return segments.reduce((res, segment, i)=>{
|
|
8
|
+
const formattedSegment = formatJSONPathSegment(segment);
|
|
9
|
+
if (i + 1 === segments.length) return `${res}->>${formattedSegment}`;
|
|
10
|
+
return `${res}->${formattedSegment}`;
|
|
11
|
+
}, '');
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=convertPathToJSONTraversal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/postgres/createJSONQuery/convertPathToJSONTraversal.ts"],"sourcesContent":["import { formatJSONPathSegment } from './formatJSONPathSegment.js'\n\nexport const convertPathToJSONTraversal = (incomingSegments: string[]) => {\n const segments = [...incomingSegments]\n segments.shift()\n\n return segments.reduce((res, segment, i) => {\n const formattedSegment = formatJSONPathSegment(segment)\n\n if (i + 1 === segments.length) return `${res}->>${formattedSegment}`\n return `${res}->${formattedSegment}`\n }, '')\n}\n"],"names":["formatJSONPathSegment","convertPathToJSONTraversal","incomingSegments","segments","shift","reduce","res","segment","i","formattedSegment","length"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,6BAA4B;AAElE,OAAO,MAAMC,6BAA6B,CAACC;IACzC,MAAMC,WAAW;WAAID;KAAiB;IACtCC,SAASC,KAAK;IAEd,OAAOD,SAASE,MAAM,CAAC,CAACC,KAAKC,SAASC;QACpC,MAAMC,mBAAmBT,sBAAsBO;QAE/C,IAAIC,IAAI,MAAML,SAASO,MAAM,EAAE,OAAO,CAAC,EAAEJ,IAAI,GAAG,EAAEG,iBAAiB,CAAC;QACpE,OAAO,CAAC,EAAEH,IAAI,EAAE,EAAEG,iBAAiB,CAAC;IACtC,GAAG;AACL,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatJSONPathSegment.d.ts","sourceRoot":"","sources":["../../../src/postgres/createJSONQuery/formatJSONPathSegment.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,YAAa,MAAM,WAEpD,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/postgres/createJSONQuery/formatJSONPathSegment.ts"],"sourcesContent":["export const formatJSONPathSegment = (segment: string) => {\n return Number.isNaN(parseInt(segment)) ? `'${segment}'` : segment\n}\n"],"names":["formatJSONPathSegment","segment","Number","isNaN","parseInt"],"mappings":"AAAA,OAAO,MAAMA,wBAAwB,CAACC;IACpC,OAAOC,OAAOC,KAAK,CAACC,SAASH,YAAY,CAAC,CAAC,EAAEA,QAAQ,CAAC,CAAC,GAAGA;AAC5D,EAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type Args = {
|
|
2
|
+
operator: string;
|
|
3
|
+
pathSegments: string[];
|
|
4
|
+
treatAsArray?: string[];
|
|
5
|
+
treatRootAsArray?: boolean;
|
|
6
|
+
value: unknown;
|
|
7
|
+
};
|
|
8
|
+
export declare const createJSONQuery: ({ operator, pathSegments, treatAsArray, treatRootAsArray, value, }: Args) => string;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/postgres/createJSONQuery/index.ts"],"names":[],"mappings":"AAmDA,KAAK,IAAI,GAAG;IACV,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,KAAK,EAAE,OAAO,CAAA;CACf,CAAA;AAED,eAAO,MAAM,eAAe,uEAMzB,IAAI,KAAG,MAqBT,CAAA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { convertPathToJSONTraversal } from './convertPathToJSONTraversal.js';
|
|
2
|
+
import { formatJSONPathSegment } from './formatJSONPathSegment.js';
|
|
3
|
+
const operatorMap = {
|
|
4
|
+
contains: '~*',
|
|
5
|
+
equals: '=',
|
|
6
|
+
like: '~*'
|
|
7
|
+
};
|
|
8
|
+
const fromArray = ({ isRoot, operator, pathSegments, treatAsArray, value })=>{
|
|
9
|
+
const newPathSegments = pathSegments.slice(isRoot ? 1 : 2);
|
|
10
|
+
const alias = `${pathSegments[isRoot ? 0 : 1]}_alias_${newPathSegments.length}`;
|
|
11
|
+
newPathSegments.unshift(alias);
|
|
12
|
+
const arrayElements = isRoot ? pathSegments[0] : `${pathSegments[0]} -> ${formatJSONPathSegment(pathSegments[1])}`;
|
|
13
|
+
return `EXISTS (
|
|
14
|
+
SELECT 1
|
|
15
|
+
FROM jsonb_array_elements(${arrayElements}) AS ${alias}
|
|
16
|
+
WHERE ${createJSONQuery({
|
|
17
|
+
operator,
|
|
18
|
+
pathSegments: newPathSegments,
|
|
19
|
+
treatAsArray,
|
|
20
|
+
value
|
|
21
|
+
})}
|
|
22
|
+
)`;
|
|
23
|
+
};
|
|
24
|
+
const createConstraint = ({ operator, pathSegments, value })=>{
|
|
25
|
+
const jsonQuery = convertPathToJSONTraversal(pathSegments);
|
|
26
|
+
return `${pathSegments[0]}${jsonQuery} ${operatorMap[operator]} '${value}'`;
|
|
27
|
+
};
|
|
28
|
+
export const createJSONQuery = ({ operator, pathSegments, treatAsArray, treatRootAsArray, value })=>{
|
|
29
|
+
if (treatRootAsArray) {
|
|
30
|
+
return fromArray({
|
|
31
|
+
isRoot: true,
|
|
32
|
+
operator,
|
|
33
|
+
pathSegments,
|
|
34
|
+
treatAsArray,
|
|
35
|
+
value
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (treatAsArray.includes(pathSegments[1])) {
|
|
39
|
+
return fromArray({
|
|
40
|
+
operator,
|
|
41
|
+
pathSegments,
|
|
42
|
+
treatAsArray,
|
|
43
|
+
value
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return createConstraint({
|
|
47
|
+
operator,
|
|
48
|
+
pathSegments,
|
|
49
|
+
treatAsArray,
|
|
50
|
+
value
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/postgres/createJSONQuery/index.ts"],"sourcesContent":["import { convertPathToJSONTraversal } from './convertPathToJSONTraversal.js'\nimport { formatJSONPathSegment } from './formatJSONPathSegment.js'\n\nconst operatorMap = {\n contains: '~*',\n equals: '=',\n like: '~*',\n}\n\ntype FromArrayArgs = {\n isRoot?: true\n operator: string\n pathSegments: string[]\n treatAsArray?: string[]\n value: unknown\n}\n\nconst fromArray = ({ isRoot, operator, pathSegments, treatAsArray, value }: FromArrayArgs) => {\n const newPathSegments = pathSegments.slice(isRoot ? 1 : 2)\n const alias = `${pathSegments[isRoot ? 0 : 1]}_alias_${newPathSegments.length}`\n\n newPathSegments.unshift(alias)\n\n const arrayElements = isRoot\n ? pathSegments[0]\n : `${pathSegments[0]} -> ${formatJSONPathSegment(pathSegments[1])}`\n\n return `EXISTS (\n SELECT 1\n FROM jsonb_array_elements(${arrayElements}) AS ${alias}\n WHERE ${createJSONQuery({\n operator,\n pathSegments: newPathSegments,\n treatAsArray,\n value,\n })}\n )`\n}\n\ntype CreateConstraintArgs = {\n operator: string\n pathSegments: string[]\n treatAsArray?: string[]\n value: unknown\n}\n\nconst createConstraint = ({ operator, pathSegments, value }: CreateConstraintArgs): string => {\n const jsonQuery = convertPathToJSONTraversal(pathSegments)\n return `${pathSegments[0]}${jsonQuery} ${operatorMap[operator]} '${value}'`\n}\n\ntype Args = {\n operator: string\n pathSegments: string[]\n treatAsArray?: string[]\n treatRootAsArray?: boolean\n value: unknown\n}\n\nexport const createJSONQuery = ({\n operator,\n pathSegments,\n treatAsArray,\n treatRootAsArray,\n value,\n}: Args): string => {\n if (treatRootAsArray) {\n return fromArray({\n isRoot: true,\n operator,\n pathSegments,\n treatAsArray,\n value,\n })\n }\n\n if (treatAsArray.includes(pathSegments[1])) {\n return fromArray({\n operator,\n pathSegments,\n treatAsArray,\n value,\n })\n }\n\n return createConstraint({ operator, pathSegments, treatAsArray, value })\n}\n"],"names":["convertPathToJSONTraversal","formatJSONPathSegment","operatorMap","contains","equals","like","fromArray","isRoot","operator","pathSegments","treatAsArray","value","newPathSegments","slice","alias","length","unshift","arrayElements","createJSONQuery","createConstraint","jsonQuery","treatRootAsArray","includes"],"mappings":"AAAA,SAASA,0BAA0B,QAAQ,kCAAiC;AAC5E,SAASC,qBAAqB,QAAQ,6BAA4B;AAElE,MAAMC,cAAc;IAClBC,UAAU;IACVC,QAAQ;IACRC,MAAM;AACR;AAUA,MAAMC,YAAY,CAAC,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,YAAY,EAAEC,YAAY,EAAEC,KAAK,EAAiB;IACvF,MAAMC,kBAAkBH,aAAaI,KAAK,CAACN,SAAS,IAAI;IACxD,MAAMO,QAAQ,CAAC,EAAEL,YAAY,CAACF,SAAS,IAAI,EAAE,CAAC,OAAO,EAAEK,gBAAgBG,MAAM,CAAC,CAAC;IAE/EH,gBAAgBI,OAAO,CAACF;IAExB,MAAMG,gBAAgBV,SAClBE,YAAY,CAAC,EAAE,GACf,CAAC,EAAEA,YAAY,CAAC,EAAE,CAAC,IAAI,EAAER,sBAAsBQ,YAAY,CAAC,EAAE,EAAE,CAAC;IAErE,OAAO,CAAC;;8BAEoB,EAAEQ,cAAc,KAAK,EAAEH,MAAM;UACjD,EAAEI,gBAAgB;QACtBV;QACAC,cAAcG;QACdF;QACAC;IACF,GAAG;GACJ,CAAC;AACJ;AASA,MAAMQ,mBAAmB,CAAC,EAAEX,QAAQ,EAAEC,YAAY,EAAEE,KAAK,EAAwB;IAC/E,MAAMS,YAAYpB,2BAA2BS;IAC7C,OAAO,CAAC,EAAEA,YAAY,CAAC,EAAE,CAAC,EAAEW,UAAU,CAAC,EAAElB,WAAW,CAACM,SAAS,CAAC,EAAE,EAAEG,MAAM,CAAC,CAAC;AAC7E;AAUA,OAAO,MAAMO,kBAAkB,CAAC,EAC9BV,QAAQ,EACRC,YAAY,EACZC,YAAY,EACZW,gBAAgB,EAChBV,KAAK,EACA;IACL,IAAIU,kBAAkB;QACpB,OAAOf,UAAU;YACfC,QAAQ;YACRC;YACAC;YACAC;YACAC;QACF;IACF;IAEA,IAAID,aAAaY,QAAQ,CAACb,YAAY,CAAC,EAAE,GAAG;QAC1C,OAAOH,UAAU;YACfE;YACAC;YACAC;YACAC;QACF;IACF;IAEA,OAAOQ,iBAAiB;QAAEX;QAAUC;QAAcC;QAAcC;IAAM;AACxE,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createMigration.d.ts","sourceRoot":"","sources":["../../src/postgres/createMigration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAgB9C,eAAO,MAAM,eAAe,EAAE,eAyG7B,CAAA"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { createRequire } from 'module';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { getPredefinedMigration, writeMigrationIndex } from 'payload';
|
|
5
|
+
import prompts from 'prompts';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
import { defaultDrizzleSnapshot } from './defaultSnapshot.js';
|
|
8
|
+
import { getMigrationTemplate } from './getMigrationTemplate.js';
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
10
|
+
export const createMigration = async function createMigration({ file, forceAcceptWarning, migrationName, payload }) {
|
|
11
|
+
const filename = fileURLToPath(import.meta.url);
|
|
12
|
+
const dirname = path.dirname(filename);
|
|
13
|
+
const dir = payload.db.migrationDir;
|
|
14
|
+
if (!fs.existsSync(dir)) {
|
|
15
|
+
fs.mkdirSync(dir);
|
|
16
|
+
}
|
|
17
|
+
const { generateDrizzleJson, generateMigration, upPgSnapshot } = require('drizzle-kit/api');
|
|
18
|
+
const drizzleJsonAfter = generateDrizzleJson(this.schema);
|
|
19
|
+
const [yyymmdd, hhmmss] = new Date().toISOString().split('T');
|
|
20
|
+
const formattedDate = yyymmdd.replace(/\D/g, '');
|
|
21
|
+
const formattedTime = hhmmss.split('.')[0].replace(/\D/g, '');
|
|
22
|
+
let imports = '';
|
|
23
|
+
let downSQL;
|
|
24
|
+
let upSQL;
|
|
25
|
+
({ downSQL, imports, upSQL } = await getPredefinedMigration({
|
|
26
|
+
dirname,
|
|
27
|
+
file,
|
|
28
|
+
migrationName,
|
|
29
|
+
payload
|
|
30
|
+
}));
|
|
31
|
+
const timestamp = `${formattedDate}_${formattedTime}`;
|
|
32
|
+
const name = migrationName || file?.split('/').slice(2).join('/');
|
|
33
|
+
const fileName = `${timestamp}${name ? `_${name.replace(/\W/g, '_')}` : ''}`;
|
|
34
|
+
const filePath = `${dir}/${fileName}`;
|
|
35
|
+
let drizzleJsonBefore = defaultDrizzleSnapshot;
|
|
36
|
+
if (this.schemaName) {
|
|
37
|
+
drizzleJsonBefore.schemas = {
|
|
38
|
+
[this.schemaName]: this.schemaName
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (!upSQL) {
|
|
42
|
+
// Get latest migration snapshot
|
|
43
|
+
const latestSnapshot = fs.readdirSync(dir).filter((file)=>file.endsWith('.json')).sort().reverse()?.[0];
|
|
44
|
+
if (latestSnapshot) {
|
|
45
|
+
drizzleJsonBefore = JSON.parse(fs.readFileSync(`${dir}/${latestSnapshot}`, 'utf8'));
|
|
46
|
+
if (drizzleJsonBefore.version < drizzleJsonAfter.version) {
|
|
47
|
+
drizzleJsonBefore = upPgSnapshot(drizzleJsonBefore);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const sqlStatementsUp = await generateMigration(drizzleJsonBefore, drizzleJsonAfter);
|
|
51
|
+
const sqlStatementsDown = await generateMigration(drizzleJsonAfter, drizzleJsonBefore);
|
|
52
|
+
const sqlExecute = 'await payload.db.drizzle.execute(sql`';
|
|
53
|
+
if (sqlStatementsUp?.length) {
|
|
54
|
+
upSQL = `${sqlExecute}\n ${sqlStatementsUp?.join('\n')}\`)`;
|
|
55
|
+
}
|
|
56
|
+
if (sqlStatementsDown?.length) {
|
|
57
|
+
downSQL = `${sqlExecute}\n ${sqlStatementsDown?.join('\n')}\`)`;
|
|
58
|
+
}
|
|
59
|
+
if (!upSQL?.length && !downSQL?.length && !forceAcceptWarning) {
|
|
60
|
+
const { confirm: shouldCreateBlankMigration } = await prompts({
|
|
61
|
+
name: 'confirm',
|
|
62
|
+
type: 'confirm',
|
|
63
|
+
initial: false,
|
|
64
|
+
message: 'No schema changes detected. Would you like to create a blank migration file?'
|
|
65
|
+
}, {
|
|
66
|
+
onCancel: ()=>{
|
|
67
|
+
process.exit(0);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
if (!shouldCreateBlankMigration) {
|
|
71
|
+
process.exit(0);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// write schema
|
|
75
|
+
fs.writeFileSync(`${filePath}.json`, JSON.stringify(drizzleJsonAfter, null, 2));
|
|
76
|
+
}
|
|
77
|
+
// write migration
|
|
78
|
+
fs.writeFileSync(`${filePath}.ts`, getMigrationTemplate({
|
|
79
|
+
downSQL: downSQL || ` // Migration code`,
|
|
80
|
+
imports,
|
|
81
|
+
packageName: payload.db.packageName,
|
|
82
|
+
upSQL: upSQL || ` // Migration code`
|
|
83
|
+
}));
|
|
84
|
+
writeMigrationIndex({
|
|
85
|
+
migrationsDir: payload.db.migrationDir
|
|
86
|
+
});
|
|
87
|
+
payload.logger.info({
|
|
88
|
+
msg: `Migration created at ${filePath}.ts`
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
//# sourceMappingURL=createMigration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/postgres/createMigration.ts"],"sourcesContent":["import type { CreateMigration } from 'payload'\n\nimport fs from 'fs'\nimport { createRequire } from 'module'\nimport path from 'path'\nimport { getPredefinedMigration, writeMigrationIndex } from 'payload'\nimport prompts from 'prompts'\nimport { fileURLToPath } from 'url'\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 { file, forceAcceptWarning, migrationName, payload },\n) {\n const filename = fileURLToPath(import.meta.url)\n const dirname = path.dirname(filename)\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 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","path","getPredefinedMigration","writeMigrationIndex","prompts","fileURLToPath","defaultDrizzleSnapshot","getMigrationTemplate","require","url","createMigration","file","forceAcceptWarning","migrationName","payload","filename","dirname","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","confirm","shouldCreateBlankMigration","type","initial","message","onCancel","process","exit","writeFileSync","stringify","packageName","migrationsDir","logger","info","msg"],"mappings":"AAEA,OAAOA,QAAQ,KAAI;AACnB,SAASC,aAAa,QAAQ,SAAQ;AACtC,OAAOC,UAAU,OAAM;AACvB,SAASC,sBAAsB,EAAEC,mBAAmB,QAAQ,UAAS;AACrE,OAAOC,aAAa,UAAS;AAC7B,SAASC,aAAa,QAAQ,MAAK;AAInC,SAASC,sBAAsB,QAAQ,uBAAsB;AAC7D,SAASC,oBAAoB,QAAQ,4BAA2B;AAEhE,MAAMC,UAAUR,cAAc,YAAYS,GAAG;AAE7C,OAAO,MAAMC,kBAAmC,eAAeA,gBAE7D,EAAEC,IAAI,EAAEC,kBAAkB,EAAEC,aAAa,EAAEC,OAAO,EAAE;IAEpD,MAAMC,WAAWV,cAAc,YAAYI,GAAG;IAC9C,MAAMO,UAAUf,KAAKe,OAAO,CAACD;IAC7B,MAAME,MAAMH,QAAQI,EAAE,CAACC,YAAY;IACnC,IAAI,CAACpB,GAAGqB,UAAU,CAACH,MAAM;QACvBlB,GAAGsB,SAAS,CAACJ;IACf;IACA,MAAM,EAAEK,mBAAmB,EAAEC,iBAAiB,EAAEC,YAAY,EAAE,GAAGhB,QAAQ;IACzE,MAAMiB,mBAAmBH,oBAAoB,IAAI,CAACI,MAAM;IACxD,MAAM,CAACC,SAASC,OAAO,GAAG,IAAIC,OAAOC,WAAW,GAAGC,KAAK,CAAC;IACzD,MAAMC,gBAA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ts","sourceRoot":"","sources":["../../src/postgres/defaultSnapshot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAE1D,eAAO,MAAM,sBAAsB,EAAE,mBAcpC,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const defaultDrizzleSnapshot = {
|
|
2
|
+
id: '00000000-0000-0000-0000-000000000000',
|
|
3
|
+
_meta: {
|
|
4
|
+
columns: {},
|
|
5
|
+
schemas: {},
|
|
6
|
+
tables: {}
|
|
7
|
+
},
|
|
8
|
+
dialect: 'postgresql',
|
|
9
|
+
enums: {},
|
|
10
|
+
prevId: '00000000-0000-0000-0000-00000000000',
|
|
11
|
+
schemas: {},
|
|
12
|
+
sequences: {},
|
|
13
|
+
tables: {},
|
|
14
|
+
version: '7'
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=defaultSnapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/postgres/defaultSnapshot.ts"],"sourcesContent":["import type { DrizzleSnapshotJSON } from 'drizzle-kit/api'\n\nexport const defaultDrizzleSnapshot: DrizzleSnapshotJSON = {\n id: '00000000-0000-0000-0000-000000000000',\n _meta: {\n columns: {},\n schemas: {},\n tables: {},\n },\n dialect: 'postgresql',\n enums: {},\n prevId: '00000000-0000-0000-0000-00000000000',\n schemas: {},\n sequences: {},\n tables: {},\n version: '7',\n}\n"],"names":["defaultDrizzleSnapshot","id","_meta","columns","schemas","tables","dialect","enums","prevId","sequences","version"],"mappings":"AAEA,OAAO,MAAMA,yBAA8C;IACzDC,IAAI;IACJC,OAAO;QACLC,SAAS,CAAC;QACVC,SAAS,CAAC;QACVC,QAAQ,CAAC;IACX;IACAC,SAAS;IACTC,OAAO,CAAC;IACRC,QAAQ;IACRJ,SAAS,CAAC;IACVK,WAAW,CAAC;IACZJ,QAAQ,CAAC;IACTK,SAAS;AACX,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deleteWhere.d.ts","sourceRoot":"","sources":["../../src/postgres/deleteWhere.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C,eAAO,MAAM,WAAW,EAAE,WAGzB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/postgres/deleteWhere.ts"],"sourcesContent":["import type { TransactionPg } from '../types.js'\nimport type { DeleteWhere } from './types.js'\n\nexport const deleteWhere: DeleteWhere = async function deleteWhere({ db, tableName, where }) {\n const table = this.tables[tableName]\n await (db as TransactionPg).delete(table).where(where)\n}\n"],"names":["deleteWhere","db","tableName","where","table","tables","delete"],"mappings":"AAGA,OAAO,MAAMA,cAA2B,eAAeA,YAAY,EAAEC,EAAE,EAAEC,SAAS,EAAEC,KAAK,EAAE;IACzF,MAAMC,QAAQ,IAAI,CAACC,MAAM,CAACH,UAAU;IACpC,MAAM,AAACD,GAAqBK,MAAM,CAACF,OAAOD,KAAK,CAACA;AAClD,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dropDatabase.d.ts","sourceRoot":"","sources":["../../src/postgres/dropDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE9C,eAAO,MAAM,YAAY,EAAE,YAM1B,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const dropDatabase = async function dropDatabase({ adapter }) {
|
|
2
|
+
await adapter.execute({
|
|
3
|
+
drizzle: adapter.drizzle,
|
|
4
|
+
raw: `drop schema if exists ${this.schemaName || 'public'} cascade;
|
|
5
|
+
create schema ${this.schemaName || 'public'};`
|
|
6
|
+
});
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=dropDatabase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/postgres/dropDatabase.ts"],"sourcesContent":["import type { DropDatabase } from './types.js'\n\nexport const dropDatabase: DropDatabase = async function dropDatabase({ adapter }) {\n await adapter.execute({\n drizzle: adapter.drizzle,\n raw: `drop schema if exists ${this.schemaName || 'public'} cascade;\n create schema ${this.schemaName || 'public'};`,\n })\n}\n"],"names":["dropDatabase","adapter","execute","drizzle","raw","schemaName"],"mappings":"AAEA,OAAO,MAAMA,eAA6B,eAAeA,aAAa,EAAEC,OAAO,EAAE;IAC/E,MAAMA,QAAQC,OAAO,CAAC;QACpBC,SAASF,QAAQE,OAAO;QACxBC,KAAK,CAAC,sBAAsB,EAAE,IAAI,CAACC,UAAU,IAAI,SAAS;kBAC5C,EAAE,IAAI,CAACA,UAAU,IAAI,SAAS,CAAC,CAAC;IAChD;AACF,EAAC"}
|