@payloadcms/drizzle 3.0.0-canary.a5aaf21 → 3.0.0-canary.a6e7305
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/create.d.ts.map +1 -1
- package/dist/create.js +2 -1
- package/dist/create.js.map +1 -1
- package/dist/createGlobalVersion.d.ts +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +4 -1
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createVersion.d.ts +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +4 -4
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +2 -1
- package/dist/deleteOne.js.map +1 -1
- package/dist/exports/postgres.d.ts +1 -0
- package/dist/exports/postgres.d.ts.map +1 -1
- package/dist/exports/postgres.js +1 -0
- package/dist/exports/postgres.js.map +1 -1
- package/dist/find/buildFindManyArgs.d.ts +4 -2
- package/dist/find/buildFindManyArgs.d.ts.map +1 -1
- package/dist/find/buildFindManyArgs.js +40 -21
- package/dist/find/buildFindManyArgs.js.map +1 -1
- package/dist/find/findMany.d.ts +2 -1
- package/dist/find/findMany.d.ts.map +1 -1
- package/dist/find/findMany.js +7 -5
- package/dist/find/findMany.js.map +1 -1
- package/dist/find/traverseFields.d.ts +13 -3
- package/dist/find/traverseFields.d.ts.map +1 -1
- package/dist/find/traverseFields.js +275 -89
- package/dist/find/traverseFields.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +3 -2
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +2 -1
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +3 -2
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +2 -1
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +3 -2
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/migrateReset.js +1 -1
- package/dist/migrateReset.js.map +1 -1
- package/dist/postgres/countDistinct.d.ts.map +1 -1
- package/dist/postgres/countDistinct.js +2 -3
- package/dist/postgres/countDistinct.js.map +1 -1
- package/dist/postgres/createDatabase.d.ts +14 -0
- package/dist/postgres/createDatabase.d.ts.map +1 -0
- package/dist/postgres/createDatabase.js +76 -0
- package/dist/postgres/createDatabase.js.map +1 -0
- package/dist/postgres/defaultSnapshot.d.ts.map +1 -1
- package/dist/postgres/defaultSnapshot.js +2 -1
- package/dist/postgres/defaultSnapshot.js.map +1 -1
- package/dist/postgres/init.d.ts.map +1 -1
- package/dist/postgres/init.js +10 -1
- package/dist/postgres/init.js.map +1 -1
- package/dist/postgres/schema/build.d.ts +3 -1
- package/dist/postgres/schema/build.d.ts.map +1 -1
- package/dist/postgres/schema/build.js +29 -3
- package/dist/postgres/schema/build.js.map +1 -1
- package/dist/postgres/schema/createIndex.d.ts +2 -3
- package/dist/postgres/schema/createIndex.d.ts.map +1 -1
- package/dist/postgres/schema/createIndex.js +3 -3
- package/dist/postgres/schema/createIndex.js.map +1 -1
- package/dist/postgres/schema/traverseFields.d.ts +3 -1
- package/dist/postgres/schema/traverseFields.d.ts.map +1 -1
- package/dist/postgres/schema/traverseFields.js +34 -28
- package/dist/postgres/schema/traverseFields.js.map +1 -1
- package/dist/postgres/types.d.ts +32 -6
- package/dist/postgres/types.d.ts.map +1 -1
- package/dist/postgres/types.js.map +1 -1
- package/dist/queries/addJoinTable.d.ts +11 -0
- package/dist/queries/addJoinTable.d.ts.map +1 -0
- package/dist/queries/addJoinTable.js +13 -0
- package/dist/queries/addJoinTable.js.map +1 -0
- package/dist/queries/buildOrderBy.d.ts +2 -2
- package/dist/queries/buildOrderBy.d.ts.map +1 -1
- package/dist/queries/buildOrderBy.js +32 -27
- package/dist/queries/buildOrderBy.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +4 -3
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
- package/dist/queries/getTableColumnFromPath.js +80 -70
- package/dist/queries/getTableColumnFromPath.js.map +1 -1
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +2 -0
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts +2 -1
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +13 -3
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +5 -4
- package/dist/queryDrafts.js.map +1 -1
- package/dist/transform/read/traverseFields.d.ts.map +1 -1
- package/dist/transform/read/traverseFields.js +41 -7
- package/dist/transform/read/traverseFields.js.map +1 -1
- package/dist/transform/write/traverseFields.d.ts.map +1 -1
- package/dist/transform/write/traverseFields.js +13 -2
- package/dist/transform/write/traverseFields.js.map +1 -1
- package/dist/types.d.ts +1 -0
- 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 -1
- package/dist/update.js.map +1 -1
- package/dist/updateGlobal.d.ts +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +2 -1
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +2 -1
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateVersion.d.ts +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +2 -1
- package/dist/updateVersion.js.map +1 -1
- package/dist/upsertRow/index.d.ts +1 -1
- package/dist/upsertRow/index.d.ts.map +1 -1
- package/dist/upsertRow/index.js +2 -1
- package/dist/upsertRow/index.js.map +1 -1
- package/dist/upsertRow/types.d.ts +3 -1
- package/dist/upsertRow/types.d.ts.map +1 -1
- package/dist/upsertRow/types.js.map +1 -1
- package/dist/utilities/buildIndexName.d.ts +7 -0
- package/dist/utilities/buildIndexName.d.ts.map +1 -0
- package/dist/utilities/buildIndexName.js +14 -0
- package/dist/utilities/buildIndexName.js.map +1 -0
- package/dist/utilities/executeSchemaHooks.d.ts +24 -0
- package/dist/utilities/executeSchemaHooks.d.ts.map +1 -0
- package/dist/utilities/executeSchemaHooks.js +21 -0
- package/dist/utilities/executeSchemaHooks.js.map +1 -0
- package/dist/utilities/extendDrizzleTable.d.ts +19 -0
- package/dist/utilities/extendDrizzleTable.d.ts.map +1 -0
- package/dist/utilities/extendDrizzleTable.js +38 -0
- package/dist/utilities/extendDrizzleTable.js.map +1 -0
- package/dist/utilities/getNameFromDrizzleTable.d.ts +3 -0
- package/dist/utilities/getNameFromDrizzleTable.d.ts.map +1 -0
- package/dist/utilities/getNameFromDrizzleTable.js +6 -0
- package/dist/utilities/getNameFromDrizzleTable.js.map +1 -0
- package/package.json +7 -7
package/dist/findGlobal.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import toSnakeCase from 'to-snake-case';
|
|
2
2
|
import { findMany } from './find/findMany.js';
|
|
3
|
-
export const findGlobal = async function findGlobal({ slug, locale, req, where }) {
|
|
3
|
+
export const findGlobal = async function findGlobal({ slug, locale, req, select, where }) {
|
|
4
4
|
const globalConfig = this.payload.globals.config.find((config)=>config.slug === slug);
|
|
5
5
|
const tableName = this.tableNameMap.get(toSnakeCase(globalConfig.slug));
|
|
6
6
|
const { docs: [doc] } = await findMany({
|
|
@@ -10,6 +10,7 @@ export const findGlobal = async function findGlobal({ slug, locale, req, where }
|
|
|
10
10
|
locale,
|
|
11
11
|
pagination: false,
|
|
12
12
|
req,
|
|
13
|
+
select,
|
|
13
14
|
tableName,
|
|
14
15
|
where
|
|
15
16
|
});
|
package/dist/findGlobal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/findGlobal.ts"],"sourcesContent":["import type { FindGlobal } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport const findGlobal: FindGlobal = async function findGlobal(\n this: DrizzleAdapter,\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"],"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;
|
|
1
|
+
{"version":3,"sources":["../src/findGlobal.ts"],"sourcesContent":["import type { FindGlobal } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport const findGlobal: FindGlobal = async function findGlobal(\n this: DrizzleAdapter,\n { slug, locale, req, select, 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 select,\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","select","where","globalConfig","payload","globals","config","find","tableName","tableNameMap","get","docs","doc","adapter","fields","limit","pagination","globalType"],"mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,IAAI,EAAEC,MAAM,EAAEC,GAAG,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAEpC,MAAMC,eAAe,IAAI,CAACC,OAAO,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAACD,SAAWA,OAAOR,IAAI,KAAKA;IAElF,MAAMU,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAACf,YAAYQ,aAAaL,IAAI;IAErE,MAAM,EACJa,MAAM,CAACC,IAAI,EACZ,GAAG,MAAMhB,SAAS;QACjBiB,SAAS,IAAI;QACbC,QAAQX,aAAaW,MAAM;QAC3BC,OAAO;QACPhB;QACAiB,YAAY;QACZhB;QACAC;QACAO;QACAN;IACF;IAEA,IAAIU,KAAK;QACPA,IAAIK,UAAU,GAAGnB;QACjB,OAAOc;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,EAAyC,MAAM,SAAS,CAAA;AASxF,eAAO,MAAM,kBAAkB,EAAE,
|
|
1
|
+
{"version":3,"file":"findGlobalVersions.d.ts","sourceRoot":"","sources":["../src/findGlobalVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAyC,MAAM,SAAS,CAAA;AASxF,eAAO,MAAM,kBAAkB,EAAE,kBAwChC,CAAA"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { buildVersionGlobalFields } from 'payload';
|
|
2
2
|
import toSnakeCase from 'to-snake-case';
|
|
3
3
|
import { findMany } from './find/findMany.js';
|
|
4
|
-
export const findGlobalVersions = async function findGlobalVersions({ global, limit, locale, page, pagination, req = {}, skip, sort: sortArg, where }) {
|
|
4
|
+
export const findGlobalVersions = async function findGlobalVersions({ global, limit, locale, page, pagination, req = {}, select, skip, sort: sortArg, where }) {
|
|
5
5
|
const globalConfig = this.payload.globals.config.find(({ slug })=>slug === global);
|
|
6
|
-
const sort =
|
|
6
|
+
const sort = sortArg !== undefined && sortArg !== null ? sortArg : '-createdAt';
|
|
7
7
|
const tableName = this.tableNameMap.get(`_${toSnakeCase(globalConfig.slug)}${this.versionsSuffix}`);
|
|
8
8
|
const fields = buildVersionGlobalFields(this.payload.config, globalConfig);
|
|
9
9
|
return findMany({
|
|
@@ -14,6 +14,7 @@ export const findGlobalVersions = async function findGlobalVersions({ global, li
|
|
|
14
14
|
page,
|
|
15
15
|
pagination,
|
|
16
16
|
req,
|
|
17
|
+
select,
|
|
17
18
|
skip,
|
|
18
19
|
sort,
|
|
19
20
|
tableName,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/findGlobalVersions.ts"],"sourcesContent":["import type { FindGlobalVersions, PayloadRequest, SanitizedGlobalConfig } from 'payload'\n\nimport { buildVersionGlobalFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport const findGlobalVersions: FindGlobalVersions = async function findGlobalVersions(\n this: DrizzleAdapter,\n {\n global,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequest,\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 =
|
|
1
|
+
{"version":3,"sources":["../src/findGlobalVersions.ts"],"sourcesContent":["import type { FindGlobalVersions, PayloadRequest, SanitizedGlobalConfig } from 'payload'\n\nimport { buildVersionGlobalFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport const findGlobalVersions: FindGlobalVersions = async function findGlobalVersions(\n this: DrizzleAdapter,\n {\n global,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequest,\n select,\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 = sortArg !== undefined && sortArg !== null ? sortArg : '-createdAt'\n\n const tableName = this.tableNameMap.get(\n `_${toSnakeCase(globalConfig.slug)}${this.versionsSuffix}`,\n )\n\n const fields = buildVersionGlobalFields(this.payload.config, globalConfig)\n\n return findMany({\n adapter: this,\n fields,\n limit,\n locale,\n page,\n pagination,\n req,\n select,\n skip,\n sort,\n tableName,\n where,\n })\n}\n"],"names":["buildVersionGlobalFields","toSnakeCase","findMany","findGlobalVersions","global","limit","locale","page","pagination","req","select","skip","sort","sortArg","where","globalConfig","payload","globals","config","find","slug","undefined","tableName","tableNameMap","get","versionsSuffix","fields","adapter"],"mappings":"AAEA,SAASA,wBAAwB,QAAQ,UAAS;AAClD,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,CAAmB,EAC1BC,MAAM,EACNC,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,SAAShB;IAEzB,MAAMQ,OAAOC,YAAYQ,aAAaR,YAAY,OAAOA,UAAU;IAEnE,MAAMS,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CACrC,CAAC,CAAC,EAAEvB,YAAYc,aAAaK,IAAI,EAAE,EAAE,IAAI,CAACK,cAAc,CAAC,CAAC;IAG5D,MAAMC,SAAS1B,yBAAyB,IAAI,CAACgB,OAAO,CAACE,MAAM,EAAEH;IAE7D,OAAOb,SAAS;QACdyB,SAAS,IAAI;QACbD;QACArB;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAU;QACAR;IACF;AACF,EAAC"}
|
package/dist/findOne.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { FindOneArgs, TypeWithID } from 'payload';
|
|
2
2
|
import type { DrizzleAdapter } from './types.js';
|
|
3
|
-
export declare function findOne<T extends TypeWithID>(this: DrizzleAdapter, { collection, joins, locale, req, where }: FindOneArgs): Promise<T>;
|
|
3
|
+
export declare function findOne<T extends TypeWithID>(this: DrizzleAdapter, { collection, joins, locale, req, select, where }: FindOneArgs): Promise<T>;
|
|
4
4
|
//# sourceMappingURL=findOne.d.ts.map
|
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,EAA6C,UAAU,EAAE,MAAM,SAAS,CAAA;AAIjG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAIhD,wBAAsB,OAAO,CAAC,CAAC,SAAS,UAAU,EAChD,IAAI,EAAE,cAAc,EACpB,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,GAA0B,EAAE,KAAK,EAAE,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../src/findOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAA6C,UAAU,EAAE,MAAM,SAAS,CAAA;AAIjG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAIhD,wBAAsB,OAAO,CAAC,CAAC,SAAS,UAAU,EAChD,IAAI,EAAE,cAAc,EACpB,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,GAA0B,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,WAAW,GACpF,OAAO,CAAC,CAAC,CAAC,CAqBZ"}
|
package/dist/findOne.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import toSnakeCase from 'to-snake-case';
|
|
2
2
|
import { findMany } from './find/findMany.js';
|
|
3
|
-
export async function findOne({ collection, joins, locale, req = {}, where }) {
|
|
3
|
+
export async function findOne({ collection, joins, locale, req = {}, select, where }) {
|
|
4
4
|
const collectionConfig = this.payload.collections[collection].config;
|
|
5
5
|
const tableName = this.tableNameMap.get(toSnakeCase(collectionConfig.slug));
|
|
6
6
|
const { docs } = await findMany({
|
|
@@ -12,6 +12,7 @@ export async function findOne({ collection, joins, locale, req = {}, where }) {
|
|
|
12
12
|
page: 1,
|
|
13
13
|
pagination: false,
|
|
14
14
|
req,
|
|
15
|
+
select,
|
|
15
16
|
sort: undefined,
|
|
16
17
|
tableName,
|
|
17
18
|
where
|
package/dist/findOne.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/findOne.ts"],"sourcesContent":["import type { FindOneArgs, PayloadRequest, SanitizedCollectionConfig, TypeWithID } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport async function findOne<T extends TypeWithID>(\n this: DrizzleAdapter,\n { collection, joins, locale, req = {} as PayloadRequest, 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 joins,\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","joins","locale","req","where","collectionConfig","payload","collections","config","tableName","tableNameMap","get","slug","docs","adapter","fields","limit","page","pagination","sort","undefined"],"mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,OAAO,eAAeC,QAEpB,EAAEC,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAe;
|
|
1
|
+
{"version":3,"sources":["../src/findOne.ts"],"sourcesContent":["import type { FindOneArgs, PayloadRequest, SanitizedCollectionConfig, TypeWithID } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport async function findOne<T extends TypeWithID>(\n this: DrizzleAdapter,\n { collection, joins, locale, req = {} as PayloadRequest, select, 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 joins,\n limit: 1,\n locale,\n page: 1,\n pagination: false,\n req,\n select,\n sort: undefined,\n tableName,\n where,\n })\n\n return docs?.[0] || null\n}\n"],"names":["toSnakeCase","findMany","findOne","collection","joins","locale","req","select","where","collectionConfig","payload","collections","config","tableName","tableNameMap","get","slug","docs","adapter","fields","limit","page","pagination","sort","undefined"],"mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,OAAO,eAAeC,QAEpB,EAAEC,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAM,EAAEC,KAAK,EAAe;IAErF,MAAMC,mBAA8C,IAAI,CAACC,OAAO,CAACC,WAAW,CAACR,WAAW,CAACS,MAAM;IAE/F,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAACf,YAAYS,iBAAiBO,IAAI;IAEzE,MAAM,EAAEC,IAAI,EAAE,GAAG,MAAMhB,SAAS;QAC9BiB,SAAS,IAAI;QACbC,QAAQV,iBAAiBU,MAAM;QAC/Bf;QACAgB,OAAO;QACPf;QACAgB,MAAM;QACNC,YAAY;QACZhB;QACAC;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,EAA6C,MAAM,SAAS,CAAA;AAStF,eAAO,MAAM,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../src/findVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAA6C,MAAM,SAAS,CAAA;AAStF,eAAO,MAAM,YAAY,EAAE,YAsC1B,CAAA"}
|
package/dist/findVersions.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { buildVersionCollectionFields } from 'payload';
|
|
2
2
|
import toSnakeCase from 'to-snake-case';
|
|
3
3
|
import { findMany } from './find/findMany.js';
|
|
4
|
-
export const findVersions = async function findVersions({ collection, limit, locale, page, pagination, req = {}, skip, sort: sortArg, where }) {
|
|
4
|
+
export const findVersions = async function findVersions({ collection, limit, locale, page, pagination, req = {}, select, skip, sort: sortArg, where }) {
|
|
5
5
|
const collectionConfig = this.payload.collections[collection].config;
|
|
6
|
-
const sort =
|
|
6
|
+
const sort = sortArg !== undefined && sortArg !== null ? sortArg : collectionConfig.defaultSort;
|
|
7
7
|
const tableName = this.tableNameMap.get(`_${toSnakeCase(collectionConfig.slug)}${this.versionsSuffix}`);
|
|
8
8
|
const fields = buildVersionCollectionFields(this.payload.config, collectionConfig);
|
|
9
9
|
return findMany({
|
|
@@ -14,6 +14,7 @@ export const findVersions = async function findVersions({ collection, limit, loc
|
|
|
14
14
|
page,
|
|
15
15
|
pagination,
|
|
16
16
|
req,
|
|
17
|
+
select,
|
|
17
18
|
skip,
|
|
18
19
|
sort,
|
|
19
20
|
tableName,
|
package/dist/findVersions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/findVersions.ts"],"sourcesContent":["import type { FindVersions, PayloadRequest, SanitizedCollectionConfig } from 'payload'\n\nimport { buildVersionCollectionFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport const findVersions: FindVersions = async function findVersions(\n this: DrizzleAdapter,\n {\n collection,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequest,\n skip,\n sort: sortArg,\n where,\n },\n) {\n const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config\n const sort =
|
|
1
|
+
{"version":3,"sources":["../src/findVersions.ts"],"sourcesContent":["import type { FindVersions, PayloadRequest, SanitizedCollectionConfig } from 'payload'\n\nimport { buildVersionCollectionFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport const findVersions: FindVersions = async function findVersions(\n this: DrizzleAdapter,\n {\n collection,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequest,\n select,\n skip,\n sort: sortArg,\n where,\n },\n) {\n const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config\n const sort = sortArg !== undefined && sortArg !== null ? sortArg : collectionConfig.defaultSort\n\n const tableName = this.tableNameMap.get(\n `_${toSnakeCase(collectionConfig.slug)}${this.versionsSuffix}`,\n )\n\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig)\n\n return findMany({\n adapter: this,\n fields,\n limit,\n locale,\n page,\n pagination,\n req,\n select,\n skip,\n sort,\n tableName,\n where,\n })\n}\n"],"names":["buildVersionCollectionFields","toSnakeCase","findMany","findVersions","collection","limit","locale","page","pagination","req","select","skip","sort","sortArg","where","collectionConfig","payload","collections","config","undefined","defaultSort","tableName","tableNameMap","get","slug","versionsSuffix","fields","adapter"],"mappings":"AAEA,SAASA,4BAA4B,QAAQ,UAAS;AACtD,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,CAAmB,EAC1BC,MAAM,EACNC,IAAI,EACJC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,mBAA8C,IAAI,CAACC,OAAO,CAACC,WAAW,CAACb,WAAW,CAACc,MAAM;IAC/F,MAAMN,OAAOC,YAAYM,aAAaN,YAAY,OAAOA,UAAUE,iBAAiBK,WAAW;IAE/F,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CACrC,CAAC,CAAC,EAAEtB,YAAYc,iBAAiBS,IAAI,EAAE,EAAE,IAAI,CAACC,cAAc,CAAC,CAAC;IAGhE,MAAMC,SAAS1B,6BAA6B,IAAI,CAACgB,OAAO,CAACE,MAAM,EAAEH;IAEjE,OAAOb,SAAS;QACdyB,SAAS,IAAI;QACbD;QACArB;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAS;QACAP;IACF;AACF,EAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -32,6 +32,9 @@ export { updateGlobal } from './updateGlobal.js';
|
|
|
32
32
|
export { updateGlobalVersion } from './updateGlobalVersion.js';
|
|
33
33
|
export { updateVersion } from './updateVersion.js';
|
|
34
34
|
export { upsertRow } from './upsertRow/index.js';
|
|
35
|
+
export { buildIndexName } from './utilities/buildIndexName.js';
|
|
36
|
+
export { executeSchemaHooks } from './utilities/executeSchemaHooks.js';
|
|
37
|
+
export { extendDrizzleTable } from './utilities/extendDrizzleTable.js';
|
|
35
38
|
export { hasLocalesTable } from './utilities/hasLocalesTable.js';
|
|
36
39
|
export { pushDevSchema } from './utilities/pushDevSchema.js';
|
|
37
40
|
export { validateExistingBlockIsIdentical } from './utilities/validateExistingBlockIsIdentical.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uB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B,CAAA;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAA;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAA;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAA;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAC5D,OAAO,EAAE,gCAAgC,EAAE,MAAM,iDAAiD,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -31,6 +31,9 @@ export { updateGlobal } from './updateGlobal.js';
|
|
|
31
31
|
export { updateGlobalVersion } from './updateGlobalVersion.js';
|
|
32
32
|
export { updateVersion } from './updateVersion.js';
|
|
33
33
|
export { upsertRow } from './upsertRow/index.js';
|
|
34
|
+
export { buildIndexName } from './utilities/buildIndexName.js';
|
|
35
|
+
export { executeSchemaHooks } from './utilities/executeSchemaHooks.js';
|
|
36
|
+
export { extendDrizzleTable } from './utilities/extendDrizzleTable.js';
|
|
34
37
|
export { hasLocalesTable } from './utilities/hasLocalesTable.js';
|
|
35
38
|
export { pushDevSchema } from './utilities/pushDevSchema.js';
|
|
36
39
|
export { validateExistingBlockIsIdentical } from './utilities/validateExistingBlockIsIdentical.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { count } from './count.js'\nexport { create } from './create.js'\nexport { createGlobal } from './createGlobal.js'\nexport { createGlobalVersion } from './createGlobalVersion.js'\nexport { createTableName } from './createTableName.js'\nexport { createVersion } from './createVersion.js'\nexport { deleteMany } from './deleteMany.js'\nexport { deleteOne } from './deleteOne.js'\nexport { deleteVersions } from './deleteVersions.js'\nexport { destroy } from './destroy.js'\nexport { find } from './find.js'\nexport { chainMethods } from './find/chainMethods.js'\nexport { findGlobal } from './findGlobal.js'\nexport { findGlobalVersions } from './findGlobalVersions.js'\nexport { findMigrationDir } from './findMigrationDir.js'\nexport { findOne } from './findOne.js'\nexport { findVersions } from './findVersions.js'\nexport { migrate } from './migrate.js'\nexport { migrateDown } from './migrateDown.js'\nexport { migrateFresh } from './migrateFresh.js'\nexport { migrateRefresh } from './migrateRefresh.js'\nexport { migrateReset } from './migrateReset.js'\nexport { migrateStatus } from './migrateStatus.js'\nexport { operatorMap } from './queries/operatorMap.js'\nexport type { Operators } from './queries/operatorMap.js'\nexport { queryDrafts } from './queryDrafts.js'\nexport { beginTransaction } from './transactions/beginTransaction.js'\nexport { commitTransaction } from './transactions/commitTransaction.js'\nexport { rollbackTransaction } from './transactions/rollbackTransaction.js'\nexport { updateOne } from './update.js'\nexport { updateGlobal } from './updateGlobal.js'\nexport { updateGlobalVersion } from './updateGlobalVersion.js'\nexport { updateVersion } from './updateVersion.js'\nexport { upsertRow } from './upsertRow/index.js'\nexport { hasLocalesTable } from './utilities/hasLocalesTable.js'\nexport { pushDevSchema } from './utilities/pushDevSchema.js'\nexport { validateExistingBlockIsIdentical } from './utilities/validateExistingBlockIsIdentical.js'\n"],"names":["count","create","createGlobal","createGlobalVersion","createTableName","createVersion","deleteMany","deleteOne","deleteVersions","destroy","find","chainMethods","findGlobal","findGlobalVersions","findMigrationDir","findOne","findVersions","migrate","migrateDown","migrateFresh","migrateRefresh","migrateReset","migrateStatus","operatorMap","queryDrafts","beginTransaction","commitTransaction","rollbackTransaction","updateOne","updateGlobal","updateGlobalVersion","updateVersion","upsertRow","hasLocalesTable","pushDevSchema","validateExistingBlockIsIdentical"],"mappings":"AAAA,SAASA,KAAK,QAAQ,aAAY;AAClC,SAASC,MAAM,QAAQ,cAAa;AACpC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,IAAI,QAAQ,YAAW;AAChC,SAASC,YAAY,QAAQ,yBAAwB;AACrD,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,gBAAgB,QAAQ,wBAAuB;AACxD,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,WAAW,QAAQ,2BAA0B;AAEtD,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,gBAAgB,QAAQ,qCAAoC;AACrE,SAASC,iBAAiB,QAAQ,sCAAqC;AACvE,SAASC,mBAAmB,QAAQ,wCAAuC;AAC3E,SAASC,SAAS,QAAQ,cAAa;AACvC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SAASC,eAAe,QAAQ,iCAAgC;AAChE,SAASC,aAAa,QAAQ,+BAA8B;AAC5D,SAASC,gCAAgC,QAAQ,kDAAiD"}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { count } from './count.js'\nexport { create } from './create.js'\nexport { createGlobal } from './createGlobal.js'\nexport { createGlobalVersion } from './createGlobalVersion.js'\nexport { createTableName } from './createTableName.js'\nexport { createVersion } from './createVersion.js'\nexport { deleteMany } from './deleteMany.js'\nexport { deleteOne } from './deleteOne.js'\nexport { deleteVersions } from './deleteVersions.js'\nexport { destroy } from './destroy.js'\nexport { find } from './find.js'\nexport { chainMethods } from './find/chainMethods.js'\nexport { findGlobal } from './findGlobal.js'\nexport { findGlobalVersions } from './findGlobalVersions.js'\nexport { findMigrationDir } from './findMigrationDir.js'\nexport { findOne } from './findOne.js'\nexport { findVersions } from './findVersions.js'\nexport { migrate } from './migrate.js'\nexport { migrateDown } from './migrateDown.js'\nexport { migrateFresh } from './migrateFresh.js'\nexport { migrateRefresh } from './migrateRefresh.js'\nexport { migrateReset } from './migrateReset.js'\nexport { migrateStatus } from './migrateStatus.js'\nexport { operatorMap } from './queries/operatorMap.js'\nexport type { Operators } from './queries/operatorMap.js'\nexport { queryDrafts } from './queryDrafts.js'\nexport { beginTransaction } from './transactions/beginTransaction.js'\nexport { commitTransaction } from './transactions/commitTransaction.js'\nexport { rollbackTransaction } from './transactions/rollbackTransaction.js'\nexport { updateOne } from './update.js'\nexport { updateGlobal } from './updateGlobal.js'\nexport { updateGlobalVersion } from './updateGlobalVersion.js'\nexport { updateVersion } from './updateVersion.js'\nexport { upsertRow } from './upsertRow/index.js'\nexport { buildIndexName } from './utilities/buildIndexName.js'\nexport { executeSchemaHooks } from './utilities/executeSchemaHooks.js'\nexport { extendDrizzleTable } from './utilities/extendDrizzleTable.js'\nexport { hasLocalesTable } from './utilities/hasLocalesTable.js'\nexport { pushDevSchema } from './utilities/pushDevSchema.js'\nexport { validateExistingBlockIsIdentical } from './utilities/validateExistingBlockIsIdentical.js'\n"],"names":["count","create","createGlobal","createGlobalVersion","createTableName","createVersion","deleteMany","deleteOne","deleteVersions","destroy","find","chainMethods","findGlobal","findGlobalVersions","findMigrationDir","findOne","findVersions","migrate","migrateDown","migrateFresh","migrateRefresh","migrateReset","migrateStatus","operatorMap","queryDrafts","beginTransaction","commitTransaction","rollbackTransaction","updateOne","updateGlobal","updateGlobalVersion","updateVersion","upsertRow","buildIndexName","executeSchemaHooks","extendDrizzleTable","hasLocalesTable","pushDevSchema","validateExistingBlockIsIdentical"],"mappings":"AAAA,SAASA,KAAK,QAAQ,aAAY;AAClC,SAASC,MAAM,QAAQ,cAAa;AACpC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,IAAI,QAAQ,YAAW;AAChC,SAASC,YAAY,QAAQ,yBAAwB;AACrD,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,gBAAgB,QAAQ,wBAAuB;AACxD,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,WAAW,QAAQ,2BAA0B;AAEtD,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,gBAAgB,QAAQ,qCAAoC;AACrE,SAASC,iBAAiB,QAAQ,sCAAqC;AACvE,SAASC,mBAAmB,QAAQ,wCAAuC;AAC3E,SAASC,SAAS,QAAQ,cAAa;AACvC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SAASC,cAAc,QAAQ,gCAA+B;AAC9D,SAASC,kBAAkB,QAAQ,oCAAmC;AACtE,SAASC,kBAAkB,QAAQ,oCAAmC;AACtE,SAASC,eAAe,QAAQ,iCAAgC;AAChE,SAASC,aAAa,QAAQ,+BAA8B;AAC5D,SAASC,gCAAgC,QAAQ,kDAAiD"}
|
package/dist/migrateReset.js
CHANGED
package/dist/migrateReset.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/migrateReset.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport {\n commitTransaction,\n getMigrations,\n initTransaction,\n killTransaction,\n readMigrationFiles,\n} from 'payload'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { migrationTableExists } from './utilities/migrationTableExists.js'\n\n/**\n * Run all migrate down functions\n */\nexport async function migrateReset(this: DrizzleAdapter): Promise<void> {\n const { payload } = this\n const migrationFiles = await readMigrationFiles({ payload })\n\n const { existingMigrations } = await getMigrations({ payload })\n\n if (!existingMigrations?.length) {\n payload.logger.info({ msg: 'No migrations to reset.' })\n return\n }\n\n const req = { payload } as PayloadRequest\n\n // Rollback all migrations in order\n for (const migration of existingMigrations) {\n const migrationFile = migrationFiles.find((m) => m.name === migration.name)\n try {\n if (!migrationFile) {\n throw new Error(`Migration ${migration.name} not found locally.`)\n }\n\n const start = Date.now()\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)\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 let msg = `Error running migration ${migrationFile.name}.`\n\n if (err instanceof Error) {\n msg += ` ${err.message}`\n }\n\n await killTransaction(req)\n payload.logger.error({\n err,\n msg,\n })\n process.exit(1)\n }\n }\n\n // Delete dev migration\n\n const tableExists = await migrationTableExists(this)\n if (tableExists) {\n try {\n await payload.delete({\n collection: 'payload-migrations',\n where: {\n batch: {\n equals: -1,\n },\n },\n })\n } catch (err: unknown) {\n payload.logger.error({
|
|
1
|
+
{"version":3,"sources":["../src/migrateReset.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport {\n commitTransaction,\n getMigrations,\n initTransaction,\n killTransaction,\n readMigrationFiles,\n} from 'payload'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { migrationTableExists } from './utilities/migrationTableExists.js'\n\n/**\n * Run all migrate down functions\n */\nexport async function migrateReset(this: DrizzleAdapter): Promise<void> {\n const { payload } = this\n const migrationFiles = await readMigrationFiles({ payload })\n\n const { existingMigrations } = await getMigrations({ payload })\n\n if (!existingMigrations?.length) {\n payload.logger.info({ msg: 'No migrations to reset.' })\n return\n }\n\n const req = { payload } as PayloadRequest\n\n // Rollback all migrations in order\n for (const migration of existingMigrations) {\n const migrationFile = migrationFiles.find((m) => m.name === migration.name)\n try {\n if (!migrationFile) {\n throw new Error(`Migration ${migration.name} not found locally.`)\n }\n\n const start = Date.now()\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)\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 let msg = `Error running migration ${migrationFile.name}.`\n\n if (err instanceof Error) {\n msg += ` ${err.message}`\n }\n\n await killTransaction(req)\n payload.logger.error({\n err,\n msg,\n })\n process.exit(1)\n }\n }\n\n // Delete dev migration\n\n const tableExists = await migrationTableExists(this)\n if (tableExists) {\n try {\n await payload.delete({\n collection: 'payload-migrations',\n where: {\n batch: {\n equals: -1,\n },\n },\n })\n } catch (err: unknown) {\n payload.logger.error({ err, msg: 'Error deleting dev migration' })\n }\n }\n}\n"],"names":["commitTransaction","getMigrations","initTransaction","killTransaction","readMigrationFiles","migrationTableExists","migrateReset","payload","migrationFiles","existingMigrations","length","logger","info","msg","req","migration","migrationFile","find","m","name","Error","start","Date","now","down","tableExists","delete","id","collection","err","message","error","process","exit","where","batch","equals"],"mappings":"AAEA,SACEA,iBAAiB,EACjBC,aAAa,EACbC,eAAe,EACfC,eAAe,EACfC,kBAAkB,QACb,UAAS;AAIhB,SAASC,oBAAoB,QAAQ,sCAAqC;AAE1E;;CAEC,GACD,OAAO,eAAeC;IACpB,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IACxB,MAAMC,iBAAiB,MAAMJ,mBAAmB;QAAEG;IAAQ;IAE1D,MAAM,EAAEE,kBAAkB,EAAE,GAAG,MAAMR,cAAc;QAAEM;IAAQ;IAE7D,IAAI,CAACE,oBAAoBC,QAAQ;QAC/BH,QAAQI,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK;QAA0B;QACrD;IACF;IAEA,MAAMC,MAAM;QAAEP;IAAQ;IAEtB,mCAAmC;IACnC,KAAK,MAAMQ,aAAaN,mBAAoB;QAC1C,MAAMO,gBAAgBR,eAAeS,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ,UAAUI,IAAI;QAC1E,IAAI;YACF,IAAI,CAACH,eAAe;gBAClB,MAAM,IAAII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;QAClE;IACF;AACF"}
|
|
@@ -1 +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,
|
|
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,aAwB3B,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { count
|
|
1
|
+
import { count } from 'drizzle-orm';
|
|
2
2
|
import { chainMethods } from '../find/chainMethods.js';
|
|
3
3
|
export const countDistinct = async function countDistinct({ db, joins, tableName, where }) {
|
|
4
4
|
const chainedMethods = [];
|
|
@@ -14,8 +14,7 @@ export const countDistinct = async function countDistinct({ db, joins, tableName
|
|
|
14
14
|
const countResult = await chainMethods({
|
|
15
15
|
methods: chainedMethods,
|
|
16
16
|
query: db.select({
|
|
17
|
-
count:
|
|
18
|
-
(DISTINCT ${this.tables[tableName].id})`.mapWith(Number) : count()
|
|
17
|
+
count: count()
|
|
19
18
|
}).from(this.tables[tableName]).where(where)
|
|
20
19
|
});
|
|
21
20
|
return Number(countResult[0].count);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/postgres/countDistinct.ts"],"sourcesContent":["import { count
|
|
1
|
+
{"version":3,"sources":["../../src/postgres/countDistinct.ts"],"sourcesContent":["import { count } 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: count(),\n })\n .from(this.tables[tableName])\n .where(where),\n })\n\n return Number(countResult[0].count)\n}\n"],"names":["count","chainMethods","countDistinct","db","joins","tableName","where","chainedMethods","forEach","condition","table","push","args","method","countResult","methods","query","select","from","tables","Number"],"mappings":"AAAA,SAASA,KAAK,QAAQ,cAAa;AAKnC,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;YACNjB,OAAOA;QACT,GACCkB,IAAI,CAAC,IAAI,CAACC,MAAM,CAACd,UAAU,EAC3BC,KAAK,CAACA;IACX;IAEA,OAAOc,OAAON,WAAW,CAAC,EAAE,CAACd,KAAK;AACpC,EAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { BasePostgresAdapter } from './types.js';
|
|
2
|
+
type Args = {
|
|
3
|
+
/**
|
|
4
|
+
* Name of a database, defaults to the current one
|
|
5
|
+
*/
|
|
6
|
+
name?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Schema to create in addition to 'public'. Defaults to adapter.schemaName if exists.
|
|
9
|
+
*/
|
|
10
|
+
schemaName?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const createDatabase: (this: BasePostgresAdapter, args?: Args) => Promise<boolean>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=createDatabase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createDatabase.d.ts","sourceRoot":"","sources":["../../src/postgres/createDatabase.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAgBrD,KAAK,IAAI,GAAG;IACV;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AACD,eAAO,MAAM,cAAc,SAAyB,mBAAmB,SAAQ,IAAI,qBAkFlF,CAAA"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const setConnectionStringDatabase = ({ connectionString, database })=>{
|
|
2
|
+
const connectionURL = new URL(connectionString);
|
|
3
|
+
const newConnectionURL = new URL(connectionURL);
|
|
4
|
+
newConnectionURL.pathname = `/${database}`;
|
|
5
|
+
return newConnectionURL.toString();
|
|
6
|
+
};
|
|
7
|
+
export const createDatabase = async function(args = {}) {
|
|
8
|
+
// POSTGRES_URL - default Vercel env
|
|
9
|
+
const connectionString = this.poolOptions?.connectionString ?? process.env.POSTGRES_URL ?? process.env.DATABASE_URL;
|
|
10
|
+
let managementClientConfig = {};
|
|
11
|
+
let dbName = args.name;
|
|
12
|
+
const schemaName = this.schemaName || 'public';
|
|
13
|
+
if (connectionString) {
|
|
14
|
+
if (!dbName) {
|
|
15
|
+
dbName = new URL(connectionString).pathname.slice(1);
|
|
16
|
+
}
|
|
17
|
+
managementClientConfig.connectionString = setConnectionStringDatabase({
|
|
18
|
+
connectionString,
|
|
19
|
+
database: 'postgres'
|
|
20
|
+
});
|
|
21
|
+
} else {
|
|
22
|
+
if (!dbName) {
|
|
23
|
+
dbName = this.poolOptions.database;
|
|
24
|
+
}
|
|
25
|
+
managementClientConfig = {
|
|
26
|
+
...this.poolOptions,
|
|
27
|
+
database: 'postgres'
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
// import pg only when createDatabase is used
|
|
31
|
+
const pg = await import('pg').then((mod)=>mod.default);
|
|
32
|
+
const managementClient = new pg.Client(managementClientConfig);
|
|
33
|
+
try {
|
|
34
|
+
await managementClient.connect();
|
|
35
|
+
await managementClient.query(`CREATE DATABASE "${dbName}"`);
|
|
36
|
+
this.payload.logger.info(`Created database "${dbName}"`);
|
|
37
|
+
if (schemaName !== 'public') {
|
|
38
|
+
let createdDatabaseConfig = {};
|
|
39
|
+
if (connectionString) {
|
|
40
|
+
createdDatabaseConfig.connectionString = setConnectionStringDatabase({
|
|
41
|
+
connectionString,
|
|
42
|
+
database: dbName
|
|
43
|
+
});
|
|
44
|
+
} else {
|
|
45
|
+
createdDatabaseConfig = {
|
|
46
|
+
...this.poolOptions,
|
|
47
|
+
database: dbName
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const createdDatabaseClient = new pg.Client(createdDatabaseConfig);
|
|
51
|
+
try {
|
|
52
|
+
await createdDatabaseClient.connect();
|
|
53
|
+
await createdDatabaseClient.query(`CREATE SCHEMA ${schemaName}`);
|
|
54
|
+
this.payload.logger.info(`Created schema "${dbName}.${schemaName}"`);
|
|
55
|
+
} catch (err) {
|
|
56
|
+
this.payload.logger.error({
|
|
57
|
+
err,
|
|
58
|
+
msg: `Error: failed to create schema "${dbName}.${schemaName}". Details: ${err.message}`
|
|
59
|
+
});
|
|
60
|
+
} finally{
|
|
61
|
+
await createdDatabaseClient.end();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
} catch (err) {
|
|
66
|
+
this.payload.logger.error({
|
|
67
|
+
err,
|
|
68
|
+
msg: `Error: failed to create database ${dbName}. Details: ${err.message}`
|
|
69
|
+
});
|
|
70
|
+
return false;
|
|
71
|
+
} finally{
|
|
72
|
+
await managementClient.end();
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
//# sourceMappingURL=createDatabase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/postgres/createDatabase.ts"],"sourcesContent":["import type { ClientConfig } from 'pg'\n\nimport type { BasePostgresAdapter } from './types.js'\n\nconst setConnectionStringDatabase = ({\n connectionString,\n database,\n}: {\n connectionString: string\n database: string\n}): string => {\n const connectionURL = new URL(connectionString)\n const newConnectionURL = new URL(connectionURL)\n newConnectionURL.pathname = `/${database}`\n\n return newConnectionURL.toString()\n}\n\ntype Args = {\n /**\n * Name of a database, defaults to the current one\n */\n name?: string\n /**\n * Schema to create in addition to 'public'. Defaults to adapter.schemaName if exists.\n */\n schemaName?: string\n}\nexport const createDatabase = async function (this: BasePostgresAdapter, args: Args = {}) {\n // POSTGRES_URL - default Vercel env\n const connectionString =\n this.poolOptions?.connectionString ?? process.env.POSTGRES_URL ?? process.env.DATABASE_URL\n let managementClientConfig: ClientConfig = {}\n let dbName = args.name\n const schemaName = this.schemaName || 'public'\n\n if (connectionString) {\n if (!dbName) {\n dbName = new URL(connectionString).pathname.slice(1)\n }\n\n managementClientConfig.connectionString = setConnectionStringDatabase({\n connectionString,\n database: 'postgres',\n })\n } else {\n if (!dbName) {\n dbName = this.poolOptions.database\n }\n\n managementClientConfig = {\n ...this.poolOptions,\n database: 'postgres',\n }\n }\n\n // import pg only when createDatabase is used\n const pg = await import('pg').then((mod) => mod.default)\n\n const managementClient = new pg.Client(managementClientConfig)\n\n try {\n await managementClient.connect()\n await managementClient.query(`CREATE DATABASE \"${dbName}\"`)\n\n this.payload.logger.info(`Created database \"${dbName}\"`)\n\n if (schemaName !== 'public') {\n let createdDatabaseConfig: ClientConfig = {}\n\n if (connectionString) {\n createdDatabaseConfig.connectionString = setConnectionStringDatabase({\n connectionString,\n database: dbName,\n })\n } else {\n createdDatabaseConfig = {\n ...this.poolOptions,\n database: dbName,\n }\n }\n\n const createdDatabaseClient = new pg.Client(createdDatabaseConfig)\n\n try {\n await createdDatabaseClient.connect()\n\n await createdDatabaseClient.query(`CREATE SCHEMA ${schemaName}`)\n this.payload.logger.info(`Created schema \"${dbName}.${schemaName}\"`)\n } catch (err) {\n this.payload.logger.error({\n err,\n msg: `Error: failed to create schema \"${dbName}.${schemaName}\". Details: ${err.message}`,\n })\n } finally {\n await createdDatabaseClient.end()\n }\n }\n\n return true\n } catch (err) {\n this.payload.logger.error({\n err,\n msg: `Error: failed to create database ${dbName}. Details: ${err.message}`,\n })\n\n return false\n } finally {\n await managementClient.end()\n }\n}\n"],"names":["setConnectionStringDatabase","connectionString","database","connectionURL","URL","newConnectionURL","pathname","toString","createDatabase","args","poolOptions","process","env","POSTGRES_URL","DATABASE_URL","managementClientConfig","dbName","name","schemaName","slice","pg","then","mod","default","managementClient","Client","connect","query","payload","logger","info","createdDatabaseConfig","createdDatabaseClient","err","error","msg","message","end"],"mappings":"AAIA,MAAMA,8BAA8B,CAAC,EACnCC,gBAAgB,EAChBC,QAAQ,EAIT;IACC,MAAMC,gBAAgB,IAAIC,IAAIH;IAC9B,MAAMI,mBAAmB,IAAID,IAAID;IACjCE,iBAAiBC,QAAQ,GAAG,CAAC,CAAC,EAAEJ,SAAS,CAAC;IAE1C,OAAOG,iBAAiBE,QAAQ;AAClC;AAYA,OAAO,MAAMC,iBAAiB,eAA2CC,OAAa,CAAC,CAAC;IACtF,oCAAoC;IACpC,MAAMR,mBACJ,IAAI,CAACS,WAAW,EAAET,oBAAoBU,QAAQC,GAAG,CAACC,YAAY,IAAIF,QAAQC,GAAG,CAACE,YAAY;IAC5F,IAAIC,yBAAuC,CAAC;IAC5C,IAAIC,SAASP,KAAKQ,IAAI;IACtB,MAAMC,aAAa,IAAI,CAACA,UAAU,IAAI;IAEtC,IAAIjB,kBAAkB;QACpB,IAAI,CAACe,QAAQ;YACXA,SAAS,IAAIZ,IAAIH,kBAAkBK,QAAQ,CAACa,KAAK,CAAC;QACpD;QAEAJ,uBAAuBd,gBAAgB,GAAGD,4BAA4B;YACpEC;YACAC,UAAU;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1F;YACF,SAAU;gBACR,MAAMJ,sBAAsBK,GAAG;YACjC;QACF;QAEA,OAAO;IACT,EAAE,OAAOJ,KAAK;QACZ,IAAI,CAACL,OAAO,CAACC,MAAM,CAACK,KAAK,CAAC;YACxBD;YACAE,KAAK,CAAC,iCAAiC,EAAEnB,OAAO,WAAW,EAAEiB,IAAIG,OAAO,CAAC,CAAC;QAC5E;QAEA,OAAO;IACT,SAAU;QACR,MAAMZ,iBAAiBa,GAAG;IAC5B;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultSnapshot.d.ts","sourceRoot":"","sources":["../../src/postgres/defaultSnapshot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAE1D,eAAO,MAAM,sBAAsB,EAAE,
|
|
1
|
+
{"version":3,"file":"defaultSnapshot.d.ts","sourceRoot":"","sources":["../../src/postgres/defaultSnapshot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAE1D,eAAO,MAAM,sBAAsB,EAAE,mBAepC,CAAA"}
|
|
@@ -1 +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;
|
|
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 views: {},\n}\n"],"names":["defaultDrizzleSnapshot","id","_meta","columns","schemas","tables","dialect","enums","prevId","sequences","version","views"],"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;IACTC,OAAO,CAAC;AACV,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/postgres/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAA6B,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/postgres/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAA6B,MAAM,SAAS,CAAA;AAY9D,eAAO,MAAM,IAAI,EAAE,IAyGlB,CAAA"}
|
package/dist/postgres/init.js
CHANGED
|
@@ -2,8 +2,13 @@ import { uniqueIndex } from 'drizzle-orm/pg-core';
|
|
|
2
2
|
import { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload';
|
|
3
3
|
import toSnakeCase from 'to-snake-case';
|
|
4
4
|
import { createTableName } from '../createTableName.js';
|
|
5
|
+
import { executeSchemaHooks } from '../utilities/executeSchemaHooks.js';
|
|
5
6
|
import { buildTable } from './schema/build.js';
|
|
6
|
-
export const init = function init() {
|
|
7
|
+
export const init = async function init() {
|
|
8
|
+
await executeSchemaHooks({
|
|
9
|
+
type: 'beforeSchemaInit',
|
|
10
|
+
adapter: this
|
|
11
|
+
});
|
|
7
12
|
if (this.payload.config.localization) {
|
|
8
13
|
this.enums.enum__locales = this.pgSchema.enum('_locales', this.payload.config.localization.locales.map(({ code })=>code));
|
|
9
14
|
}
|
|
@@ -90,6 +95,10 @@ export const init = function init() {
|
|
|
90
95
|
});
|
|
91
96
|
}
|
|
92
97
|
});
|
|
98
|
+
await executeSchemaHooks({
|
|
99
|
+
type: 'afterSchemaInit',
|
|
100
|
+
adapter: this
|
|
101
|
+
});
|
|
93
102
|
};
|
|
94
103
|
|
|
95
104
|
//# sourceMappingURL=init.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/postgres/init.ts"],"sourcesContent":["import type { Init, SanitizedCollectionConfig } from 'payload'\n\nimport { uniqueIndex } from 'drizzle-orm/pg-core'\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { BaseExtraConfig, BasePostgresAdapter } from './types.js'\n\nimport { createTableName } from '../createTableName.js'\nimport { buildTable } from './schema/build.js'\n\nexport const init: Init = function init(this: BasePostgresAdapter) {\n if (this.payload.config.localization) {\n this.enums.enum__locales = this.pgSchema.enum(\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 createTableName({\n adapter: this,\n config: collection,\n })\n\n if (collection.versions) {\n createTableName({\n adapter: this,\n config: collection,\n versions: true,\n versionsCustomName: true,\n })\n }\n })\n this.payload.config.collections.forEach((collection: SanitizedCollectionConfig) => {\n const tableName = this.tableNameMap.get(toSnakeCase(collection.slug))\n\n const baseExtraConfig: BaseExtraConfig = {}\n\n if (collection.upload.filenameCompoundIndex) {\n const indexName = `${tableName}_filename_compound_idx`\n\n baseExtraConfig.filename_compound_index = (cols) => {\n const colsConstraint = collection.upload.filenameCompoundIndex.map((f) => {\n return cols[f]\n })\n return uniqueIndex(indexName).on(colsConstraint[0], ...colsConstraint.slice(1))\n }\n }\n\n buildTable({\n adapter: this,\n baseExtraConfig,\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 = this.tableNameMap.get(\n `_${toSnakeCase(collection.slug)}${this.versionsSuffix}`,\n )\n const versionFields = buildVersionCollectionFields(this.payload.config, collection)\n\n buildTable({\n adapter: this,\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 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(this.payload.config, global)\n\n buildTable({\n adapter: this,\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":["uniqueIndex","buildVersionCollectionFields","buildVersionGlobalFields","toSnakeCase","createTableName","buildTable","init","payload","config","localization","enums","enum__locales","pgSchema","enum","locales","map","code","collections","forEach","collection","
|
|
1
|
+
{"version":3,"sources":["../../src/postgres/init.ts"],"sourcesContent":["import type { Init, SanitizedCollectionConfig } from 'payload'\n\nimport { uniqueIndex } from 'drizzle-orm/pg-core'\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { BaseExtraConfig, BasePostgresAdapter } from './types.js'\n\nimport { createTableName } from '../createTableName.js'\nimport { executeSchemaHooks } from '../utilities/executeSchemaHooks.js'\nimport { buildTable } from './schema/build.js'\n\nexport const init: Init = async function init(this: BasePostgresAdapter) {\n await executeSchemaHooks({ type: 'beforeSchemaInit', adapter: this })\n\n if (this.payload.config.localization) {\n this.enums.enum__locales = this.pgSchema.enum(\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 createTableName({\n adapter: this,\n config: collection,\n })\n\n if (collection.versions) {\n createTableName({\n adapter: this,\n config: collection,\n versions: true,\n versionsCustomName: true,\n })\n }\n })\n this.payload.config.collections.forEach((collection: SanitizedCollectionConfig) => {\n const tableName = this.tableNameMap.get(toSnakeCase(collection.slug))\n\n const baseExtraConfig: BaseExtraConfig = {}\n\n if (collection.upload.filenameCompoundIndex) {\n const indexName = `${tableName}_filename_compound_idx`\n\n baseExtraConfig.filename_compound_index = (cols) => {\n const colsConstraint = collection.upload.filenameCompoundIndex.map((f) => {\n return cols[f]\n })\n return uniqueIndex(indexName).on(colsConstraint[0], ...colsConstraint.slice(1))\n }\n }\n\n buildTable({\n adapter: this,\n baseExtraConfig,\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 = this.tableNameMap.get(\n `_${toSnakeCase(collection.slug)}${this.versionsSuffix}`,\n )\n const versionFields = buildVersionCollectionFields(this.payload.config, collection)\n\n buildTable({\n adapter: this,\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 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(this.payload.config, global)\n\n buildTable({\n adapter: this,\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 await executeSchemaHooks({ type: 'afterSchemaInit', adapter: this })\n}\n"],"names":["uniqueIndex","buildVersionCollectionFields","buildVersionGlobalFields","toSnakeCase","createTableName","executeSchemaHooks","buildTable","init","type","adapter","payload","config","localization","enums","enum__locales","pgSchema","enum","locales","map","code","collections","forEach","collection","versions","versionsCustomName","tableName","tableNameMap","get","slug","baseExtraConfig","upload","filenameCompoundIndex","indexName","filename_compound_index","cols","colsConstraint","f","on","slice","disableNotNull","drafts","disableUnique","fields","timestamps","versionsTableName","versionsSuffix","versionFields","globals","global"],"mappings":"AAEA,SAASA,WAAW,QAAQ,sBAAqB;AACjD,SAASC,4BAA4B,EAAEC,wBAAwB,QAAQ,UAAS;AAChF,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,eAAe,QAAQ,wBAAuB;AACvD,SAASC,kBAAkB,QAAQ,qCAAoC;AACvE,SAASC,UAAU,QAAQ,oBAAmB;AAE9C,OAAO,MAAMC,OAAa,eAAeA;IACvC,MAAMF,mBAAmB;QAAEG,MAAM;QAAoBC,SAAS,IAAI;IAAC;IAEnE,IAAI,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,YAAY,EAAE;QACpC,IAAI,CAACC,KAAK,CAACC,aAAa,GAAG,IAAI,CAACC,QAAQ,CAACC,IAAI,CAC3C,YACA,IAAI,CAAC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B,cAAc,CAAC,CAAC;YAE1D,MAAMC,gBAAgB7C,6BAA6B,IAAI,CAACS,OAAO,CAACC,MAAM,EAAEW;YAExEhB,WAAW;gBACTG,SAAS,IAAI;gBACb8B,gBAAgB,CAAC,CAACjB,WAAWC,QAAQ,EAAEiB;gBACvCC,eAAe;gBACfC,QAAQI;gBACRrB,WAAWmB;gBACXD,YAAY;gBACZpB,UAAU;YACZ;QACF;IACF;IAEA,IAAI,CAACb,OAAO,CAACC,MAAM,CAACoC,OAAO,CAAC1B,OAAO,CAAC,CAAC2B;QACnC,MAAMvB,YAAYrB,gBAAgB;YAAEK,SAAS,IAAI;YAAEE,QAAQqC;QAAO;QAElE1C,WAAW;YACTG,SAAS,IAAI;YACb8B,gBAAgB,CAAC,CAACS,QAAQzB,UAAUiB;YACpCC,eAAe;YACfC,QAAQM,OAAON,MAAM;YACrBjB;YACAkB,YAAY;YACZpB,UAAU;QACZ;QAEA,IAAIyB,OAAOzB,QAAQ,EAAE;YACnB,MAAMqB,oBAAoBxC,gBAAgB;gBACxCK,SAAS,IAAI;gBACbE,QAAQqC;gBACRzB,UAAU;gBACVC,oBAAoB;YACtB;YACA,MAAMsB,gBAAgB5C,yBAAyB,IAAI,CAACQ,OAAO,CAACC,MAAM,EAAEqC;YAEpE1C,WAAW;gBACTG,SAAS,IAAI;gBACb8B,gBAAgB,CAAC,CAACS,OAAOzB,QAAQ,EAAEiB;gBACnCC,eAAe;gBACfC,QAAQI;gBACRrB,WAAWmB;gBACXD,YAAY;gBACZpB,UAAU;YACZ;QACF;IACF;IAEA,MAAMlB,mBAAmB;QAAEG,MAAM;QAAmBC,SAAS,IAAI;IAAC;AACpE,EAAC"}
|
|
@@ -12,12 +12,14 @@ type Args = {
|
|
|
12
12
|
buildNumbers?: boolean;
|
|
13
13
|
buildRelationships?: boolean;
|
|
14
14
|
disableNotNull: boolean;
|
|
15
|
+
disableRelsTableUnique?: boolean;
|
|
15
16
|
disableUnique: boolean;
|
|
16
17
|
fields: Field[];
|
|
17
18
|
rootRelationships?: Set<string>;
|
|
18
19
|
rootRelationsToBuild?: RelationMap;
|
|
19
20
|
rootTableIDColType?: string;
|
|
20
21
|
rootTableName?: string;
|
|
22
|
+
rootUniqueRelationships?: Set<string>;
|
|
21
23
|
tableName: string;
|
|
22
24
|
timestamps?: boolean;
|
|
23
25
|
versions: boolean;
|
|
@@ -35,6 +37,6 @@ type Result = {
|
|
|
35
37
|
hasManyTextField: 'index' | boolean;
|
|
36
38
|
relationsToBuild: RelationMap;
|
|
37
39
|
};
|
|
38
|
-
export declare const buildTable: ({ adapter, baseColumns, baseExtraConfig, disableNotNull, disableUnique, fields, rootRelationships, rootRelationsToBuild, rootTableIDColType, rootTableName: incomingRootTableName, tableName, timestamps, versions, withinLocalizedArrayOrBlock, }: Args) => Result;
|
|
40
|
+
export declare const buildTable: ({ adapter, baseColumns, baseExtraConfig, disableNotNull, disableRelsTableUnique, disableUnique, fields, rootRelationships, rootRelationsToBuild, rootTableIDColType, rootTableName: incomingRootTableName, rootUniqueRelationships, tableName, timestamps, versions, withinLocalizedArrayOrBlock, }: Args) => Result;
|
|
39
41
|
export {};
|
|
40
42
|
//# sourceMappingURL=build.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/postgres/schema/build.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGV,eAAe,EAEhB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/postgres/schema/build.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGV,eAAe,EAEhB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,KAAK,EAAkB,MAAM,SAAS,CAAA;AAepD,OAAO,KAAK,EACV,eAAe,EACf,mBAAmB,EAInB,WAAW,EACZ,MAAM,aAAa,CAAA;AASpB,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,mBAAmB,CAAA;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;IAC7C;;;OAGG;IACH,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,cAAc,EAAE,OAAO,CAAA;IACvB,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC,aAAa,EAAE,OAAO,CAAA;IACtB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,iBAAiB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAC/B,oBAAoB,CAAC,EAAE,WAAW,CAAA;IAClC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,uBAAuB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACrC,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,QAAQ,EAAE,OAAO,CAAA;IACjB;;;OAGG;IACH,2BAA2B,CAAC,EAAE,OAAO,CAAA;CACtC,CAAA;AAED,KAAK,MAAM,GAAG;IACZ,2BAA2B,EAAE,OAAO,CAAA;IACpC,yBAAyB,EAAE,OAAO,CAAA;IAClC,6BAA6B,EAAE,OAAO,CAAA;IACtC,kBAAkB,EAAE,OAAO,GAAG,OAAO,CAAA;IACrC,gBAAgB,EAAE,OAAO,GAAG,OAAO,CAAA;IACnC,gBAAgB,EAAE,WAAW,CAAA;CAC9B,CAAA;AAED,eAAO,MAAM,UAAU,wSAiBpB,IAAI,KAAG,MA4aT,CAAA"}
|
|
@@ -2,10 +2,12 @@ import { relations } from 'drizzle-orm';
|
|
|
2
2
|
import { foreignKey, index, integer, numeric, serial, timestamp, unique, varchar } from 'drizzle-orm/pg-core';
|
|
3
3
|
import toSnakeCase from 'to-snake-case';
|
|
4
4
|
import { createTableName } from '../../createTableName.js';
|
|
5
|
+
import { buildIndexName } from '../../utilities/buildIndexName.js';
|
|
6
|
+
import { createIndex } from './createIndex.js';
|
|
5
7
|
import { parentIDColumnMap } from './parentIDColumnMap.js';
|
|
6
8
|
import { setColumnID } from './setColumnID.js';
|
|
7
9
|
import { traverseFields } from './traverseFields.js';
|
|
8
|
-
export const buildTable = ({ adapter, baseColumns = {}, baseExtraConfig = {}, disableNotNull, disableUnique = false, fields, rootRelationships, rootRelationsToBuild, rootTableIDColType, rootTableName: incomingRootTableName, tableName, timestamps, versions, withinLocalizedArrayOrBlock })=>{
|
|
10
|
+
export const buildTable = ({ adapter, baseColumns = {}, baseExtraConfig = {}, disableNotNull, disableRelsTableUnique = false, disableUnique = false, fields, rootRelationships, rootRelationsToBuild, rootTableIDColType, rootTableName: incomingRootTableName, rootUniqueRelationships, tableName, timestamps, versions, withinLocalizedArrayOrBlock })=>{
|
|
9
11
|
const isRoot = !incomingRootTableName;
|
|
10
12
|
const rootTableName = incomingRootTableName || tableName;
|
|
11
13
|
const columns = baseColumns;
|
|
@@ -17,6 +19,8 @@ export const buildTable = ({ adapter, baseColumns = {}, baseExtraConfig = {}, di
|
|
|
17
19
|
let numbersTable;
|
|
18
20
|
// Relationships to the base collection
|
|
19
21
|
const relationships = rootRelationships || new Set();
|
|
22
|
+
// Unique relationships to the base collection
|
|
23
|
+
const uniqueRelationships = rootUniqueRelationships || new Set();
|
|
20
24
|
let relationshipsTable;
|
|
21
25
|
// Drizzle relations
|
|
22
26
|
const relationsToBuild = new Map();
|
|
@@ -29,6 +33,7 @@ export const buildTable = ({ adapter, baseColumns = {}, baseExtraConfig = {}, di
|
|
|
29
33
|
adapter,
|
|
30
34
|
columns,
|
|
31
35
|
disableNotNull,
|
|
36
|
+
disableRelsTableUnique,
|
|
32
37
|
disableUnique,
|
|
33
38
|
fields,
|
|
34
39
|
indexes,
|
|
@@ -41,6 +46,7 @@ export const buildTable = ({ adapter, baseColumns = {}, baseExtraConfig = {}, di
|
|
|
41
46
|
rootRelationsToBuild: rootRelationsToBuild || relationsToBuild,
|
|
42
47
|
rootTableIDColType: rootTableIDColType || idColType,
|
|
43
48
|
rootTableName,
|
|
49
|
+
uniqueRelationships,
|
|
44
50
|
versions,
|
|
45
51
|
withinLocalizedArrayOrBlock
|
|
46
52
|
});
|
|
@@ -255,16 +261,36 @@ export const buildTable = ({ adapter, baseColumns = {}, baseExtraConfig = {}, di
|
|
|
255
261
|
if (relatedCollectionCustomIDType === 'text') {
|
|
256
262
|
colType = 'varchar';
|
|
257
263
|
}
|
|
258
|
-
|
|
264
|
+
const colName = `${relationTo}ID`;
|
|
265
|
+
relationshipColumns[colName] = parentIDColumnMap[colType](`${formattedRelationTo}_id`);
|
|
259
266
|
relationExtraConfig[`${relationTo}IdFk`] = (cols)=>foreignKey({
|
|
260
267
|
name: `${relationshipsTableName}_${toSnakeCase(relationTo)}_fk`,
|
|
261
268
|
columns: [
|
|
262
|
-
cols[
|
|
269
|
+
cols[colName]
|
|
263
270
|
],
|
|
264
271
|
foreignColumns: [
|
|
265
272
|
adapter.tables[formattedRelationTo].id
|
|
266
273
|
]
|
|
267
274
|
}).onDelete('cascade');
|
|
275
|
+
const indexColumns = [
|
|
276
|
+
colName
|
|
277
|
+
];
|
|
278
|
+
const unique = !disableUnique && uniqueRelationships.has(relationTo);
|
|
279
|
+
if (unique) {
|
|
280
|
+
indexColumns.push('path');
|
|
281
|
+
}
|
|
282
|
+
if (hasLocalizedRelationshipField) {
|
|
283
|
+
indexColumns.push('locale');
|
|
284
|
+
}
|
|
285
|
+
const indexName = buildIndexName({
|
|
286
|
+
name: `${relationshipsTableName}_${formattedRelationTo}_id`,
|
|
287
|
+
adapter
|
|
288
|
+
});
|
|
289
|
+
relationExtraConfig[indexName] = createIndex({
|
|
290
|
+
name: indexColumns,
|
|
291
|
+
indexName,
|
|
292
|
+
unique
|
|
293
|
+
});
|
|
268
294
|
});
|
|
269
295
|
relationshipsTable = adapter.pgSchema.table(relationshipsTableName, relationshipColumns, (cols)=>{
|
|
270
296
|
const result = Object.entries(relationExtraConfig).reduce((config, [key, func])=>{
|