@payloadcms/drizzle 3.5.1-canary.d9bd64a → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/exports/postgres.d.ts +1 -2
- package/dist/exports/postgres.d.ts.map +1 -1
- package/dist/exports/postgres.js +1 -2
- package/dist/exports/postgres.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/migrateDown.d.ts.map +1 -1
- package/dist/migrateDown.js +2 -0
- package/dist/migrateDown.js.map +1 -1
- package/dist/migrateFresh.d.ts.map +1 -1
- package/dist/migrateFresh.js +1 -2
- package/dist/migrateFresh.js.map +1 -1
- package/dist/migrateRefresh.d.ts.map +1 -1
- package/dist/migrateRefresh.js +2 -0
- package/dist/migrateRefresh.js.map +1 -1
- package/dist/migrateReset.d.ts.map +1 -1
- package/dist/migrateReset.js +2 -0
- package/dist/migrateReset.js.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts +20 -0
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.js +169 -0
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts +11 -0
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js +149 -0
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts +3 -0
- package/dist/postgres/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/groupUpSQLStatements.js +56 -0
- package/dist/postgres/predefinedMigrations/v2-v3/groupUpSQLStatements.js.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/index.d.ts +23 -0
- package/dist/postgres/predefinedMigrations/v2-v3/index.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/index.js +212 -0
- package/dist/postgres/predefinedMigrations/v2-v3/index.js.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/migrateRelationships.d.ts +20 -0
- package/dist/postgres/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/migrateRelationships.js +63 -0
- package/dist/postgres/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/traverseFields.d.ts +23 -0
- package/dist/postgres/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/traverseFields.js +60 -0
- package/dist/postgres/predefinedMigrations/v2-v3/traverseFields.js.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/types.d.ts +9 -0
- package/dist/postgres/predefinedMigrations/v2-v3/types.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/types.js +6 -0
- package/dist/postgres/predefinedMigrations/v2-v3/types.js.map +1 -0
- package/dist/postgres/requireDrizzleKit.d.ts.map +1 -1
- package/dist/postgres/requireDrizzleKit.js +9 -1
- package/dist/postgres/requireDrizzleKit.js.map +1 -1
- package/dist/postgres/types.d.ts +54 -0
- package/dist/postgres/types.d.ts.map +1 -1
- package/dist/postgres/types.js.map +1 -1
- package/dist/types.d.ts +5 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/buildCreateMigration.d.ts +10 -0
- package/dist/utilities/buildCreateMigration.d.ts.map +1 -0
- package/dist/utilities/buildCreateMigration.js +98 -0
- package/dist/utilities/buildCreateMigration.js.map +1 -0
- package/dist/utilities/getMigrationTemplate.d.ts +4 -0
- package/dist/utilities/getMigrationTemplate.d.ts.map +1 -0
- package/dist/utilities/getMigrationTemplate.js +13 -0
- package/dist/utilities/getMigrationTemplate.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { FlattenedField, Payload } from 'payload';
|
|
2
|
+
import type { TransactionPg } from '../../../types.js';
|
|
3
|
+
import type { BasePostgresAdapter } from '../../types.js';
|
|
4
|
+
import type { PathsToQuery } from './types.js';
|
|
5
|
+
type Args = {
|
|
6
|
+
adapter: BasePostgresAdapter;
|
|
7
|
+
collectionSlug?: string;
|
|
8
|
+
columnPrefix: string;
|
|
9
|
+
db: TransactionPg;
|
|
10
|
+
disableNotNull: boolean;
|
|
11
|
+
fields: FlattenedField[];
|
|
12
|
+
globalSlug?: string;
|
|
13
|
+
isVersions: boolean;
|
|
14
|
+
newTableName: string;
|
|
15
|
+
parentTableName: string;
|
|
16
|
+
path: string;
|
|
17
|
+
pathsToQuery: PathsToQuery;
|
|
18
|
+
payload: Payload;
|
|
19
|
+
rootTableName: string;
|
|
20
|
+
};
|
|
21
|
+
export declare const traverseFields: (args: Args) => void;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=traverseFields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../../../src/postgres/predefinedMigrations/v2-v3/traverseFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAItD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE9C,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,mBAAmB,CAAA;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,YAAY,EAAE,MAAM,CAAA;IACpB,EAAE,EAAE,aAAa,CAAA;IACjB,cAAc,EAAE,OAAO,CAAA;IACvB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,OAAO,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,eAAe,EAAE,MAAM,CAAA;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,YAAY,CAAA;IAC1B,OAAO,EAAE,OAAO,CAAA;IAChB,aAAa,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,eAAO,MAAM,cAAc,SAAU,IAAI,SAgExC,CAAA"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import toSnakeCase from 'to-snake-case';
|
|
2
|
+
export const traverseFields = (args)=>{
|
|
3
|
+
args.fields.forEach((field)=>{
|
|
4
|
+
switch(field.type){
|
|
5
|
+
case 'array':
|
|
6
|
+
{
|
|
7
|
+
const newTableName = args.adapter.tableNameMap.get(`${args.newTableName}_${toSnakeCase(field.name)}`);
|
|
8
|
+
return traverseFields({
|
|
9
|
+
...args,
|
|
10
|
+
columnPrefix: '',
|
|
11
|
+
fields: field.flattenedFields,
|
|
12
|
+
newTableName,
|
|
13
|
+
parentTableName: newTableName,
|
|
14
|
+
path: `${args.path ? `${args.path}.` : ''}${field.name}.%`
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
case 'blocks':
|
|
18
|
+
{
|
|
19
|
+
return field.blocks.forEach((block)=>{
|
|
20
|
+
const newTableName = args.adapter.tableNameMap.get(`${args.rootTableName}_blocks_${toSnakeCase(block.slug)}`);
|
|
21
|
+
traverseFields({
|
|
22
|
+
...args,
|
|
23
|
+
columnPrefix: '',
|
|
24
|
+
fields: block.flattenedFields,
|
|
25
|
+
newTableName,
|
|
26
|
+
parentTableName: newTableName,
|
|
27
|
+
path: `${args.path ? `${args.path}.` : ''}${field.name}.%`
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
case 'group':
|
|
32
|
+
case 'tab':
|
|
33
|
+
{
|
|
34
|
+
let newTableName = `${args.newTableName}_${toSnakeCase(field.name)}`;
|
|
35
|
+
if (field.localized && args.payload.config.localization) {
|
|
36
|
+
newTableName += args.adapter.localesSuffix;
|
|
37
|
+
}
|
|
38
|
+
return traverseFields({
|
|
39
|
+
...args,
|
|
40
|
+
columnPrefix: `${args.columnPrefix}${toSnakeCase(field.name)}_`,
|
|
41
|
+
fields: field.flattenedFields,
|
|
42
|
+
newTableName,
|
|
43
|
+
path: `${args.path ? `${args.path}.` : ''}${field.name}`
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
case 'relationship':
|
|
47
|
+
case 'upload':
|
|
48
|
+
{
|
|
49
|
+
if (typeof field.relationTo === 'string') {
|
|
50
|
+
if (field.type === 'upload' || !field.hasMany) {
|
|
51
|
+
args.pathsToQuery.add(`${args.path ? `${args.path}.` : ''}${field.name}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=traverseFields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/postgres/predefinedMigrations/v2-v3/traverseFields.ts"],"sourcesContent":["import type { FlattenedField, Payload } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { TransactionPg } from '../../../types.js'\nimport type { BasePostgresAdapter } from '../../types.js'\nimport type { PathsToQuery } from './types.js'\n\ntype Args = {\n adapter: BasePostgresAdapter\n collectionSlug?: string\n columnPrefix: string\n db: TransactionPg\n disableNotNull: boolean\n fields: FlattenedField[]\n globalSlug?: string\n isVersions: boolean\n newTableName: string\n parentTableName: string\n path: string\n pathsToQuery: PathsToQuery\n payload: Payload\n rootTableName: string\n}\n\nexport const traverseFields = (args: Args) => {\n args.fields.forEach((field) => {\n switch (field.type) {\n case 'array': {\n const newTableName = args.adapter.tableNameMap.get(\n `${args.newTableName}_${toSnakeCase(field.name)}`,\n )\n\n return traverseFields({\n ...args,\n columnPrefix: '',\n fields: field.flattenedFields,\n newTableName,\n parentTableName: newTableName,\n path: `${args.path ? `${args.path}.` : ''}${field.name}.%`,\n })\n }\n\n case 'blocks': {\n return field.blocks.forEach((block) => {\n const newTableName = args.adapter.tableNameMap.get(\n `${args.rootTableName}_blocks_${toSnakeCase(block.slug)}`,\n )\n\n traverseFields({\n ...args,\n columnPrefix: '',\n fields: block.flattenedFields,\n newTableName,\n parentTableName: newTableName,\n path: `${args.path ? `${args.path}.` : ''}${field.name}.%`,\n })\n })\n }\n\n case 'group':\n case 'tab': {\n let newTableName = `${args.newTableName}_${toSnakeCase(field.name)}`\n\n if (field.localized && args.payload.config.localization) {\n newTableName += args.adapter.localesSuffix\n }\n\n return traverseFields({\n ...args,\n columnPrefix: `${args.columnPrefix}${toSnakeCase(field.name)}_`,\n fields: field.flattenedFields,\n newTableName,\n path: `${args.path ? `${args.path}.` : ''}${field.name}`,\n })\n }\n\n case 'relationship':\n case 'upload': {\n if (typeof field.relationTo === 'string') {\n if (field.type === 'upload' || !field.hasMany) {\n args.pathsToQuery.add(`${args.path ? `${args.path}.` : ''}${field.name}`)\n }\n }\n\n return null\n }\n }\n })\n}\n"],"names":["toSnakeCase","traverseFields","args","fields","forEach","field","type","newTableName","adapter","tableNameMap","get","name","columnPrefix","flattenedFields","parentTableName","path","blocks","block","rootTableName","slug","localized","payload","config","localization","localesSuffix","relationTo","hasMany","pathsToQuery","add"],"mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAuBvC,OAAO,MAAMC,iBAAiB,CAACC;IAC7BA,KAAKC,MAAM,CAACC,OAAO,CAAC,CAACC;QACnB,OAAQA,MAAMC,IAAI;YAChB,KAAK;gBAAS;oBACZ,MAAMC,eAAeL,KAAKM,OAAO,CAACC,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,KAAKa,IAAI,GAAG,GAAGb,KAAKa,IAAI,CAAC,CAAC,CAAC,GAAG,KAAKV,MAAMM,IAAI,EAAE;oBAC1D;gBACF;YAEA,KAAK;YACL,KAAK;gBAAU;oBACb,IAAI,OAAON,MAAMoB,UAAU,KAAK,UAAU;wBACxC,IAAIpB,MAAMC,IAAI,KAAK,YAAY,CAACD,MAAMqB,OAAO,EAAE;4BAC7CxB,KAAKyB,YAAY,CAACC,GAAG,CAAC,GAAG1B,KAAKa,IAAI,GAAG,GAAGb,KAAKa,IAAI,CAAC,CAAC,CAAC,GAAG,KAAKV,MAAMM,IAAI,EAAE;wBAC1E;oBACF;oBAEA,OAAO;gBACT;QACF;IACF;AACF,EAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Set of all paths which should be moved
|
|
3
|
+
* This will be built up into one WHERE query
|
|
4
|
+
*/
|
|
5
|
+
export type PathsToQuery = Set<string>;
|
|
6
|
+
export type DocsToResave = {
|
|
7
|
+
[id: number | string]: Record<string, unknown>[];
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/postgres/predefinedMigrations/v2-v3/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,GAAG,CAAC,MAAM,CAAC,CAAA;AAEtC,MAAM,MAAM,YAAY,GAAG;IACzB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;CACjD,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/postgres/predefinedMigrations/v2-v3/types.ts"],"sourcesContent":["/**\n * Set of all paths which should be moved\n * This will be built up into one WHERE query\n */\nexport type PathsToQuery = Set<string>\n\nexport type DocsToResave = {\n [id: number | string]: Record<string, unknown>[]\n}\n"],"names":[],"mappings":"AAAA;;;CAGC,GAGD,WAEC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requireDrizzleKit.d.ts","sourceRoot":"","sources":["../../src/postgres/requireDrizzleKit.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"requireDrizzleKit.d.ts","sourceRoot":"","sources":["../../src/postgres/requireDrizzleKit.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAIpD,eAAO,MAAM,iBAAiB,EAAE,iBAc/B,CAAA"}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { createRequire } from 'module';
|
|
2
2
|
const require = createRequire(import.meta.url);
|
|
3
|
-
export const requireDrizzleKit = ()=>
|
|
3
|
+
export const requireDrizzleKit = ()=>{
|
|
4
|
+
const { generateDrizzleJson, generateMigration, pushSchema, upPgSnapshot } = require('drizzle-kit/api');
|
|
5
|
+
return {
|
|
6
|
+
generateDrizzleJson,
|
|
7
|
+
generateMigration,
|
|
8
|
+
pushSchema,
|
|
9
|
+
upSnapshot: upPgSnapshot
|
|
10
|
+
};
|
|
11
|
+
};
|
|
4
12
|
|
|
5
13
|
//# sourceMappingURL=requireDrizzleKit.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/postgres/requireDrizzleKit.ts"],"sourcesContent":["import { createRequire } from 'module'\n\nimport type { RequireDrizzleKit } from '../types.js'\n\nconst require = createRequire(import.meta.url)\nexport const requireDrizzleKit: RequireDrizzleKit = () => require('drizzle-kit/api')\n"],"names":["createRequire","require","url","requireDrizzleKit"],"mappings":"AAAA,SAASA,aAAa,QAAQ,SAAQ;AAItC,MAAMC,UAAUD,cAAc,YAAYE,GAAG;
|
|
1
|
+
{"version":3,"sources":["../../src/postgres/requireDrizzleKit.ts"],"sourcesContent":["import { createRequire } from 'module'\n\nimport type { RequireDrizzleKit } from '../types.js'\n\nconst require = createRequire(import.meta.url)\n\nexport const requireDrizzleKit: RequireDrizzleKit = () => {\n const {\n generateDrizzleJson,\n generateMigration,\n pushSchema,\n upPgSnapshot,\n } = require('drizzle-kit/api')\n\n return {\n generateDrizzleJson,\n generateMigration,\n pushSchema,\n upSnapshot: upPgSnapshot,\n }\n}\n"],"names":["createRequire","require","url","requireDrizzleKit","generateDrizzleJson","generateMigration","pushSchema","upPgSnapshot","upSnapshot"],"mappings":"AAAA,SAASA,aAAa,QAAQ,SAAQ;AAItC,MAAMC,UAAUD,cAAc,YAAYE,GAAG;AAE7C,OAAO,MAAMC,oBAAuC;IAClD,MAAM,EACJC,mBAAmB,EACnBC,iBAAiB,EACjBC,UAAU,EACVC,YAAY,EACb,GAAGN,QAAQ;IAEZ,OAAO;QACLG;QACAC;QACAC;QACAE,YAAYD;IACd;AACF,EAAC"}
|
package/dist/postgres/types.d.ts
CHANGED
|
@@ -131,11 +131,65 @@ export type BasePostgresAdapter = {
|
|
|
131
131
|
export type PostgresDrizzleAdapter = Omit<DrizzleAdapter, 'countDistinct' | 'deleteWhere' | 'drizzle' | 'dropDatabase' | 'execute' | 'insert' | 'operators' | 'relations'>;
|
|
132
132
|
export type IDType = 'integer' | 'numeric' | 'uuid' | 'varchar';
|
|
133
133
|
export type MigrateUpArgs = {
|
|
134
|
+
/**
|
|
135
|
+
* The Postgres Drizzle instance that you can use to execute SQL directly within the current transaction.
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* import { type MigrateUpArgs, sql } from '@payloadcms/db-postgres'
|
|
139
|
+
*
|
|
140
|
+
* export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
|
|
141
|
+
* const { rows: posts } = await db.execute(sql`SELECT * FROM posts`)
|
|
142
|
+
* }
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
db: PostgresDB;
|
|
146
|
+
/**
|
|
147
|
+
* The Payload instance that you can use to execute Local API methods
|
|
148
|
+
* To use the current transaction you must pass `req` to arguments
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* import { type MigrateUpArgs, sql } from '@payloadcms/db-postgres'
|
|
152
|
+
*
|
|
153
|
+
* export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
|
|
154
|
+
* const posts = await payload.find({ collection: 'posts', req })
|
|
155
|
+
* }
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
134
158
|
payload: Payload;
|
|
159
|
+
/**
|
|
160
|
+
* The `PayloadRequest` object that contains the current transaction
|
|
161
|
+
*/
|
|
135
162
|
req: PayloadRequest;
|
|
136
163
|
};
|
|
137
164
|
export type MigrateDownArgs = {
|
|
165
|
+
/**
|
|
166
|
+
* The Postgres Drizzle instance that you can use to execute SQL directly within the current transaction.
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts
|
|
169
|
+
* import { type MigrateDownArgs, sql } from '@payloadcms/db-postgres'
|
|
170
|
+
*
|
|
171
|
+
* export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
|
|
172
|
+
* const { rows: posts } = await db.execute(sql`SELECT * FROM posts`)
|
|
173
|
+
* }
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
db: PostgresDB;
|
|
177
|
+
/**
|
|
178
|
+
* The Payload instance that you can use to execute Local API methods
|
|
179
|
+
* To use the current transaction you must pass `req` to arguments
|
|
180
|
+
* @example
|
|
181
|
+
* ```ts
|
|
182
|
+
* import { type MigrateDownArgs } from '@payloadcms/db-postgres'
|
|
183
|
+
*
|
|
184
|
+
* export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
|
|
185
|
+
* const posts = await payload.find({ collection: 'posts', req })
|
|
186
|
+
* }
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
138
189
|
payload: Payload;
|
|
190
|
+
/**
|
|
191
|
+
* The `PayloadRequest` object that contains the current transaction
|
|
192
|
+
*/
|
|
139
193
|
req: PayloadRequest;
|
|
140
194
|
};
|
|
141
195
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/postgres/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,KAAK,EACV,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,QAAQ,EACR,SAAS,EACT,GAAG,EACJ,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC/D,OAAO,KAAK,EACV,iBAAiB,EACjB,YAAY,EACZ,QAAQ,EACR,MAAM,EACN,MAAM,EACN,gCAAgC,EAChC,QAAQ,EACR,kBAAkB,EAClB,uBAAuB,EACxB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAC1D,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,IAAI,CAAA;AAEnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAChE,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEvF,MAAM,MAAM,eAAe,GAAG,MAAM,CAClC,MAAM,EACN,CAAC,IAAI,EAAE,cAAc,KAAK,iBAAiB,GAAG,YAAY,GAAG,uBAAuB,CACrF,CAAA;AAED,MAAM,MAAM,WAAW,GAAG,GAAG,CAC3B,MAAM,EACN;IACE,SAAS,EAAE,OAAO,CAAA;IAClB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,GAAG,KAAK,CAAA;CACrB,CACF,CAAA;AAED,MAAM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OAAO,EAAE,OAAO,CAAA;IAChB;;OAEG;IACH,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B;;;;;;;;;;OAUG;IACH,EAAE,EAAE,UAAU,CAAA;IACd;;;;;;;;;;;OAWG;IACH,OAAO,EAAE,OAAO,CAAA;IAChB;;OAEG;IACH,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/postgres/types.ts"],"sourcesContent":["import type { DrizzleSnapshotJSON } from 'drizzle-kit/api'\nimport type {\n ColumnBaseConfig,\n ColumnDataType,\n DrizzleConfig,\n Relation,\n Relations,\n SQL,\n} from 'drizzle-orm'\nimport type { NodePgDatabase } from 'drizzle-orm/node-postgres'\nimport type {\n ForeignKeyBuilder,\n IndexBuilder,\n PgColumn,\n PgEnum,\n pgEnum,\n PgInsertOnConflictDoUpdateConfig,\n PgSchema,\n PgTableWithColumns,\n UniqueConstraintBuilder,\n} from 'drizzle-orm/pg-core'\nimport type { PgTableFn } from 'drizzle-orm/pg-core/table'\nimport type { Payload, PayloadRequest } from 'payload'\nimport type { ClientConfig, QueryResult } from 'pg'\n\nimport type { extendDrizzleTable, Operators } from '../index.js'\nimport type { BuildQueryJoinAliases, DrizzleAdapter, TransactionPg } from '../types.js'\n\nexport type BaseExtraConfig = Record<\n string,\n (cols: GenericColumns) => ForeignKeyBuilder | IndexBuilder | UniqueConstraintBuilder\n>\n\nexport type RelationMap = Map<\n string,\n {\n localized: boolean\n relationName?: string\n target: string\n type: 'many' | 'one'\n }\n>\n\nexport type GenericColumn = PgColumn<\n ColumnBaseConfig<ColumnDataType, string>,\n Record<string, unknown>\n>\n\nexport type GenericColumns = {\n [x: string]: GenericColumn\n}\n\nexport type GenericTable = PgTableWithColumns<{\n columns: GenericColumns\n dialect: string\n name: string\n schema: string\n}>\n\nexport type GenericEnum = PgEnum<[string, ...string[]]>\n\nexport type GenericRelation = Relations<string, Record<string, Relation<string>>>\n\nexport type PostgresDB = NodePgDatabase<Record<string, unknown>>\n\nexport type CountDistinct = (args: {\n db: PostgresDB | TransactionPg\n joins: BuildQueryJoinAliases\n tableName: string\n where: SQL\n}) => Promise<number>\n\nexport type DeleteWhere = (args: {\n db: PostgresDB | TransactionPg\n tableName: string\n where: SQL\n}) => Promise<void>\n\nexport type DropDatabase = (args: { adapter: BasePostgresAdapter }) => Promise<void>\n\nexport type Execute<T> = (args: {\n db?: PostgresDB | TransactionPg\n drizzle?: PostgresDB\n raw?: string\n sql?: SQL<unknown>\n}) => Promise<QueryResult<Record<string, T>>>\n\nexport type Insert = (args: {\n db: PostgresDB | TransactionPg\n onConflictDoUpdate?: PgInsertOnConflictDoUpdateConfig<any>\n tableName: string\n values: Record<string, unknown> | Record<string, unknown>[]\n}) => Promise<Record<string, unknown>[]>\n\nexport type CreateDatabase = (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 from adapter.schemaName if exists.\n */\n schemaName?: string\n}) => Promise<boolean>\n\ntype Schema =\n | {\n enum: typeof pgEnum\n table: PgTableFn<string>\n }\n | PgSchema\n\ntype PostgresSchema = {\n enums: Record<string, GenericEnum>\n relations: Record<string, GenericRelation>\n tables: Record<string, PgTableWithColumns<any>>\n}\n\ntype PostgresSchemaHookArgs = {\n adapter: PostgresDrizzleAdapter\n extendTable: typeof extendDrizzleTable\n schema: PostgresSchema\n}\n\nexport type PostgresSchemaHook = (\n args: PostgresSchemaHookArgs,\n) => PostgresSchema | Promise<PostgresSchema>\n\nexport type BasePostgresAdapter = {\n afterSchemaInit: PostgresSchemaHook[]\n beforeSchemaInit: PostgresSchemaHook[]\n countDistinct: CountDistinct\n createDatabase: CreateDatabase\n createExtensions: () => Promise<void>\n defaultDrizzleSnapshot: DrizzleSnapshotJSON\n deleteWhere: DeleteWhere\n disableCreateDatabase: boolean\n drizzle: PostgresDB\n dropDatabase: DropDatabase\n enums: Record<string, GenericEnum>\n execute: Execute<unknown>\n extensions: Record<string, boolean>\n /**\n * An object keyed on each table, with a key value pair where the constraint name is the key, followed by the dot-notation field name\n * Used for returning properly formed errors from unique fields\n */\n fieldConstraints: Record<string, Record<string, string>>\n idType: 'serial' | 'uuid'\n initializing: Promise<void>\n insert: Insert\n localesSuffix?: string\n logger: DrizzleConfig['logger']\n operators: Operators\n pgSchema: Schema\n poolOptions?: ClientConfig\n prodMigrations?: {\n down: (args: MigrateDownArgs) => Promise<void>\n name: string\n up: (args: MigrateUpArgs) => Promise<void>\n }[]\n push: boolean\n rejectInitializing: () => void\n relations: Record<string, GenericRelation>\n relationshipsSuffix?: string\n resolveInitializing: () => void\n schemaName?: string\n sessions: {\n [id: string]: {\n db: PostgresDB | TransactionPg\n reject: () => Promise<void>\n resolve: () => Promise<void>\n }\n }\n tableNameMap: Map<string, string>\n tables: Record<string, GenericTable>\n tablesFilter?: string[]\n versionsSuffix?: string\n} & PostgresDrizzleAdapter\n\nexport type PostgresDrizzleAdapter = Omit<\n DrizzleAdapter,\n | 'countDistinct'\n | 'deleteWhere'\n | 'drizzle'\n | 'dropDatabase'\n | 'execute'\n | 'insert'\n | 'operators'\n | 'relations'\n>\n\nexport type IDType = 'integer' | 'numeric' | 'uuid' | 'varchar'\n\nexport type MigrateUpArgs = { payload: Payload
|
|
1
|
+
{"version":3,"sources":["../../src/postgres/types.ts"],"sourcesContent":["import type { DrizzleSnapshotJSON } from 'drizzle-kit/api'\nimport type {\n ColumnBaseConfig,\n ColumnDataType,\n DrizzleConfig,\n Relation,\n Relations,\n SQL,\n} from 'drizzle-orm'\nimport type { NodePgDatabase } from 'drizzle-orm/node-postgres'\nimport type {\n ForeignKeyBuilder,\n IndexBuilder,\n PgColumn,\n PgEnum,\n pgEnum,\n PgInsertOnConflictDoUpdateConfig,\n PgSchema,\n PgTableWithColumns,\n UniqueConstraintBuilder,\n} from 'drizzle-orm/pg-core'\nimport type { PgTableFn } from 'drizzle-orm/pg-core/table'\nimport type { Payload, PayloadRequest } from 'payload'\nimport type { ClientConfig, QueryResult } from 'pg'\n\nimport type { extendDrizzleTable, Operators } from '../index.js'\nimport type { BuildQueryJoinAliases, DrizzleAdapter, TransactionPg } from '../types.js'\n\nexport type BaseExtraConfig = Record<\n string,\n (cols: GenericColumns) => ForeignKeyBuilder | IndexBuilder | UniqueConstraintBuilder\n>\n\nexport type RelationMap = Map<\n string,\n {\n localized: boolean\n relationName?: string\n target: string\n type: 'many' | 'one'\n }\n>\n\nexport type GenericColumn = PgColumn<\n ColumnBaseConfig<ColumnDataType, string>,\n Record<string, unknown>\n>\n\nexport type GenericColumns = {\n [x: string]: GenericColumn\n}\n\nexport type GenericTable = PgTableWithColumns<{\n columns: GenericColumns\n dialect: string\n name: string\n schema: string\n}>\n\nexport type GenericEnum = PgEnum<[string, ...string[]]>\n\nexport type GenericRelation = Relations<string, Record<string, Relation<string>>>\n\nexport type PostgresDB = NodePgDatabase<Record<string, unknown>>\n\nexport type CountDistinct = (args: {\n db: PostgresDB | TransactionPg\n joins: BuildQueryJoinAliases\n tableName: string\n where: SQL\n}) => Promise<number>\n\nexport type DeleteWhere = (args: {\n db: PostgresDB | TransactionPg\n tableName: string\n where: SQL\n}) => Promise<void>\n\nexport type DropDatabase = (args: { adapter: BasePostgresAdapter }) => Promise<void>\n\nexport type Execute<T> = (args: {\n db?: PostgresDB | TransactionPg\n drizzle?: PostgresDB\n raw?: string\n sql?: SQL<unknown>\n}) => Promise<QueryResult<Record<string, T>>>\n\nexport type Insert = (args: {\n db: PostgresDB | TransactionPg\n onConflictDoUpdate?: PgInsertOnConflictDoUpdateConfig<any>\n tableName: string\n values: Record<string, unknown> | Record<string, unknown>[]\n}) => Promise<Record<string, unknown>[]>\n\nexport type CreateDatabase = (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 from adapter.schemaName if exists.\n */\n schemaName?: string\n}) => Promise<boolean>\n\ntype Schema =\n | {\n enum: typeof pgEnum\n table: PgTableFn<string>\n }\n | PgSchema\n\ntype PostgresSchema = {\n enums: Record<string, GenericEnum>\n relations: Record<string, GenericRelation>\n tables: Record<string, PgTableWithColumns<any>>\n}\n\ntype PostgresSchemaHookArgs = {\n adapter: PostgresDrizzleAdapter\n extendTable: typeof extendDrizzleTable\n schema: PostgresSchema\n}\n\nexport type PostgresSchemaHook = (\n args: PostgresSchemaHookArgs,\n) => PostgresSchema | Promise<PostgresSchema>\n\nexport type BasePostgresAdapter = {\n afterSchemaInit: PostgresSchemaHook[]\n beforeSchemaInit: PostgresSchemaHook[]\n countDistinct: CountDistinct\n createDatabase: CreateDatabase\n createExtensions: () => Promise<void>\n defaultDrizzleSnapshot: DrizzleSnapshotJSON\n deleteWhere: DeleteWhere\n disableCreateDatabase: boolean\n drizzle: PostgresDB\n dropDatabase: DropDatabase\n enums: Record<string, GenericEnum>\n execute: Execute<unknown>\n extensions: Record<string, boolean>\n /**\n * An object keyed on each table, with a key value pair where the constraint name is the key, followed by the dot-notation field name\n * Used for returning properly formed errors from unique fields\n */\n fieldConstraints: Record<string, Record<string, string>>\n idType: 'serial' | 'uuid'\n initializing: Promise<void>\n insert: Insert\n localesSuffix?: string\n logger: DrizzleConfig['logger']\n operators: Operators\n pgSchema: Schema\n poolOptions?: ClientConfig\n prodMigrations?: {\n down: (args: MigrateDownArgs) => Promise<void>\n name: string\n up: (args: MigrateUpArgs) => Promise<void>\n }[]\n push: boolean\n rejectInitializing: () => void\n relations: Record<string, GenericRelation>\n relationshipsSuffix?: string\n resolveInitializing: () => void\n schemaName?: string\n sessions: {\n [id: string]: {\n db: PostgresDB | TransactionPg\n reject: () => Promise<void>\n resolve: () => Promise<void>\n }\n }\n tableNameMap: Map<string, string>\n tables: Record<string, GenericTable>\n tablesFilter?: string[]\n versionsSuffix?: string\n} & PostgresDrizzleAdapter\n\nexport type PostgresDrizzleAdapter = Omit<\n DrizzleAdapter,\n | 'countDistinct'\n | 'deleteWhere'\n | 'drizzle'\n | 'dropDatabase'\n | 'execute'\n | 'insert'\n | 'operators'\n | 'relations'\n>\n\nexport type IDType = 'integer' | 'numeric' | 'uuid' | 'varchar'\n\nexport type MigrateUpArgs = {\n /**\n * The Postgres Drizzle instance that you can use to execute SQL directly within the current transaction.\n * @example\n * ```ts\n * import { type MigrateUpArgs, sql } from '@payloadcms/db-postgres'\n *\n * export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {\n * const { rows: posts } = await db.execute(sql`SELECT * FROM posts`)\n * }\n * ```\n */\n db: PostgresDB\n /**\n * The Payload instance that you can use to execute Local API methods\n * To use the current transaction you must pass `req` to arguments\n * @example\n * ```ts\n * import { type MigrateUpArgs, sql } from '@payloadcms/db-postgres'\n *\n * export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {\n * const posts = await payload.find({ collection: 'posts', req })\n * }\n * ```\n */\n payload: Payload\n /**\n * The `PayloadRequest` object that contains the current transaction\n */\n req: PayloadRequest\n}\n\nexport type MigrateDownArgs = {\n /**\n * The Postgres Drizzle instance that you can use to execute SQL directly within the current transaction.\n * @example\n * ```ts\n * import { type MigrateDownArgs, sql } from '@payloadcms/db-postgres'\n *\n * export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {\n * const { rows: posts } = await db.execute(sql`SELECT * FROM posts`)\n * }\n * ```\n */\n db: PostgresDB\n /**\n * The Payload instance that you can use to execute Local API methods\n * To use the current transaction you must pass `req` to arguments\n * @example\n * ```ts\n * import { type MigrateDownArgs } from '@payloadcms/db-postgres'\n *\n * export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {\n * const posts = await payload.find({ collection: 'posts', req })\n * }\n * ```\n */\n payload: Payload\n /**\n * The `PayloadRequest` object that contains the current transaction\n */\n req: PayloadRequest\n}\n"],"names":[],"mappings":"AAiOA,WA8BC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -4,10 +4,11 @@ import type { NodePgDatabase, NodePgQueryResultHKT } from 'drizzle-orm/node-post
|
|
|
4
4
|
import type { PgColumn, PgTable, PgTransaction } from 'drizzle-orm/pg-core';
|
|
5
5
|
import type { SQLiteColumn, SQLiteTable, SQLiteTransaction } from 'drizzle-orm/sqlite-core';
|
|
6
6
|
import type { Result } from 'drizzle-orm/sqlite-core/session';
|
|
7
|
-
import type { BaseDatabaseAdapter, MigrationData,
|
|
7
|
+
import type { BaseDatabaseAdapter, MigrationData, Payload, PayloadRequest } from 'payload';
|
|
8
8
|
import type { BuildQueryJoinAliases } from './queries/buildQuery.js';
|
|
9
9
|
export { BuildQueryJoinAliases };
|
|
10
10
|
import type { ResultSet } from '@libsql/client';
|
|
11
|
+
import type { DrizzleSnapshotJSON } from 'drizzle-kit/api';
|
|
11
12
|
import type { SQLiteRaw } from 'drizzle-orm/sqlite-core/query-builders/raw';
|
|
12
13
|
import type { QueryResult } from 'pg';
|
|
13
14
|
import type { ChainedMethods } from './find/chainMethods.js';
|
|
@@ -68,14 +69,14 @@ export type Insert = (args: {
|
|
|
68
69
|
values: Record<string, unknown> | Record<string, unknown>[];
|
|
69
70
|
}) => Promise<Record<string, unknown>[]>;
|
|
70
71
|
export type RequireDrizzleKit = () => {
|
|
71
|
-
generateDrizzleJson: (args:
|
|
72
|
-
|
|
73
|
-
}) => unknown;
|
|
72
|
+
generateDrizzleJson: (args: Record<string, unknown>) => DrizzleSnapshotJSON | Promise<DrizzleSnapshotJSON>;
|
|
73
|
+
generateMigration: (prev: DrizzleSnapshotJSON, cur: DrizzleSnapshotJSON) => Promise<string[]>;
|
|
74
74
|
pushSchema: (schema: Record<string, unknown>, drizzle: DrizzleAdapter['drizzle'], filterSchema?: string[], tablesFilter?: string[], extensionsFilter?: string[]) => Promise<{
|
|
75
75
|
apply: any;
|
|
76
76
|
hasDataLoss: any;
|
|
77
77
|
warnings: any;
|
|
78
78
|
}>;
|
|
79
|
+
upSnapshot?: (snapshot: Record<string, unknown>) => DrizzleSnapshotJSON;
|
|
79
80
|
};
|
|
80
81
|
export type Migration = {
|
|
81
82
|
down: ({ db, payload, req, }: {
|
|
@@ -116,7 +117,6 @@ export interface DrizzleAdapter extends BaseDatabaseAdapter {
|
|
|
116
117
|
* Used for returning properly formed errors from unique fields
|
|
117
118
|
*/
|
|
118
119
|
fieldConstraints: Record<string, Record<string, string>>;
|
|
119
|
-
getMigrationTemplate: (args: MigrationTemplateArgs) => string;
|
|
120
120
|
idType: 'serial' | 'uuid';
|
|
121
121
|
indexes: Set<string>;
|
|
122
122
|
initializing: Promise<void>;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EACN,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,0BAA0B,EAC1B,QAAQ,EACR,SAAS,EACT,GAAG,EACH,qBAAqB,EACtB,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AACrF,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAC3E,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAC3F,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAA;AAC7D,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EACN,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,0BAA0B,EAC1B,QAAQ,EACR,SAAS,EACT,GAAG,EACH,qBAAqB,EACtB,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAA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,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IAC3B,MAAM,EAAE,MAAM,CAAA;IACd,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAA;IAC/B,SAAS,EAAE,SAAS,CAAA;IACpB,IAAI,EAAE,OAAO,CAAA;IACb,kBAAkB,EAAE,MAAM,IAAI,CAAA;IAC9B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;IAC1C,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,mBAAmB,EAAE,MAAM,IAAI,CAAA;IAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAE/B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE;QACR,CAAC,EAAE,EAAE,MAAM,GAAG;YACZ,EAAE,EAAE,kBAAkB,CAAA;YACtB,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;YAC3B,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;SAC7B,CAAA;KACF,CAAA;IACD,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACjC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC3B,kBAAkB,EAAE,OAAO,CAAA;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n Column,\n ColumnBaseConfig,\n ColumnDataType,\n DrizzleConfig,\n ExtractTablesWithRelations,\n Relation,\n Relations,\n SQL,\n TableRelationalConfig,\n} from 'drizzle-orm'\nimport type { LibSQLDatabase } from 'drizzle-orm/libsql'\nimport type { NodePgDatabase, NodePgQueryResultHKT } from 'drizzle-orm/node-postgres'\nimport type { PgColumn, PgTable, PgTransaction } from 'drizzle-orm/pg-core'\nimport type { SQLiteColumn, SQLiteTable, SQLiteTransaction } from 'drizzle-orm/sqlite-core'\nimport type { Result } from 'drizzle-orm/sqlite-core/session'\nimport type {
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n Column,\n ColumnBaseConfig,\n ColumnDataType,\n DrizzleConfig,\n ExtractTablesWithRelations,\n Relation,\n Relations,\n SQL,\n TableRelationalConfig,\n} from 'drizzle-orm'\nimport type { LibSQLDatabase } from 'drizzle-orm/libsql'\nimport type { NodePgDatabase, NodePgQueryResultHKT } from 'drizzle-orm/node-postgres'\nimport type { PgColumn, PgTable, PgTransaction } from 'drizzle-orm/pg-core'\nimport type { SQLiteColumn, SQLiteTable, SQLiteTransaction } from 'drizzle-orm/sqlite-core'\nimport type { Result } from 'drizzle-orm/sqlite-core/session'\nimport type { BaseDatabaseAdapter, MigrationData, Payload, PayloadRequest } from 'payload'\n\nimport type { BuildQueryJoinAliases } from './queries/buildQuery.js'\n\nexport { BuildQueryJoinAliases }\n\nimport type { ResultSet } from '@libsql/client'\nimport type { DrizzleSnapshotJSON } from 'drizzle-kit/api'\nimport type { SQLiteRaw } from 'drizzle-orm/sqlite-core/query-builders/raw'\nimport type { QueryResult } from 'pg'\n\nimport type { ChainedMethods } from './find/chainMethods.js'\nimport type { Operators } from './queries/operatorMap.js'\n\nexport { ChainedMethods }\n\nexport type PostgresDB = NodePgDatabase<Record<string, unknown>>\n\nexport type SQLiteDB = LibSQLDatabase<\n Record<string, GenericRelation | GenericTable> & Record<string, unknown>\n>\n\nexport type GenericPgColumn = PgColumn<\n ColumnBaseConfig<ColumnDataType, string>,\n Record<string, unknown>\n>\n\nexport type GenericColumns<T> = {\n [x: string]: T\n}\n\ntype GenericPgTable = PgTable<{\n columns: GenericColumns<GenericPgColumn>\n dialect: string\n name: string\n schema: undefined\n}>\n\ntype GenericSQLiteTable = SQLiteTable<{\n columns: GenericColumns<SQLiteColumn>\n dialect: string\n name: string\n schema: undefined\n}>\n\nexport type GenericColumn = GenericPgColumn | SQLiteColumn\n\nexport type GenericTable = GenericPgTable | GenericSQLiteTable\n\nexport type GenericRelation = Relations<string, Record<string, Relation<string>>>\n\nexport type TransactionSQLite = SQLiteTransaction<\n 'async',\n Result<'async', unknown>,\n Record<string, unknown>,\n { tsName: TableRelationalConfig }\n>\nexport type TransactionPg = PgTransaction<\n NodePgQueryResultHKT,\n Record<string, unknown>,\n ExtractTablesWithRelations<Record<string, unknown>>\n>\n\nexport type DrizzleTransaction = TransactionPg | TransactionSQLite\n\nexport type CountDistinct = (args: {\n db: DrizzleTransaction | LibSQLDatabase | PostgresDB\n joins: BuildQueryJoinAliases\n tableName: string\n where: SQL\n}) => Promise<number>\n\nexport type DeleteWhere = (args: {\n db: DrizzleTransaction | LibSQLDatabase | PostgresDB\n tableName: string\n where: SQL\n}) => Promise<void>\n\nexport type DropDatabase = (args: { adapter: DrizzleAdapter }) => Promise<void>\n\nexport type Execute<T> = (args: {\n db?: DrizzleTransaction | LibSQLDatabase | PostgresDB\n drizzle?: LibSQLDatabase | PostgresDB\n raw?: string\n sql?: SQL<unknown>\n}) =>\n | Promise<QueryResult<Record<string, T>>>\n | SQLiteRaw<Promise<{ rows: T[] }>>\n | SQLiteRaw<ResultSet>\n\nexport type Insert = (args: {\n db: DrizzleTransaction | LibSQLDatabase | PostgresDB\n onConflictDoUpdate?: unknown\n tableName: string\n values: Record<string, unknown> | Record<string, unknown>[]\n}) => Promise<Record<string, unknown>[]>\n\nexport type RequireDrizzleKit = () => {\n generateDrizzleJson: (\n args: Record<string, unknown>,\n ) => DrizzleSnapshotJSON | Promise<DrizzleSnapshotJSON>\n generateMigration: (prev: DrizzleSnapshotJSON, cur: DrizzleSnapshotJSON) => Promise<string[]>\n pushSchema: (\n schema: Record<string, unknown>,\n drizzle: DrizzleAdapter['drizzle'],\n filterSchema?: string[],\n tablesFilter?: string[],\n extensionsFilter?: string[],\n ) => Promise<{ apply; hasDataLoss; warnings }>\n upSnapshot?: (snapshot: Record<string, unknown>) => DrizzleSnapshotJSON\n}\n\nexport type Migration = {\n down: ({\n db,\n payload,\n req,\n }: {\n db?: DrizzleTransaction | LibSQLDatabase<Record<string, never>> | PostgresDB\n payload: Payload\n req: PayloadRequest\n }) => Promise<void>\n up: ({\n db,\n payload,\n req,\n }: {\n db?: DrizzleTransaction | LibSQLDatabase | PostgresDB\n payload: Payload\n req: PayloadRequest\n }) => Promise<void>\n} & MigrationData\n\nexport type CreateJSONQueryArgs = {\n column?: Column | string\n operator: string\n pathSegments: string[]\n table?: string\n treatAsArray?: string[]\n treatRootAsArray?: boolean\n value: boolean | number | string\n}\n\nexport interface DrizzleAdapter extends BaseDatabaseAdapter {\n convertPathToJSONTraversal?: (incomingSegments: string[]) => string\n countDistinct: CountDistinct\n createJSONQuery: (args: CreateJSONQueryArgs) => string\n defaultDrizzleSnapshot: Record<string, unknown>\n deleteWhere: DeleteWhere\n drizzle: LibSQLDatabase | PostgresDB\n dropDatabase: DropDatabase\n enums?: never | Record<string, unknown>\n execute: Execute<unknown>\n\n features: {\n json?: boolean\n }\n /**\n * An object keyed on each table, with a key value pair where the constraint name is the key, followed by the dot-notation field name\n * Used for returning properly formed errors from unique fields\n */\n fieldConstraints: Record<string, Record<string, string>>\n idType: 'serial' | 'uuid'\n indexes: Set<string>\n initializing: Promise<void>\n insert: Insert\n localesSuffix?: string\n logger: DrizzleConfig['logger']\n operators: Operators\n push: boolean\n rejectInitializing: () => void\n relations: Record<string, GenericRelation>\n relationshipsSuffix?: string\n requireDrizzleKit: RequireDrizzleKit\n resolveInitializing: () => void\n schema: Record<string, unknown>\n\n schemaName?: string\n sessions: {\n [id: string]: {\n db: DrizzleTransaction\n reject: () => Promise<void>\n resolve: () => Promise<void>\n }\n }\n tableNameMap: Map<string, string>\n tables: Record<string, any>\n transactionOptions: unknown\n versionsSuffix?: string\n}\n"],"names":[],"mappings":"AA+JA,WA8CC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CreateMigration } from 'payload';
|
|
2
|
+
export declare const buildCreateMigration: ({ executeMethod, filename, sanitizeStatements, }: {
|
|
3
|
+
executeMethod: string;
|
|
4
|
+
filename: string;
|
|
5
|
+
sanitizeStatements: (args: {
|
|
6
|
+
sqlExecute: string;
|
|
7
|
+
statements: string[];
|
|
8
|
+
}) => string;
|
|
9
|
+
}) => CreateMigration;
|
|
10
|
+
//# sourceMappingURL=buildCreateMigration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildCreateMigration.d.ts","sourceRoot":"","sources":["../../src/utilities/buildCreateMigration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAW9C,eAAO,MAAM,oBAAoB,qDAI9B;IACD,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,EAAE,MAAM,CAAA;IAChB,kBAAkB,EAAE,CAAC,IAAI,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,EAAE,CAAA;KAAE,KAAK,MAAM,CAAA;CACnF,KAAG,eAiHH,CAAA"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { getPredefinedMigration, writeMigrationIndex } from 'payload';
|
|
4
|
+
import prompts from 'prompts';
|
|
5
|
+
import { getMigrationTemplate } from './getMigrationTemplate.js';
|
|
6
|
+
export const buildCreateMigration = ({ executeMethod, filename, sanitizeStatements })=>{
|
|
7
|
+
const dirname = path.dirname(filename);
|
|
8
|
+
return async function createMigration({ file, forceAcceptWarning, migrationName, payload, skipEmpty }) {
|
|
9
|
+
const dir = payload.db.migrationDir;
|
|
10
|
+
if (!fs.existsSync(dir)) {
|
|
11
|
+
fs.mkdirSync(dir);
|
|
12
|
+
}
|
|
13
|
+
const { generateDrizzleJson, generateMigration, upSnapshot } = this.requireDrizzleKit();
|
|
14
|
+
const drizzleJsonAfter = await generateDrizzleJson(this.schema);
|
|
15
|
+
const [yyymmdd, hhmmss] = new Date().toISOString().split('T');
|
|
16
|
+
const formattedDate = yyymmdd.replace(/\D/g, '');
|
|
17
|
+
const formattedTime = hhmmss.split('.')[0].replace(/\D/g, '');
|
|
18
|
+
let imports = '';
|
|
19
|
+
let downSQL;
|
|
20
|
+
let upSQL;
|
|
21
|
+
({ downSQL, imports, upSQL } = await getPredefinedMigration({
|
|
22
|
+
dirname,
|
|
23
|
+
file,
|
|
24
|
+
migrationName,
|
|
25
|
+
payload
|
|
26
|
+
}));
|
|
27
|
+
const timestamp = `${formattedDate}_${formattedTime}`;
|
|
28
|
+
const name = migrationName || file?.split('/').slice(2).join('/');
|
|
29
|
+
const fileName = `${timestamp}${name ? `_${name.replace(/\W/g, '_')}` : ''}`;
|
|
30
|
+
const filePath = `${dir}/${fileName}`;
|
|
31
|
+
let drizzleJsonBefore = this.defaultDrizzleSnapshot;
|
|
32
|
+
if (this.schemaName) {
|
|
33
|
+
drizzleJsonBefore.schemas = {
|
|
34
|
+
[this.schemaName]: this.schemaName
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (!upSQL) {
|
|
38
|
+
// Get latest migration snapshot
|
|
39
|
+
const latestSnapshot = fs.readdirSync(dir).filter((file)=>file.endsWith('.json')).sort().reverse()?.[0];
|
|
40
|
+
if (latestSnapshot) {
|
|
41
|
+
drizzleJsonBefore = JSON.parse(fs.readFileSync(`${dir}/${latestSnapshot}`, 'utf8'));
|
|
42
|
+
if (upSnapshot && drizzleJsonBefore.version < drizzleJsonAfter.version) {
|
|
43
|
+
drizzleJsonBefore = upSnapshot(drizzleJsonBefore);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const sqlStatementsUp = await generateMigration(drizzleJsonBefore, drizzleJsonAfter);
|
|
47
|
+
const sqlStatementsDown = await generateMigration(drizzleJsonAfter, drizzleJsonBefore);
|
|
48
|
+
const sqlExecute = `await db.${executeMethod}(` + 'sql`';
|
|
49
|
+
if (sqlStatementsUp?.length) {
|
|
50
|
+
upSQL = sanitizeStatements({
|
|
51
|
+
sqlExecute,
|
|
52
|
+
statements: sqlStatementsUp
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (sqlStatementsDown?.length) {
|
|
56
|
+
downSQL = sanitizeStatements({
|
|
57
|
+
sqlExecute,
|
|
58
|
+
statements: sqlStatementsDown
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if (!upSQL?.length && !downSQL?.length && !forceAcceptWarning) {
|
|
62
|
+
if (skipEmpty) {
|
|
63
|
+
process.exit(0);
|
|
64
|
+
}
|
|
65
|
+
const { confirm: shouldCreateBlankMigration } = await prompts({
|
|
66
|
+
name: 'confirm',
|
|
67
|
+
type: 'confirm',
|
|
68
|
+
initial: false,
|
|
69
|
+
message: 'No schema changes detected. Would you like to create a blank migration file?'
|
|
70
|
+
}, {
|
|
71
|
+
onCancel: ()=>{
|
|
72
|
+
process.exit(0);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
if (!shouldCreateBlankMigration) {
|
|
76
|
+
process.exit(0);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// write schema
|
|
80
|
+
fs.writeFileSync(`${filePath}.json`, JSON.stringify(drizzleJsonAfter, null, 2));
|
|
81
|
+
}
|
|
82
|
+
// write migration
|
|
83
|
+
fs.writeFileSync(`${filePath}.ts`, getMigrationTemplate({
|
|
84
|
+
downSQL: downSQL || ` // Migration code`,
|
|
85
|
+
imports,
|
|
86
|
+
packageName: payload.db.packageName,
|
|
87
|
+
upSQL: upSQL || ` // Migration code`
|
|
88
|
+
}));
|
|
89
|
+
writeMigrationIndex({
|
|
90
|
+
migrationsDir: payload.db.migrationDir
|
|
91
|
+
});
|
|
92
|
+
payload.logger.info({
|
|
93
|
+
msg: `Migration created at ${filePath}.ts`
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
//# sourceMappingURL=buildCreateMigration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/buildCreateMigration.ts"],"sourcesContent":["import type { DrizzleSnapshotJSON } from 'drizzle-kit/api'\nimport type { CreateMigration } from 'payload'\n\nimport fs from 'fs'\nimport path from 'path'\nimport { getPredefinedMigration, writeMigrationIndex } from 'payload'\nimport prompts from 'prompts'\n\nimport type { DrizzleAdapter } from '../types.js'\n\nimport { getMigrationTemplate } from './getMigrationTemplate.js'\n\nexport const buildCreateMigration = ({\n executeMethod,\n filename,\n sanitizeStatements,\n}: {\n executeMethod: string\n filename: string\n sanitizeStatements: (args: { sqlExecute: string; statements: string[] }) => string\n}): CreateMigration => {\n const dirname = path.dirname(filename)\n return async function createMigration(\n this: DrizzleAdapter,\n { file, forceAcceptWarning, migrationName, payload, skipEmpty },\n ) {\n const dir = payload.db.migrationDir\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir)\n }\n\n const { generateDrizzleJson, generateMigration, upSnapshot } = this.requireDrizzleKit()\n\n const drizzleJsonAfter = await generateDrizzleJson(this.schema)\n\n const [yyymmdd, hhmmss] = new Date().toISOString().split('T')\n const formattedDate = yyymmdd.replace(/\\D/g, '')\n const formattedTime = hhmmss.split('.')[0].replace(/\\D/g, '')\n let imports: string = ''\n let downSQL: string\n let upSQL: string\n ;({ downSQL, imports, upSQL } = await getPredefinedMigration({\n dirname,\n file,\n migrationName,\n payload,\n }))\n\n const timestamp = `${formattedDate}_${formattedTime}`\n\n const name = migrationName || file?.split('/').slice(2).join('/')\n const fileName = `${timestamp}${name ? `_${name.replace(/\\W/g, '_')}` : ''}`\n\n const filePath = `${dir}/${fileName}`\n\n let drizzleJsonBefore = this.defaultDrizzleSnapshot as DrizzleSnapshotJSON\n\n if (this.schemaName) {\n drizzleJsonBefore.schemas = {\n [this.schemaName]: this.schemaName,\n }\n }\n\n if (!upSQL) {\n // Get latest migration snapshot\n const latestSnapshot = fs\n .readdirSync(dir)\n .filter((file) => file.endsWith('.json'))\n .sort()\n .reverse()?.[0]\n\n if (latestSnapshot) {\n drizzleJsonBefore = JSON.parse(fs.readFileSync(`${dir}/${latestSnapshot}`, 'utf8'))\n\n if (upSnapshot && drizzleJsonBefore.version < drizzleJsonAfter.version) {\n drizzleJsonBefore = upSnapshot(drizzleJsonBefore)\n }\n }\n\n const sqlStatementsUp = await generateMigration(drizzleJsonBefore, drizzleJsonAfter)\n const sqlStatementsDown = await generateMigration(drizzleJsonAfter, drizzleJsonBefore)\n const sqlExecute = `await db.${executeMethod}(` + 'sql`'\n\n if (sqlStatementsUp?.length) {\n upSQL = sanitizeStatements({ sqlExecute, statements: sqlStatementsUp })\n }\n if (sqlStatementsDown?.length) {\n downSQL = sanitizeStatements({ sqlExecute, statements: sqlStatementsDown })\n }\n\n if (!upSQL?.length && !downSQL?.length && !forceAcceptWarning) {\n if (skipEmpty) {\n process.exit(0)\n }\n\n const { confirm: shouldCreateBlankMigration } = await prompts(\n {\n name: 'confirm',\n type: 'confirm',\n initial: false,\n message: 'No schema changes detected. Would you like to create a blank migration file?',\n },\n {\n onCancel: () => {\n process.exit(0)\n },\n },\n )\n\n if (!shouldCreateBlankMigration) {\n process.exit(0)\n }\n }\n\n // write schema\n fs.writeFileSync(`${filePath}.json`, JSON.stringify(drizzleJsonAfter, null, 2))\n }\n\n // write migration\n fs.writeFileSync(\n `${filePath}.ts`,\n getMigrationTemplate({\n downSQL: downSQL || ` // Migration code`,\n imports,\n packageName: payload.db.packageName,\n upSQL: upSQL || ` // Migration code`,\n }),\n )\n\n writeMigrationIndex({ migrationsDir: payload.db.migrationDir })\n\n payload.logger.info({ msg: `Migration created at ${filePath}.ts` })\n }\n}\n"],"names":["fs","path","getPredefinedMigration","writeMigrationIndex","prompts","getMigrationTemplate","buildCreateMigration","executeMethod","filename","sanitizeStatements","dirname","createMigration","file","forceAcceptWarning","migrationName","payload","skipEmpty","dir","db","migrationDir","existsSync","mkdirSync","generateDrizzleJson","generateMigration","upSnapshot","requireDrizzleKit","drizzleJsonAfter","schema","yyymmdd","hhmmss","Date","toISOString","split","formattedDate","replace","formattedTime","imports","downSQL","upSQL","timestamp","name","slice","join","fileName","filePath","drizzleJsonBefore","defaultDrizzleSnapshot","schemaName","schemas","latestSnapshot","readdirSync","filter","endsWith","sort","reverse","JSON","parse","readFileSync","version","sqlStatementsUp","sqlStatementsDown","sqlExecute","length","statements","process","exit","confirm","shouldCreateBlankMigration","type","initial","message","onCancel","writeFileSync","stringify","packageName","migrationsDir","logger","info","msg"],"mappings":"AAGA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,UAAU,OAAM;AACvB,SAASC,sBAAsB,EAAEC,mBAAmB,QAAQ,UAAS;AACrE,OAAOC,aAAa,UAAS;AAI7B,SAASC,oBAAoB,QAAQ,4BAA2B;AAEhE,OAAO,MAAMC,uBAAuB,CAAC,EACnCC,aAAa,EACbC,QAAQ,EACRC,kBAAkB,EAKnB;IACC,MAAMC,UAAUT,KAAKS,OAAO,CAACF;IAC7B,OAAO,eAAeG,gBAEpB,EAAEC,IAAI,EAAEC,kBAAkB,EAAEC,aAAa,EAAEC,OAAO,EAAEC,SAAS,EAAE;QAE/D,MAAMC,MAAMF,QAAQG,EAAE,CAACC,YAAY;QACnC,IAAI,CAACnB,GAAGoB,UAAU,CAACH,MAAM;YACvBjB,GAAGqB,SAAS,CAACJ;QACf;QAEA,MAAM,EAAEK,mBAAmB,EAAEC,iBAAiB,EAAEC,UAAU,EAAE,GAAG,IAAI,CAACC,iBAAiB;QAErF,MAAMC,mBAAmB,MAAMJ,oBAAoB,IAAI,CAACK,MAAM;QAE9D,MAAM,CAACC,SAASC,OAAO,GAAG,IAAIC,OAAOC,WAAW,GAAGC,KAAK,CAAC;QACzD,MAAMC,gBAAgBL,QAAQM,OAAO,CAAC,OAAO;QAC7C,MAAMC,gBAAgBN,OAAOG,KAAK,CAAC,IAAI,CAAC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AAC,CAAC,GAAG;YAElD,IAAIoD,iBAAiBG,QAAQ;gBAC3BxB,QAAQ7B,mBAAmB;oBAAEoD;oBAAYE,YAAYJ;gBAAgB;YACvE;YACA,IAAIC,mBAAmBE,QAAQ;gBAC7BzB,UAAU5B,mBAAmB;oBAAEoD;oBAAYE,YAAYH;gBAAkB;YAC3E;YAEA,IAAI,CAACtB,OAAOwB,UAAU,CAACzB,SAASyB,UAAU,CAACjD,oBAAoB;gBAC7D,IAAIG,WAAW;oBACbgD,QAAQC,IAAI,CAAC;gBACf;gBAEA,MAAM,EAAEC,SAASC,0BAA0B,EAAE,GAAG,MAAM/D,QACpD;oBACEoC,MAAM;oBACN4B,MAAM;oBACNC,SAAS;oBACTC,SAAS;gBACX,GACA;oBACEC,UAAU;wBACRP,QAAQC,IAAI,CAAC;oBACf;gBACF;gBAGF,IAAI,CAACE,4BAA4B;oBAC/BH,QAAQC,IAAI,CAAC;gBACf;YACF;YAEA,eAAe;YACfjE,GAAGwE,aAAa,CAAC,GAAG5B,SAAS,KAAK,CAAC,EAAEW,KAAKkB,SAAS,CAAC/C,kBAAkB,MAAM;QAC9E;QAEA,kBAAkB;QAClB1B,GAAGwE,aAAa,CACd,GAAG5B,SAAS,GAAG,CAAC,EAChBvC,qBAAqB;YACnBgC,SAASA,WAAW,CAAC,mBAAmB,CAAC;YACzCD;YACAsC,aAAa3D,QAAQG,EAAE,CAACwD,WAAW;YACnCpC,OAAOA,SAAS,CAAC,mBAAmB,CAAC;QACvC;QAGFnC,oBAAoB;YAAEwE,eAAe5D,QAAQG,EAAE,CAACC,YAAY;QAAC;QAE7DJ,QAAQ6D,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK,CAAC,qBAAqB,EAAElC,SAAS,GAAG,CAAC;QAAC;IACnE;AACF,EAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { MigrationTemplateArgs } from 'payload';
|
|
2
|
+
export declare const indent: (text: string) => string;
|
|
3
|
+
export declare const getMigrationTemplate: ({ downSQL, imports, packageName, upSQL, }: MigrationTemplateArgs) => string;
|
|
4
|
+
//# sourceMappingURL=getMigrationTemplate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMigrationTemplate.d.ts","sourceRoot":"","sources":["../../src/utilities/getMigrationTemplate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEpD,eAAO,MAAM,MAAM,SAAU,MAAM,WAIpB,CAAA;AAEf,eAAO,MAAM,oBAAoB,8CAK9B,qBAAqB,KAAG,MAS1B,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const indent = (text)=>text.split('\n').map((line)=>` ${line}`).join('\n');
|
|
2
|
+
export const getMigrationTemplate = ({ downSQL, imports, packageName, upSQL })=>`import { MigrateUpArgs, MigrateDownArgs, sql } from '${packageName}'
|
|
3
|
+
${imports ? `${imports}\n` : ''}
|
|
4
|
+
export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
|
|
5
|
+
${indent(upSQL)}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
|
|
9
|
+
${indent(downSQL)}
|
|
10
|
+
}
|
|
11
|
+
`;
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=getMigrationTemplate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getMigrationTemplate.ts"],"sourcesContent":["import type { MigrationTemplateArgs } from 'payload'\n\nexport const indent = (text: string) =>\n text\n .split('\\n')\n .map((line) => ` ${line}`)\n .join('\\n')\n\nexport const getMigrationTemplate = ({\n downSQL,\n imports,\n packageName,\n upSQL,\n}: MigrationTemplateArgs): string => `import { MigrateUpArgs, MigrateDownArgs, sql } from '${packageName}'\n${imports ? `${imports}\\n` : ''}\nexport async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {\n${indent(upSQL)}\n}\n\nexport async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {\n${indent(downSQL)}\n}\n`\n"],"names":["indent","text","split","map","line","join","getMigrationTemplate","downSQL","imports","packageName","upSQL"],"mappings":"AAEA,OAAO,MAAMA,SAAS,CAACC,OACrBA,KACGC,KAAK,CAAC,MACNC,GAAG,CAAC,CAACC,OAAS,CAAC,EAAE,EAAEA,MAAM,EACzBC,IAAI,CAAC,MAAK;AAEf,OAAO,MAAMC,uBAAuB,CAAC,EACnCC,OAAO,EACPC,OAAO,EACPC,WAAW,EACXC,KAAK,EACiB,GAAa,CAAC,qDAAqD,EAAED,YAAY;AACzG,EAAED,UAAU,GAAGA,QAAQ,EAAE,CAAC,GAAG,GAAG;;AAEhC,EAAER,OAAOU,OAAO;;;;AAIhB,EAAEV,OAAOO,SAAS;;AAElB,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/drizzle",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"description": "A library of shared functions used by different payload database adapters",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -52,11 +52,11 @@
|
|
|
52
52
|
"@libsql/client": "0.14.0",
|
|
53
53
|
"@types/pg": "8.10.2",
|
|
54
54
|
"@types/to-snake-case": "1.0.0",
|
|
55
|
-
"
|
|
56
|
-
"
|
|
55
|
+
"payload": "3.6.0",
|
|
56
|
+
"@payloadcms/eslint-config": "3.0.0"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"payload": "3.
|
|
59
|
+
"payload": "3.6.0"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"build": "pnpm build:swc && pnpm build:types",
|