@payloadcms/db-postgres 3.0.0-beta.9 → 3.0.0-canary.f6e77b8
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/count.d.ts +3 -0
- package/dist/count.d.ts.map +1 -0
- package/dist/count.js +50 -0
- package/dist/count.js.map +1 -0
- package/dist/create.d.ts.map +1 -1
- package/dist/create.js +3 -5
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.d.ts.map +1 -1
- package/dist/createGlobal.js +3 -5
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +2 -6
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +9 -13
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteMany.d.ts.map +1 -1
- package/dist/deleteMany.js +2 -5
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +2 -5
- package/dist/deleteOne.js.map +1 -1
- package/dist/deleteVersions.d.ts.map +1 -1
- package/dist/deleteVersions.js +2 -6
- package/dist/deleteVersions.js.map +1 -1
- package/dist/destroy.d.ts.map +1 -1
- package/dist/destroy.js +7 -7
- package/dist/destroy.js.map +1 -1
- package/dist/find/buildFindManyArgs.js +2 -2
- package/dist/find/buildFindManyArgs.js.map +1 -1
- package/dist/find/findMany.d.ts.map +1 -1
- package/dist/find/findMany.js.map +1 -1
- package/dist/find/traverseFields.d.ts.map +1 -1
- package/dist/find/traverseFields.js +4 -20
- package/dist/find/traverseFields.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +2 -5
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +2 -5
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +2 -6
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +2 -5
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +2 -6
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +9 -7
- package/dist/init.js.map +1 -1
- package/dist/migrate.js.map +1 -1
- package/dist/migrateDown.js.map +1 -1
- package/dist/migrateFresh.js.map +1 -1
- package/dist/migrateRefresh.js.map +1 -1
- package/dist/migrateReset.js.map +1 -1
- package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
- package/dist/queries/getTableColumnFromPath.js +95 -62
- package/dist/queries/getTableColumnFromPath.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +2 -6
- package/dist/queryDrafts.js.map +1 -1
- package/dist/schema/build.d.ts +3 -2
- package/dist/schema/build.d.ts.map +1 -1
- package/dist/schema/build.js +77 -42
- package/dist/schema/build.js.map +1 -1
- package/dist/schema/{getTableName.d.ts → createTableName.d.ts} +5 -7
- package/dist/schema/createTableName.d.ts.map +1 -0
- package/dist/schema/createTableName.js +31 -0
- package/dist/schema/createTableName.js.map +1 -0
- package/dist/schema/traverseFields.d.ts.map +1 -1
- package/dist/schema/traverseFields.js +45 -24
- package/dist/schema/traverseFields.js.map +1 -1
- package/dist/schema/validateExistingBlockIsIdentical.d.ts +2 -1
- package/dist/schema/validateExistingBlockIsIdentical.d.ts.map +1 -1
- package/dist/schema/validateExistingBlockIsIdentical.js +13 -7
- package/dist/schema/validateExistingBlockIsIdentical.js.map +1 -1
- package/dist/transform/write/array.d.ts.map +1 -1
- package/dist/transform/write/array.js.map +1 -1
- package/dist/transform/write/blocks.js +1 -1
- package/dist/transform/write/blocks.js.map +1 -1
- package/dist/transform/write/traverseFields.js +2 -2
- package/dist/transform/write/traverseFields.js.map +1 -1
- package/dist/types.d.ts +4 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/update.d.ts.map +1 -1
- package/dist/update.js +2 -5
- package/dist/update.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +2 -5
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +2 -6
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +2 -6
- package/dist/updateVersion.js.map +1 -1
- package/dist/upsertRow/index.d.ts.map +1 -1
- package/dist/upsertRow/index.js +6 -5
- package/dist/upsertRow/index.js.map +1 -1
- package/dist/upsertRow/insertArrays.d.ts.map +1 -1
- package/dist/upsertRow/insertArrays.js +3 -3
- package/dist/upsertRow/insertArrays.js.map +1 -1
- package/dist/upsertRow/types.d.ts +2 -2
- package/dist/upsertRow/types.d.ts.map +1 -1
- package/dist/upsertRow/types.js.map +1 -1
- package/package.json +21 -25
- package/dist/schema/getTableName.d.ts.map +0 -1
- package/dist/schema/getTableName.js +0 -31
- package/dist/schema/getTableName.js.map +0 -1
- package/src/index.ts +0 -156
@@ -1,5 +1,5 @@
|
|
1
1
|
/* eslint-disable no-param-reassign */ import { fieldAffectsData, tabHasName } from 'payload/types';
|
2
|
-
import
|
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
|
if (field.type === 'collapsible' || field.type === 'row') {
|
@@ -46,19 +46,8 @@ export const traverseFields = ({ _locales, adapter, currentArgs, currentTableNam
|
|
46
46
|
],
|
47
47
|
with: {}
|
48
48
|
};
|
49
|
-
const arrayTableName =
|
50
|
-
|
51
|
-
config: field,
|
52
|
-
parentTableName: currentTableName,
|
53
|
-
prefix: `${currentTableName}_${path}`
|
54
|
-
});
|
55
|
-
const arrayTableNameWithLocales = getTableName({
|
56
|
-
adapter,
|
57
|
-
config: field,
|
58
|
-
locales: true,
|
59
|
-
parentTableName: currentTableName,
|
60
|
-
prefix: `${currentTableName}_${path}`
|
61
|
-
});
|
49
|
+
const arrayTableName = adapter.tableNameMap.get(`${currentTableName}_${path}${toSnakeCase(field.name)}`);
|
50
|
+
const arrayTableNameWithLocales = `${arrayTableName}${adapter.localesSuffix}`;
|
62
51
|
if (adapter.tables[arrayTableNameWithLocales]) withArray.with._locales = _locales;
|
63
52
|
currentArgs.with[`${path}${field.name}`] = withArray;
|
64
53
|
traverseFields({
|
@@ -104,12 +93,7 @@ export const traverseFields = ({ _locales, adapter, currentArgs, currentTableNam
|
|
104
93
|
],
|
105
94
|
with: {}
|
106
95
|
};
|
107
|
-
const tableName =
|
108
|
-
adapter,
|
109
|
-
config: block,
|
110
|
-
parentTableName: topLevelTableName,
|
111
|
-
prefix: `${topLevelTableName}_blocks_`
|
112
|
-
});
|
96
|
+
const tableName = adapter.tableNameMap.get(`${topLevelTableName}_blocks_${toSnakeCase(block.slug)}`);
|
113
97
|
if (adapter.tables[`${tableName}${adapter.localesSuffix}`]) {
|
114
98
|
withBlock.with._locales = _locales;
|
115
99
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/find/traverseFields.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { Field } from 'payload/types'\n\nimport { fieldAffectsData, tabHasName } from 'payload/types'\n\nimport type { PostgresAdapter } from '../types.js'\nimport type { Result } from './buildFindManyArgs.js'\n\
|
1
|
+
{"version":3,"sources":["../../src/find/traverseFields.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { Field } from 'payload/types'\n\nimport { fieldAffectsData, tabHasName } from 'payload/types'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from '../types.js'\nimport type { Result } from './buildFindManyArgs.js'\n\ntype TraverseFieldArgs = {\n _locales: Record<string, unknown>\n adapter: PostgresAdapter\n currentArgs: Record<string, unknown>\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 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]) withArray.with._locales = _locales\n currentArgs.with[`${path}${field.name}`] = withArray\n\n traverseFields({\n _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 = _locales\n }\n topLevelArgs.with[blockKey] = withBlock\n\n traverseFields({\n _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","tabs","tab","tabPath","name","withArray","columns","_parentID","orderBy","_order","asc","with","arrayTableName","tableNameMap","get","arrayTableNameWithLocales","localesSuffix","tables","hasMany","withSelect","id","order","parent","blocks","block","blockKey","slug","withBlock","tableName"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,oCAAoC,GAGpC,SAASA,gBAAgB,EAAEC,UAAU,QAAQ,gBAAe;AAC5D,OAAOC,iBAAiB,gBAAe;AAiBvC,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,QAAQ,EACRC,OAAO,EACPC,WAAW,EACXC,gBAAgB,EAChBC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,YAAY,E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ACAC,QAAQ8B,MAAM9B,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,MAAMK,IAAI,CAAC,CAAC,CAAC;wBAC7BR;wBACAC;oBACF;oBAEA;gBAEF;oBAAS;wBACP;oBACF;YACF;QACF;IACF;IAEA,OAAOD;AACT,EAAC"}
|
package/dist/find.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../src/find.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;
|
1
|
+
{"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../src/find.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAS5C,eAAO,MAAM,IAAI,EAAE,IA8BlB,CAAA"}
|
package/dist/find.js
CHANGED
@@ -1,12 +1,9 @@
|
|
1
|
+
import toSnakeCase from 'to-snake-case';
|
1
2
|
import { findMany } from './find/findMany.js';
|
2
|
-
import { getTableName } from './schema/getTableName.js';
|
3
3
|
export const find = async function find({ collection, limit, locale, page = 1, pagination, req = {}, sort: sortArg, where }) {
|
4
4
|
const collectionConfig = this.payload.collections[collection].config;
|
5
5
|
const sort = typeof sortArg === 'string' ? sortArg : collectionConfig.defaultSort;
|
6
|
-
const tableName =
|
7
|
-
adapter: this,
|
8
|
-
config: collectionConfig
|
9
|
-
});
|
6
|
+
const tableName = this.tableNameMap.get(toSnakeCase(collectionConfig.slug));
|
10
7
|
return findMany({
|
11
8
|
adapter: this,
|
12
9
|
fields: collectionConfig.fields,
|
package/dist/find.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/find.ts"],"sourcesContent":["import type { Find } from 'payload/database'\nimport type {
|
1
|
+
{"version":3,"sources":["../src/find.ts"],"sourcesContent":["import type { Find } from 'payload/database'\nimport type { PayloadRequestWithData, SanitizedCollectionConfig } from 'payload/types'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport const find: Find = async function find(\n this: PostgresAdapter,\n {\n collection,\n limit,\n locale,\n page = 1,\n pagination,\n req = {} as PayloadRequestWithData,\n sort: sortArg,\n where,\n },\n) {\n const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config\n const sort = typeof sortArg === 'string' ? sortArg : collectionConfig.defaultSort\n\n const tableName = this.tableNameMap.get(toSnakeCase(collectionConfig.slug))\n\n return findMany({\n adapter: this,\n fields: collectionConfig.fields,\n limit,\n locale,\n page,\n pagination,\n req,\n sort,\n tableName,\n where,\n })\n}\n"],"names":["toSnakeCase","findMany","find","collection","limit","locale","page","pagination","req","sort","sortArg","where","collectionConfig","payload","collections","config","defaultSort","tableName","tableNameMap","get","slug","adapter","fields"],"rangeMappings":";;;;;;;;;;;;;;;;;;","mappings":"AAGA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,OAAO,MAAMC,OAAa,eAAeA,KAEvC,EACEC,UAAU,EACVC,KAAK,EACLC,MAAM,EACNC,OAAO,CAAC,EACRC,UAAU,EACVC,MAAM,CAAC,CAA2B,EAClCC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,mBAA8C,IAAI,CAACC,OAAO,CAACC,WAAW,CAACX,WAAW,CAACY,MAAM;IAC/F,MAAMN,OAAO,OAAOC,YAAY,WAAWA,UAAUE,iBAAiBI,WAAW;IAEjF,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAACnB,YAAYY,iBAAiBQ,IAAI;IAEzE,OAAOnB,SAAS;QACdoB,SAAS,IAAI;QACbC,QAAQV,iBAAiBU,MAAM;QAC/BlB;QACAC;QACAC;QACAC;QACAC;QACAC;QACAQ;QACAN;IACF;AACF,EAAC"}
|
package/dist/findGlobal.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"findGlobal.d.ts","sourceRoot":"","sources":["../src/findGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;
|
1
|
+
{"version":3,"file":"findGlobal.d.ts","sourceRoot":"","sources":["../src/findGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAQlD,eAAO,MAAM,UAAU,EAAE,UA2BxB,CAAA"}
|
package/dist/findGlobal.js
CHANGED
@@ -1,11 +1,8 @@
|
|
1
|
+
import toSnakeCase from 'to-snake-case';
|
1
2
|
import { findMany } from './find/findMany.js';
|
2
|
-
import { getTableName } from './schema/getTableName.js';
|
3
3
|
export const findGlobal = async function findGlobal({ slug, locale, req, where }) {
|
4
4
|
const globalConfig = this.payload.globals.config.find((config)=>config.slug === slug);
|
5
|
-
const tableName =
|
6
|
-
adapter: this,
|
7
|
-
config: globalConfig
|
8
|
-
});
|
5
|
+
const tableName = this.tableNameMap.get(toSnakeCase(globalConfig.slug));
|
9
6
|
const { docs: [doc] } = await findMany({
|
10
7
|
adapter: this,
|
11
8
|
fields: globalConfig.fields,
|
package/dist/findGlobal.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/findGlobal.ts"],"sourcesContent":["import type { FindGlobal } from 'payload/database'\n\nimport
|
1
|
+
{"version":3,"sources":["../src/findGlobal.ts"],"sourcesContent":["import type { FindGlobal } from 'payload/database'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport const findGlobal: FindGlobal = async function findGlobal(\n this: PostgresAdapter,\n { slug, locale, req, where },\n) {\n const globalConfig = this.payload.globals.config.find((config) => config.slug === slug)\n\n const tableName = this.tableNameMap.get(toSnakeCase(globalConfig.slug))\n\n const {\n docs: [doc],\n } = await findMany({\n adapter: this,\n fields: globalConfig.fields,\n limit: 1,\n locale,\n pagination: false,\n req,\n tableName,\n where,\n })\n\n if (doc) {\n doc.globalType = slug\n return doc\n }\n\n return {}\n}\n"],"names":["toSnakeCase","findMany","findGlobal","slug","locale","req","where","globalConfig","payload","globals","config","find","tableName","tableNameMap","get","docs","doc","adapter","fields","limit","pagination","globalType"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,IAAI,EAAEC,MAAM,EAAEC,GAAG,EAAEC,KAAK,EAAE;IAE5B,MAAMC,eAAe,IAAI,CAACC,OAAO,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAACD,SAAWA,OAAOP,IAAI,KAAKA;IAElF,MAAMS,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAACd,YAAYO,aAAaJ,IAAI;IAErE,MAAM,EACJY,MAAM,CAACC,IAAI,EACZ,GAAG,MAAMf,SAAS;QACjBgB,SAAS,IAAI;QACbC,QAAQX,aAAaW,MAAM;QAC3BC,OAAO;QACPf;QACAgB,YAAY;QACZf;QACAO;QACAN;IACF;IAEA,IAAIU,KAAK;QACPA,IAAIK,UAAU,GAAGlB;QACjB,OAAOa;IACT;IAEA,OAAO,CAAC;AACV,EAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"findGlobalVersions.d.ts","sourceRoot":"","sources":["../src/findGlobalVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAU1D,eAAO,MAAM,kBAAkB,EAAE,
|
1
|
+
{"version":3,"file":"findGlobalVersions.d.ts","sourceRoot":"","sources":["../src/findGlobalVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAU1D,eAAO,MAAM,kBAAkB,EAAE,kBAsChC,CAAA"}
|
@@ -1,14 +1,10 @@
|
|
1
1
|
import { buildVersionGlobalFields } from 'payload/versions';
|
2
|
+
import toSnakeCase from 'to-snake-case';
|
2
3
|
import { findMany } from './find/findMany.js';
|
3
|
-
import { getTableName } from './schema/getTableName.js';
|
4
4
|
export const findGlobalVersions = async function findGlobalVersions({ global, limit, locale, page, pagination, req = {}, skip, sort: sortArg, where }) {
|
5
5
|
const globalConfig = this.payload.globals.config.find(({ slug })=>slug === global);
|
6
6
|
const sort = typeof sortArg === 'string' ? sortArg : '-createdAt';
|
7
|
-
const tableName =
|
8
|
-
adapter: this,
|
9
|
-
config: globalConfig,
|
10
|
-
versions: true
|
11
|
-
});
|
7
|
+
const tableName = this.tableNameMap.get(`_${toSnakeCase(globalConfig.slug)}${this.versionsSuffix}`);
|
12
8
|
const fields = buildVersionGlobalFields(globalConfig);
|
13
9
|
return findMany({
|
14
10
|
adapter: this,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/findGlobalVersions.ts"],"sourcesContent":["import type { FindGlobalVersions } from 'payload/database'\nimport type {
|
1
|
+
{"version":3,"sources":["../src/findGlobalVersions.ts"],"sourcesContent":["import type { FindGlobalVersions } from 'payload/database'\nimport type { PayloadRequestWithData, SanitizedGlobalConfig } from 'payload/types'\n\nimport { buildVersionGlobalFields } from 'payload/versions'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport const findGlobalVersions: FindGlobalVersions = async function findGlobalVersions(\n this: PostgresAdapter,\n {\n global,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequestWithData,\n skip,\n sort: sortArg,\n where,\n },\n) {\n const globalConfig: SanitizedGlobalConfig = this.payload.globals.config.find(\n ({ slug }) => slug === global,\n )\n const sort = typeof sortArg === 'string' ? sortArg : '-createdAt'\n\n const tableName = this.tableNameMap.get(\n `_${toSnakeCase(globalConfig.slug)}${this.versionsSuffix}`,\n )\n\n const fields = buildVersionGlobalFields(globalConfig)\n\n return findMany({\n adapter: this,\n fields,\n limit,\n locale,\n page,\n pagination,\n req,\n skip,\n sort,\n tableName,\n where,\n })\n}\n"],"names":["buildVersionGlobalFields","toSnakeCase","findMany","findGlobalVersions","global","limit","locale","page","pagination","req","skip","sort","sortArg","where","globalConfig","payload","globals","config","find","slug","tableName","tableNameMap","get","versionsSuffix","fields","adapter"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,wBAAwB,QAAQ,mBAAkB;AAC3D,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,OAAO,MAAMC,qBAAyC,eAAeA,mBAEnE,EACEC,MAAM,EACNC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,MAAM,CAAC,CAA2B,EAClCC,IAAI,EACJC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,eAAsC,IAAI,CAACC,OAAO,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAC1E,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASf;IAEzB,MAAMO,OAAO,OAAOC,YAAY,WAAWA,UAAU;IAErD,MAAMQ,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CACrC,CAAC,CAAC,EAAErB,YAAYa,aAAaK,IAAI,EAAE,EAAE,IAAI,CAACI,cAAc,CAAC,CAAC;IAG5D,MAAMC,SAASxB,yBAAyBc;IAExC,OAAOZ,SAAS;QACduB,SAAS,IAAI;QACbD;QACAnB;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAS;QACAP;IACF;AACF,EAAC"}
|
package/dist/findOne.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../src/findOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,KAAK,
|
1
|
+
{"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../src/findOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,KAAK,EAAqD,UAAU,EAAE,MAAM,eAAe,CAAA;AAIlG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAIjD,wBAAsB,OAAO,CAAC,CAAC,SAAS,UAAU,EAChD,IAAI,EAAE,eAAe,EACrB,EAAE,UAAU,EAAE,MAAM,EAAE,GAAkC,EAAE,KAAK,EAAE,EAAE,WAAW,GAC7E,OAAO,CAAC,CAAC,CAAC,CAmBZ"}
|
package/dist/findOne.js
CHANGED
@@ -1,11 +1,8 @@
|
|
1
|
+
import toSnakeCase from 'to-snake-case';
|
1
2
|
import { findMany } from './find/findMany.js';
|
2
|
-
import { getTableName } from './schema/getTableName.js';
|
3
3
|
export async function findOne({ collection, locale, req = {}, where }) {
|
4
4
|
const collectionConfig = this.payload.collections[collection].config;
|
5
|
-
const tableName =
|
6
|
-
adapter: this,
|
7
|
-
config: collectionConfig
|
8
|
-
});
|
5
|
+
const tableName = this.tableNameMap.get(toSnakeCase(collectionConfig.slug));
|
9
6
|
const { docs } = await findMany({
|
10
7
|
adapter: this,
|
11
8
|
fields: collectionConfig.fields,
|
package/dist/findOne.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/findOne.ts"],"sourcesContent":["import type { FindOneArgs } from 'payload/database'\nimport type {
|
1
|
+
{"version":3,"sources":["../src/findOne.ts"],"sourcesContent":["import type { FindOneArgs } from 'payload/database'\nimport type { PayloadRequestWithData, SanitizedCollectionConfig, TypeWithID } from 'payload/types'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport async function findOne<T extends TypeWithID>(\n this: PostgresAdapter,\n { collection, locale, req = {} as PayloadRequestWithData, where }: FindOneArgs,\n): Promise<T> {\n const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config\n\n const tableName = this.tableNameMap.get(toSnakeCase(collectionConfig.slug))\n\n const { docs } = await findMany({\n adapter: this,\n fields: collectionConfig.fields,\n limit: 1,\n locale,\n page: 1,\n pagination: false,\n req,\n sort: undefined,\n tableName,\n where,\n })\n\n return docs?.[0] || null\n}\n"],"names":["toSnakeCase","findMany","findOne","collection","locale","req","where","collectionConfig","payload","collections","config","tableName","tableNameMap","get","slug","docs","adapter","fields","limit","page","pagination","sort","undefined"],"rangeMappings":";;;;;;;;;;;;;;;;;;","mappings":"AAGA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,OAAO,eAAeC,QAEpB,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAA2B,EAAEC,KAAK,EAAe;IAE9E,MAAMC,mBAA8C,IAAI,CAACC,OAAO,CAACC,WAAW,CAACN,WAAW,CAACO,MAAM;IAE/F,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAACb,YAAYO,iBAAiBO,IAAI;IAEzE,MAAM,EAAEC,IAAI,EAAE,GAAG,MAAMd,SAAS;QAC9Be,SAAS,IAAI;QACbC,QAAQV,iBAAiBU,MAAM;QAC/BC,OAAO;QACPd;QACAe,MAAM;QACNC,YAAY;QACZf;QACAgB,MAAMC;QACNX;QACAL;IACF;IAEA,OAAOS,MAAM,CAAC,EAAE,IAAI;AACtB"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../src/findVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAUpD,eAAO,MAAM,YAAY,EAAE,
|
1
|
+
{"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../src/findVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAUpD,eAAO,MAAM,YAAY,EAAE,YAoC1B,CAAA"}
|
package/dist/findVersions.js
CHANGED
@@ -1,14 +1,10 @@
|
|
1
1
|
import { buildVersionCollectionFields } from 'payload/versions';
|
2
|
+
import toSnakeCase from 'to-snake-case';
|
2
3
|
import { findMany } from './find/findMany.js';
|
3
|
-
import { getTableName } from './schema/getTableName.js';
|
4
4
|
export const findVersions = async function findVersions({ collection, limit, locale, page, pagination, req = {}, skip, sort: sortArg, where }) {
|
5
5
|
const collectionConfig = this.payload.collections[collection].config;
|
6
6
|
const sort = typeof sortArg === 'string' ? sortArg : collectionConfig.defaultSort;
|
7
|
-
const tableName =
|
8
|
-
adapter: this,
|
9
|
-
config: collectionConfig,
|
10
|
-
versions: true
|
11
|
-
});
|
7
|
+
const tableName = this.tableNameMap.get(`_${toSnakeCase(collectionConfig.slug)}${this.versionsSuffix}`);
|
12
8
|
const fields = buildVersionCollectionFields(collectionConfig);
|
13
9
|
return findMany({
|
14
10
|
adapter: this,
|
package/dist/findVersions.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/findVersions.ts"],"sourcesContent":["import type { FindVersions } from 'payload/database'\nimport type {
|
1
|
+
{"version":3,"sources":["../src/findVersions.ts"],"sourcesContent":["import type { FindVersions } from 'payload/database'\nimport type { PayloadRequestWithData, SanitizedCollectionConfig } from 'payload/types'\n\nimport { buildVersionCollectionFields } from 'payload/versions'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport const findVersions: FindVersions = async function findVersions(\n this: PostgresAdapter,\n {\n collection,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequestWithData,\n skip,\n sort: sortArg,\n where,\n },\n) {\n const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config\n const sort = typeof sortArg === 'string' ? sortArg : collectionConfig.defaultSort\n\n const tableName = this.tableNameMap.get(\n `_${toSnakeCase(collectionConfig.slug)}${this.versionsSuffix}`,\n )\n\n const fields = buildVersionCollectionFields(collectionConfig)\n\n return findMany({\n adapter: this,\n fields,\n limit,\n locale,\n page,\n pagination,\n req,\n skip,\n sort,\n tableName,\n where,\n })\n}\n"],"names":["buildVersionCollectionFields","toSnakeCase","findMany","findVersions","collection","limit","locale","page","pagination","req","skip","sort","sortArg","where","collectionConfig","payload","collections","config","defaultSort","tableName","tableNameMap","get","slug","versionsSuffix","fields","adapter"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,4BAA4B,QAAQ,mBAAkB;AAC/D,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EACEC,UAAU,EACVC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,MAAM,CAAC,CAA2B,EAClCC,IAAI,EACJC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,mBAA8C,IAAI,CAACC,OAAO,CAACC,WAAW,CAACZ,WAAW,CAACa,MAAM;IAC/F,MAAMN,OAAO,OAAOC,YAAY,WAAWA,UAAUE,iBAAiBI,WAAW;IAEjF,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CACrC,CAAC,CAAC,EAAEpB,YAAYa,iBAAiBQ,IAAI,EAAE,EAAE,IAAI,CAACC,cAAc,CAAC,CAAC;IAGhE,MAAMC,SAASxB,6BAA6Bc;IAE5C,OAAOZ,SAAS;QACduB,SAAS,IAAI;QACbD;QACAnB;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAQ;QACAN;IACF;AACF,EAAC"}
|
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAM1D,OAAO,KAAK,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAM1D,OAAO,KAAK,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAkCvD,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAEhE,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAEjC,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,kBAAkB,CAAC,eAAe,CAAC,CAsE/E"}
|
package/dist/index.js
CHANGED
@@ -2,6 +2,7 @@ import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
3
3
|
import { createDatabaseAdapter } from 'payload/database';
|
4
4
|
import { connect } from './connect.js';
|
5
|
+
import { count } from './count.js';
|
5
6
|
import { create } from './create.js';
|
6
7
|
import { createGlobal } from './createGlobal.js';
|
7
8
|
import { createGlobalVersion } from './createGlobalVersion.js';
|
@@ -33,17 +34,16 @@ import { updateGlobalVersion } from './updateGlobalVersion.js';
|
|
33
34
|
import { updateVersion } from './updateVersion.js';
|
34
35
|
export { sql } from 'drizzle-orm';
|
35
36
|
export function postgresAdapter(args) {
|
37
|
+
const postgresIDType = args.idType || 'serial';
|
38
|
+
const payloadIDType = postgresIDType === 'serial' ? 'number' : 'text';
|
36
39
|
function adapter({ payload }) {
|
37
40
|
const migrationDir = findMigrationDir(args.migrationDir);
|
38
|
-
const idType = args.idType || 'serial';
|
39
41
|
return createDatabaseAdapter({
|
40
42
|
name: 'postgres',
|
41
|
-
// Postgres-specific
|
42
|
-
blockTableNames: {},
|
43
43
|
drizzle: undefined,
|
44
44
|
enums: {},
|
45
45
|
fieldConstraints: {},
|
46
|
-
idType,
|
46
|
+
idType: postgresIDType,
|
47
47
|
localesSuffix: args.localesSuffix || '_locales',
|
48
48
|
logger: args.logger,
|
49
49
|
pgSchema: undefined,
|
@@ -55,20 +55,20 @@ export function postgresAdapter(args) {
|
|
55
55
|
schema: {},
|
56
56
|
schemaName: args.schemaName,
|
57
57
|
sessions: {},
|
58
|
+
tableNameMap: new Map(),
|
58
59
|
tables: {},
|
59
60
|
versionsSuffix: args.versionsSuffix || '_v',
|
60
61
|
// DatabaseAdapter
|
61
62
|
beginTransaction,
|
62
63
|
commitTransaction,
|
63
64
|
connect,
|
65
|
+
count,
|
64
66
|
create,
|
65
67
|
createGlobal,
|
66
68
|
createGlobalVersion,
|
67
69
|
createMigration,
|
68
70
|
createVersion,
|
69
|
-
|
70
|
-
* This represents how a default ID is treated in Payload as were a field type
|
71
|
-
*/ defaultIDType: idType === 'serial' ? 'number' : 'text',
|
71
|
+
defaultIDType: payloadIDType,
|
72
72
|
deleteMany,
|
73
73
|
deleteOne,
|
74
74
|
deleteVersions,
|
@@ -96,7 +96,7 @@ export function postgresAdapter(args) {
|
|
96
96
|
});
|
97
97
|
}
|
98
98
|
return {
|
99
|
-
defaultIDType:
|
99
|
+
defaultIDType: payloadIDType,
|
100
100
|
init: adapter
|
101
101
|
};
|
102
102
|
}
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Payload } from 'payload'\nimport type { DatabaseAdapterObj } from 'payload/database'\n\nimport fs from 'fs'\nimport path from 'path'\nimport { createDatabaseAdapter } from 'payload/database'\n\nimport type { Args, PostgresAdapter } from './types.js'\n\nimport { connect } from './connect.js'\nimport { create } from './create.js'\nimport { createGlobal } from './createGlobal.js'\nimport { createGlobalVersion } from './createGlobalVersion.js'\nimport { createMigration } from './createMigration.js'\nimport { createVersion } from './createVersion.js'\nimport { deleteMany } from './deleteMany.js'\nimport { deleteOne } from './deleteOne.js'\nimport { deleteVersions } from './deleteVersions.js'\nimport { destroy } from './destroy.js'\nimport { find } from './find.js'\nimport { findGlobal } from './findGlobal.js'\nimport { findGlobalVersions } from './findGlobalVersions.js'\nimport { findOne } from './findOne.js'\nimport { findVersions } from './findVersions.js'\nimport { init } from './init.js'\nimport { migrate } from './migrate.js'\nimport { migrateDown } from './migrateDown.js'\nimport { migrateFresh } from './migrateFresh.js'\nimport { migrateRefresh } from './migrateRefresh.js'\nimport { migrateReset } from './migrateReset.js'\nimport { migrateStatus } from './migrateStatus.js'\nimport { queryDrafts } from './queryDrafts.js'\nimport { beginTransaction } from './transactions/beginTransaction.js'\nimport { commitTransaction } from './transactions/commitTransaction.js'\nimport { rollbackTransaction } from './transactions/rollbackTransaction.js'\nimport { updateOne } from './update.js'\nimport { updateGlobal } from './updateGlobal.js'\nimport { updateGlobalVersion } from './updateGlobalVersion.js'\nimport { updateVersion } from './updateVersion.js'\n\nexport type { MigrateDownArgs, MigrateUpArgs } from './types.js'\n\nexport { sql } from 'drizzle-orm'\n\nexport function postgresAdapter(args: Args): DatabaseAdapterObj<PostgresAdapter> {\n function adapter({ payload }: { payload: Payload }) {\n const migrationDir = findMigrationDir(args.migrationDir)\n
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Payload } from 'payload'\nimport type { DatabaseAdapterObj } from 'payload/database'\n\nimport fs from 'fs'\nimport path from 'path'\nimport { createDatabaseAdapter } from 'payload/database'\n\nimport type { Args, PostgresAdapter } from './types.js'\n\nimport { connect } from './connect.js'\nimport { count } from './count.js'\nimport { create } from './create.js'\nimport { createGlobal } from './createGlobal.js'\nimport { createGlobalVersion } from './createGlobalVersion.js'\nimport { createMigration } from './createMigration.js'\nimport { createVersion } from './createVersion.js'\nimport { deleteMany } from './deleteMany.js'\nimport { deleteOne } from './deleteOne.js'\nimport { deleteVersions } from './deleteVersions.js'\nimport { destroy } from './destroy.js'\nimport { find } from './find.js'\nimport { findGlobal } from './findGlobal.js'\nimport { findGlobalVersions } from './findGlobalVersions.js'\nimport { findOne } from './findOne.js'\nimport { findVersions } from './findVersions.js'\nimport { init } from './init.js'\nimport { migrate } from './migrate.js'\nimport { migrateDown } from './migrateDown.js'\nimport { migrateFresh } from './migrateFresh.js'\nimport { migrateRefresh } from './migrateRefresh.js'\nimport { migrateReset } from './migrateReset.js'\nimport { migrateStatus } from './migrateStatus.js'\nimport { queryDrafts } from './queryDrafts.js'\nimport { beginTransaction } from './transactions/beginTransaction.js'\nimport { commitTransaction } from './transactions/commitTransaction.js'\nimport { rollbackTransaction } from './transactions/rollbackTransaction.js'\nimport { updateOne } from './update.js'\nimport { updateGlobal } from './updateGlobal.js'\nimport { updateGlobalVersion } from './updateGlobalVersion.js'\nimport { updateVersion } from './updateVersion.js'\n\nexport type { MigrateDownArgs, MigrateUpArgs } from './types.js'\n\nexport { sql } from 'drizzle-orm'\n\nexport function postgresAdapter(args: Args): DatabaseAdapterObj<PostgresAdapter> {\n const postgresIDType = args.idType || 'serial'\n const payloadIDType = postgresIDType === 'serial' ? 'number' : 'text'\n\n function adapter({ payload }: { payload: Payload }) {\n const migrationDir = findMigrationDir(args.migrationDir)\n\n return createDatabaseAdapter<PostgresAdapter>({\n name: 'postgres',\n drizzle: undefined,\n enums: {},\n fieldConstraints: {},\n idType: postgresIDType,\n localesSuffix: args.localesSuffix || '_locales',\n logger: args.logger,\n pgSchema: undefined,\n pool: undefined,\n poolOptions: args.pool,\n push: args.push,\n relations: {},\n relationshipsSuffix: args.relationshipsSuffix || '_rels',\n schema: {},\n schemaName: args.schemaName,\n sessions: {},\n tableNameMap: new Map<string, string>(),\n tables: {},\n versionsSuffix: args.versionsSuffix || '_v',\n\n // DatabaseAdapter\n beginTransaction,\n commitTransaction,\n connect,\n count,\n create,\n createGlobal,\n createGlobalVersion,\n createMigration,\n createVersion,\n defaultIDType: payloadIDType,\n deleteMany,\n deleteOne,\n deleteVersions,\n destroy,\n find,\n findGlobal,\n findGlobalVersions,\n findOne,\n findVersions,\n init,\n migrate,\n migrateDown,\n migrateFresh,\n migrateRefresh,\n migrateReset,\n migrateStatus,\n migrationDir,\n payload,\n queryDrafts,\n rollbackTransaction,\n updateGlobal,\n updateGlobalVersion,\n updateOne,\n updateVersion,\n })\n }\n\n return {\n defaultIDType: payloadIDType,\n init: adapter,\n }\n}\n\n/**\n * Attempt to find migrations directory.\n *\n * Checks for the following directories in order:\n * - `migrationDir` argument from Payload config\n * - `src/migrations`\n * - `dist/migrations`\n * - `migrations`\n *\n * Defaults to `src/migrations`\n *\n * @param migrationDir\n * @returns\n */\nfunction findMigrationDir(migrationDir?: string): string {\n const cwd = process.cwd()\n const srcDir = path.resolve(cwd, 'src/migrations')\n const distDir = path.resolve(cwd, 'dist/migrations')\n const relativeMigrations = path.resolve(cwd, 'migrations')\n\n // Use arg if provided\n if (migrationDir) return migrationDir\n\n // Check other common locations\n if (fs.existsSync(srcDir)) {\n return srcDir\n }\n\n if (fs.existsSync(distDir)) {\n return distDir\n }\n\n if (fs.existsSync(relativeMigrations)) {\n return relativeMigrations\n }\n\n return srcDir\n}\n"],"names":["fs","path","createDatabaseAdapter","connect","count","create","createGlobal","createGlobalVersion","createMigration","createVersion","deleteMany","deleteOne","deleteVersions","destroy","find","findGlobal","findGlobalVersions","findOne","findVersions","init","migrate","migrateDown","migrateFresh","migrateRefresh","migrateReset","migrateStatus","queryDrafts","beginTransaction","commitTransaction","rollbackTransaction","updateOne","updateGlobal","updateGlobalVersion","updateVersion","sql","postgresAdapter","args","postgresIDType","idType","payloadIDType","adapter","payload","migrationDir","findMigrationDir","name","drizzle","undefined","enums","fieldConstraints","localesSuffix","logger","pgSchema","pool","poolOptions","push","relations","relationshipsSuffix","schema","schemaName","sessions","tableNameMap","Map","tables","versionsSuffix","defaultIDType","cwd","process","srcDir","resolve","distDir","relativeMigrations","existsS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AAKmE,OAAO,CAACH,KAAK;IAClC,MAAMK,qBAAqBrE,KAAKmE,OAAO,CAACH,KAAK;IAE7C,sBAAsB;IACtB,IAAIvB,cAAc,OAAOA;IAEzB,+BAA+B;IAC/B,IAAI1C,GAAGuE,UAAU,CAACJ,SAAS;QACzB,OAAOA;IACT;IAEA,IAAInE,GAAGuE,UAAU,CAACF,UAAU;QAC1B,OAAOA;IACT;IAEA,IAAIrE,GAAGuE,UAAU,CAACD,qBAAqB;QACrC,OAAOA;IACT;IAEA,OAAOH;AACT"}
|
package/dist/init.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAW5C,eAAO,MAAM,IAAI,EAAE,
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAW5C,eAAO,MAAM,IAAI,EAAE,IAgGlB,CAAA"}
|
package/dist/init.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/* eslint-disable no-param-reassign */ import { pgEnum, pgSchema, pgTable } from 'drizzle-orm/pg-core';
|
2
2
|
import { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload/versions';
|
3
3
|
import { buildTable } from './schema/build.js';
|
4
|
-
import {
|
4
|
+
import { createTableName } from './schema/createTableName.js';
|
5
5
|
export const init = function init() {
|
6
6
|
if (this.schemaName) {
|
7
7
|
this.pgSchema = pgSchema(this.schemaName);
|
@@ -14,7 +14,7 @@ export const init = function init() {
|
|
14
14
|
this.enums.enum__locales = pgEnum('_locales', this.payload.config.localization.locales.map(({ code })=>code));
|
15
15
|
}
|
16
16
|
this.payload.config.collections.forEach((collection)=>{
|
17
|
-
const tableName =
|
17
|
+
const tableName = createTableName({
|
18
18
|
adapter: this,
|
19
19
|
config: collection
|
20
20
|
});
|
@@ -31,10 +31,11 @@ export const init = function init() {
|
|
31
31
|
versions: false
|
32
32
|
});
|
33
33
|
if (collection.versions) {
|
34
|
-
const versionsTableName =
|
34
|
+
const versionsTableName = createTableName({
|
35
35
|
adapter: this,
|
36
36
|
config: collection,
|
37
|
-
versions: true
|
37
|
+
versions: true,
|
38
|
+
versionsCustomName: true
|
38
39
|
});
|
39
40
|
const versionFields = buildVersionCollectionFields(collection);
|
40
41
|
buildTable({
|
@@ -52,7 +53,7 @@ export const init = function init() {
|
|
52
53
|
}
|
53
54
|
});
|
54
55
|
this.payload.config.globals.forEach((global)=>{
|
55
|
-
const tableName =
|
56
|
+
const tableName = createTableName({
|
56
57
|
adapter: this,
|
57
58
|
config: global
|
58
59
|
});
|
@@ -69,10 +70,11 @@ export const init = function init() {
|
|
69
70
|
versions: false
|
70
71
|
});
|
71
72
|
if (global.versions) {
|
72
|
-
const versionsTableName =
|
73
|
+
const versionsTableName = createTableName({
|
73
74
|
adapter: this,
|
74
75
|
config: global,
|
75
|
-
versions: true
|
76
|
+
versions: true,
|
77
|
+
versionsCustomName: true
|
76
78
|
});
|
77
79
|
const versionFields = buildVersionGlobalFields(global);
|
78
80
|
buildTable({
|
package/dist/init.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/init.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { Init } from 'payload/database'\nimport type { SanitizedCollectionConfig } from 'payload/types'\n\nimport { pgEnum, pgSchema, pgTable } from 'drizzle-orm/pg-core'\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload/versions'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { buildTable } from './schema/build.js'\nimport {
|
1
|
+
{"version":3,"sources":["../src/init.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { Init } from 'payload/database'\nimport type { SanitizedCollectionConfig } from 'payload/types'\n\nimport { pgEnum, pgSchema, pgTable } from 'drizzle-orm/pg-core'\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload/versions'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { buildTable } from './schema/build.js'\nimport { createTableName } from './schema/createTableName.js'\n\nexport const init: Init = function init(this: PostgresAdapter) {\n if (this.schemaName) {\n this.pgSchema = pgSchema(this.schemaName)\n } else {\n this.pgSchema = { table: pgTable }\n }\n\n if (this.payload.config.localization) {\n this.enums.enum__locales = pgEnum(\n '_locales',\n this.payload.config.localization.locales.map(({ code }) => code) as [string, ...string[]],\n )\n }\n\n this.payload.config.collections.forEach((collection: SanitizedCollectionConfig) => {\n const tableName = createTableName({\n adapter: this,\n config: collection,\n })\n\n buildTable({\n adapter: this,\n buildNumbers: true,\n buildRelationships: true,\n buildTexts: true,\n disableNotNull: !!collection?.versions?.drafts,\n disableUnique: false,\n fields: collection.fields,\n tableName,\n timestamps: collection.timestamps,\n versions: false,\n })\n\n if (collection.versions) {\n const versionsTableName = createTableName({\n adapter: this,\n config: collection,\n versions: true,\n versionsCustomName: true,\n })\n const versionFields = buildVersionCollectionFields(collection)\n\n buildTable({\n adapter: this,\n buildNumbers: true,\n buildRelationships: true,\n buildTexts: true,\n disableNotNull: !!collection.versions?.drafts,\n disableUnique: true,\n fields: versionFields,\n tableName: versionsTableName,\n timestamps: true,\n versions: true,\n })\n }\n })\n\n this.payload.config.globals.forEach((global) => {\n const tableName = createTableName({ adapter: this, config: global })\n\n buildTable({\n adapter: this,\n buildNumbers: true,\n buildRelationships: true,\n buildTexts: true,\n disableNotNull: !!global?.versions?.drafts,\n disableUnique: false,\n fields: global.fields,\n tableName,\n timestamps: false,\n versions: false,\n })\n\n if (global.versions) {\n const versionsTableName = createTableName({\n adapter: this,\n config: global,\n versions: true,\n versionsCustomName: true,\n })\n const versionFields = buildVersionGlobalFields(global)\n\n buildTable({\n adapter: this,\n buildNumbers: true,\n buildRelationships: true,\n buildTexts: true,\n disableNotNull: !!global.versions?.drafts,\n disableUnique: true,\n fields: versionFields,\n tableName: versionsTableName,\n timestamps: true,\n versions: true,\n })\n }\n })\n}\n"],"names":["pgEnum","pgSchema","pgTable","buildVersionCollectionFields","buildVersionGlobalFields","buildTable","createTableName","init","schemaName","table","payload","config","localization","enums","enum__locales","locales","map","code","collections","forEach","collection","tableName","adapter","buildNumbers","buildRelationships","buildTexts","disableNotNull","versions","drafts","disableUnique","fields","timestamps","versionsTableName","versionsCustomName","versionFields","globals","global"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,oCAAoC,GAIpC,SAASA,MAAM,EAAEC,QAAQ,EAAEC,OAAO,QAAQ,sBAAqB;AAC/D,SAASC,4BAA4B,EAAEC,wBAAwB,QAAQ,mBAAkB;AAIzF,SAASC,UAAU,QAAQ,oBAAmB;AAC9C,SAASC,eAAe,QAAQ,8BAA6B;AAE7D,OAAO,MAAMC,OAAa,SAASA;IACjC,IAAI,IAAI,CAACC,UAAU,EAAE;QACnB,IAAI,CAACP,QAAQ,GAAGA,SAAS,IAAI,CAACO,UAAU;IAC1C,OAAO;QACL,IAAI,CAACP,QAAQ,GAAG;YAAEQ,OAAOP;QAAQ;IACnC;IAEA,IAAI,IAAI,CAACQ,OAAO,CAACC,MAAM,CAACC,YAAY,EAAE;QACpC,IAAI,CAACC,KAAK,CAACC,aAAa,GAAGd,OACzB,YACA,IAAI,CAACU,OAAO,CAACC,MAAM,CAACC,YAAY,CAACG,OAAO,CAACC,GAAG,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA;IAE/D;IAEA,IAAI,CAACP,OAAO,CAACC,MAAM,CAACO,WAAW,CAACC,OAAO,CAAC,CAACC;QACvC,MAAMC,YAAYf,gBAAgB;YAChCgB,SAAS,IAAI;YACbX,QAAQS;QACV;QAEAf,WAAW;YACTiB,SAAS,IAAI;YACbC,cAAc;YACdC,oB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AY;gBACZJ,UAAU;YACZ;QACF;IACF;AACF,EAAC"}
|
package/dist/migrate.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/migrate.ts"],"sourcesContent":["/* eslint-disable no-restricted-syntax, no-await-in-loop */\nimport type { Payload } from 'payload'\nimport type { Migration } from 'payload/database'\nimport type {
|
1
|
+
{"version":3,"sources":["../src/migrate.ts"],"sourcesContent":["/* eslint-disable no-restricted-syntax, no-await-in-loop */\nimport type { Payload } from 'payload'\nimport type { Migration } from 'payload/database'\nimport type { PayloadRequestWithData } from 'payload/types'\n\nimport { createRequire } from 'module'\nimport {\n commitTransaction,\n initTransaction,\n killTransaction,\n readMigrationFiles,\n} from 'payload/database'\nimport prompts from 'prompts'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { createMigrationTable } from './utilities/createMigrationTable.js'\nimport { migrationTableExists } from './utilities/migrationTableExists.js'\nimport { parseError } from './utilities/parseError.js'\n\nconst require = createRequire(import.meta.url)\n\nexport async function migrate(this: PostgresAdapter): Promise<void> {\n const { payload } = this\n const migrationFiles = 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.drizzle)\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 } else {\n await createMigrationTable(this)\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 // eslint-disable-line no-continue\n }\n\n await runMigrationFile(payload, migration, newBatch)\n }\n}\n\nasync function runMigrationFile(payload: Payload, migration: Migration, batch: number) {\n const { generateDrizzleJson } = require('drizzle-kit/payload')\n\n const start = Date.now()\n const req = { payload } as PayloadRequestWithData\n\n payload.logger.info({ msg: `Migrating: ${migration.name}` })\n\n const pgAdapter = payload.db\n const drizzleJSON = generateDrizzleJson(pgAdapter.schema)\n\n try {\n await initTransaction(req)\n await migration.up({ 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 schema: drizzleJSON,\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":["createRequire","commitTransaction","initTransaction","killTransaction","readMigrationFiles","prompts","createMigrationTable","migrationTableExists","parseError","require","url","migrate","payload","migrationFiles","length","logger","info","msg","latestBatch","migrationsInDB","hasMigrationTable","drizzle","docs","find","collection","limit","sort","Number","batch","m","confirm","runMigrations","name","type","initial","message","onCancel","process","exit","newBatch","migration","alreadyRan","existing","runMigrationFile","generateDrizzleJson","start","Date","now","req","pgAdapter","db","drizzleJSON","schema","up","create","data","err","error"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,yDAAyD,GAKzD,SAASA,aAAa,QAAQ,SAAQ;AACtC,SACEC,iBAAiB,EACjBC,eAAe,EACfC,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rateDown.ts"],"sourcesContent":["/* eslint-disable no-restricted-syntax, no-await-in-loop */\nimport type {
|
1
|
+
{"version":3,"sources":["../src/migrateDown.ts"],"sourcesContent":["/* eslint-disable no-restricted-syntax, no-await-in-loop */\nimport type { PayloadRequestWithData } from 'payload/types'\n\nimport {\n commitTransaction,\n getMigrations,\n initTransaction,\n killTransaction,\n readMigrationFiles,\n} from 'payload/database'\n\nimport type { PostgresAdapter } from './types.js'\n\nimport { migrationTableExists } from './utilities/migrationTableExists.js'\nimport { parseError } from './utilities/parseError.js'\n\nexport async function migrateDown(this: PostgresAdapter): Promise<void> {\n const { payload } = this\n const migrationFiles = await readMigrationFiles({ payload })\n\n const { existingMigrations, latestBatch } = await getMigrations({\n payload,\n })\n\n if (!existingMigrations?.length) {\n payload.logger.info({ msg: 'No migrations to rollback.' })\n return\n }\n\n payload.logger.info({\n msg: `Rolling back batch ${latestBatch} consisting of ${existingMigrations.length} migration(s).`,\n })\n\n const latestBatchMigrations = existingMigrations.filter(({ batch }) => batch === latestBatch)\n\n for (const migration of latestBatchMigrations) {\n const migrationFile = migrationFiles.find((m) => m.name === migration.name)\n if (!migrationFile) {\n throw new Error(`Migration ${migration.name} not found locally.`)\n }\n\n const start = Date.now()\n const req = { payload } as PayloadRequestWithData\n\n try {\n payload.logger.info({ msg: `Migrating down: ${migrationFile.name}` })\n await initTransaction(req)\n await migrationFile.down({ payload, req })\n payload.logger.info({\n msg: `Migrated down: ${migrationFile.name} (${Date.now() - start}ms)`,\n })\n\n const tableExists = await migrationTableExists(this.drizzle)\n if (tableExists) {\n await payload.delete({\n id: migration.id,\n collection: 'payload-migrations',\n req,\n })\n }\n\n await commitTransaction(req)\n } catch (err: unknown) {\n await killTransaction(req)\n\n payload.logger.error({\n err,\n msg: parseError(err, `Error migrating down ${migrationFile.name}. Rolling back.`),\n })\n process.exit(1)\n }\n }\n}\n"],"names":["commitTransaction","getMigrations","initTransaction","killTransaction","readMigrationFiles","migrationTableExists","parseError","migrateDown","payload","migrationFiles","existingMigrations","latestBatch","length","logger","info","msg","latestBatchMigrations","filter","batch","migration","migrationFile","find","m","name","Error","start","Date","now","req","down","tableExists","drizzle","delete","id","collection","err","error","process","exit"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,yDAAyD,GAGzD,SACEA,iBAAiB,EACjBC,aAAa,EACbC,eAAe,EACfC,eAAe,EACfC,kBAAkB,QACb,mBAAkB;AAIzB,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,eAAeC;IACpB,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IACxB,MAAMC,iBAAiB,MAAML,mBAAmB;QAAEI;IAAQ;IAE1D,MAAM,EAAEE,kBAAkB,EAAEC,WAAW,EAAE,GAAG,MAAMV,cAAc;QAC9DO;IACF;IAEA,IAAI,CAACE,oBAAoBE,QAAQ;QAC/BJ,QAAQK,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK;QAA6B;QACxD;IACF;IAEAP,QAAQK,MAAM,CAACC,IAAI,CAAC;QAClBC,KAAK,CAAC,mBAAmB,EAAEJ,YAAY,eAAe,EAAED,mBAAmBE,MAAM,CAAC,cAAc,CAAC;IACnG;IAEA,MAAMI,wBAAwBN,mBAAmBO,MAAM,CAAC,CAAC,EAAEC,KAAK,EAAE,GAAKA,UAAUP;IAEjF,KAAK,MAAMQ,aAAaH,sBAAuB;QAC7C,MAAMI,gBAAgBX,eAAeY,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ,UAAUI,IAAI;QAC1E,IAAI,CAACH,eAAe;YAClB,MAAM,IAAII,MAAM,CAAC,UAAU,EAAEL,UAAUI,IAAI,CAAC,mBAAmB,CAAC;QAClE;QAEA,MAAME,QAAQC,KAAKC,GAAG;QACtB,MAAMC,MAAM;YAAEpB;QAAQ;QAEtB,IAAI;YACFA,QAAQK,MAAM,CAACC,IAAI,CAAC;gBAAEC,KAAK,CAAC,gBAAgB,EAAEK,cAAcG,IAAI,CAAC,CAAC;YAAC;YACnE,MAAMrB,gBAAgB0B;YACtB,MAAMR,cAAcS,IAAI,CAAC;gBAAErB;gBAASoB;YAAI;YACxCpB,QAAQK,MAAM,CAACC,IAAI,CAAC;gBAClBC,KAAK,CAAC,gBAAgB,EAAEK,cAAcG,IAAI,CAAC,EAAE,EAAEG,KAAKC,GAAG,KAAKF,MAAM,GAAG,CAAC;YACxE;YAEA,MAAMK,cAAc,MAAMzB,qBAAqB,IAAI,CAAC0B,OAAO;YAC3D,IAAID,aAAa;gBACf,MAAMtB,QAAQwB,MAAM,CAAC;oBACnBC,IAAId,UAAUc,EAAE;oBAChBC,YAAY;oBACZN;gBACF;YACF;YAEA,MAAM5B,kBAAkB4B;QAC1B,EAAE,OAAOO,KAAc;YACrB,MAAMhC,gBAAgByB;YAEtBpB,QAAQK,MAAM,CAACuB,KAAK,CAAC;gBACnBD;gBACApB,KAAKT,WAAW6B,KAAK,CAAC,qBAAqB,EAAEf,cAAcG,IAAI,CAAC,eAAe,CAAC;YAClF;YACAc,QAAQC,IAAI,CAAC;QACf;IACF;AACF"}
|
package/dist/migrateFresh.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/migrateFresh.ts"],"sourcesContent":["import type {
|
1
|
+
{"version":3,"sources":["../src/migrateFresh.ts"],"sourcesContent":["import type { PayloadRequestWithData } from 'payload/types'\n\nimport { sql } from 'drizzle-orm'\nimport {\n commitTransaction,\n initTransaction,\n killTransaction,\n readMigrationFiles,\n} from 'payload/database'\nimport prompts from 'prompts'\n\nimport type { PostgresAdapter } 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: PostgresAdapter,\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.drizzle.execute(\n sql.raw(`drop schema ${this.schemaName || 'public'} cascade;\n create schema ${this.schemaName || 'public'};`),\n )\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 PayloadRequestWithData\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 await migration.up({ 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":["sql","commitTransaction","initTransaction","killTransaction","readMigrationFiles","prompts","parseError","migrateFresh","forceAcceptWarning","payload","confirm","acceptWarning","name","type","initial","message","onCancel","process","exit","logger","info","msg","drizzle","execute","raw","schemaName","migrationFiles","debug","length","req","migration","start","Date","now","up","create","collection","data","batch","err","error"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,GAAG,QAAQ,cAAa;AACjC,SACEC,iBAAiB,EACjBC,eAAe,EACfC,eAAe,EACfC,kBAAkB,QACb,mBAAkB;AACzB,OAAOC,aAAa,UAAS;AAI7B,SAASC,UAAU,QAAQ,4BAA2B;AAEtD;;CAEC,GACD,OAAO,eAAe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