@payloadcms/db-mongodb 4.0.0-canary.30 → 4.0.0-canary.32
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/createMigration.d.ts.map +1 -1
- package/dist/createMigration.js +9 -2
- package/dist/createMigration.js.map +1 -1
- package/dist/migrateFresh.d.ts +4 -2
- package/dist/migrateFresh.d.ts.map +1 -1
- package/dist/migrateFresh.js +20 -6
- package/dist/migrateFresh.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createMigration.d.ts","sourceRoot":"","sources":["../src/createMigration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAyB,MAAM,SAAS,CAAA;AAqBrE,eAAO,MAAM,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"createMigration.d.ts","sourceRoot":"","sources":["../src/createMigration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAyB,MAAM,SAAS,CAAA;AAqBrE,eAAO,MAAM,eAAe,EAAE,eA4C7B,CAAA"}
|
package/dist/createMigration.js
CHANGED
|
@@ -36,15 +36,22 @@ export const createMigration = async function createMigration({ file, migrationN
|
|
|
36
36
|
const formattedName = migrationName?.replace(/\W/g, '_');
|
|
37
37
|
const fileName = migrationName ? `${timestamp}_${formattedName}.ts` : `${timestamp}_migration.ts`;
|
|
38
38
|
const filePath = `${dir}/${fileName}`;
|
|
39
|
-
if (
|
|
40
|
-
|
|
39
|
+
if (skipEmpty) {
|
|
40
|
+
return {
|
|
41
|
+
created: false
|
|
42
|
+
};
|
|
41
43
|
}
|
|
44
|
+
fs.writeFileSync(filePath, migrationFileContent);
|
|
42
45
|
writeMigrationIndex({
|
|
43
46
|
migrationsDir: payload.db.migrationDir
|
|
44
47
|
});
|
|
45
48
|
payload.logger.info({
|
|
46
49
|
msg: `Migration created at ${filePath}`
|
|
47
50
|
});
|
|
51
|
+
return {
|
|
52
|
+
created: true,
|
|
53
|
+
path: filePath
|
|
54
|
+
};
|
|
48
55
|
};
|
|
49
56
|
|
|
50
57
|
//# sourceMappingURL=createMigration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/createMigration.ts"],"sourcesContent":["import type { CreateMigration, MigrationTemplateArgs } from 'payload'\n\nimport fs from 'fs'\nimport path from 'path'\nimport { getPredefinedMigration, writeMigrationIndex } from 'payload'\nimport { fileURLToPath } from 'url'\n\nconst migrationTemplate = ({ downSQL, imports, upSQL }: MigrationTemplateArgs): string => `import {\n MigrateDownArgs,\n MigrateUpArgs,\n} from '@payloadcms/db-mongodb'\n${imports ?? ''}\nexport async function up({ payload, req, session }: MigrateUpArgs): Promise<void> {\n${upSQL ?? ` // Migration code`}\n}\n\nexport async function down({ payload, req, session }: MigrateDownArgs): Promise<void> {\n${downSQL ?? ` // Migration code`}\n}\n`\n\nexport const createMigration: CreateMigration = async function createMigration({\n file,\n migrationName,\n payload,\n skipEmpty,\n}) {\n const filename = fileURLToPath(import.meta.url)\n const dirname = path.dirname(filename)\n\n const dir = payload.db.migrationDir\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir)\n }\n const predefinedMigration = await getPredefinedMigration({\n dirname,\n file,\n migrationName,\n payload,\n })\n\n const migrationFileContent = migrationTemplate(predefinedMigration)\n\n const [yyymmdd, hhmmss] = new Date().toISOString().split('T')\n\n const formattedDate = yyymmdd!.replace(/\\D/g, '')\n const formattedTime = hhmmss!.split('.')[0]!.replace(/\\D/g, '')\n\n const timestamp = `${formattedDate}_${formattedTime}`\n\n const formattedName = migrationName?.replace(/\\W/g, '_')\n const fileName = migrationName ? `${timestamp}_${formattedName}.ts` : `${timestamp}_migration.ts`\n const filePath = `${dir}/${fileName}`\n\n if (
|
|
1
|
+
{"version":3,"sources":["../src/createMigration.ts"],"sourcesContent":["import type { CreateMigration, MigrationTemplateArgs } from 'payload'\n\nimport fs from 'fs'\nimport path from 'path'\nimport { getPredefinedMigration, writeMigrationIndex } from 'payload'\nimport { fileURLToPath } from 'url'\n\nconst migrationTemplate = ({ downSQL, imports, upSQL }: MigrationTemplateArgs): string => `import {\n MigrateDownArgs,\n MigrateUpArgs,\n} from '@payloadcms/db-mongodb'\n${imports ?? ''}\nexport async function up({ payload, req, session }: MigrateUpArgs): Promise<void> {\n${upSQL ?? ` // Migration code`}\n}\n\nexport async function down({ payload, req, session }: MigrateDownArgs): Promise<void> {\n${downSQL ?? ` // Migration code`}\n}\n`\n\nexport const createMigration: CreateMigration = async function createMigration({\n file,\n migrationName,\n payload,\n skipEmpty,\n}) {\n const filename = fileURLToPath(import.meta.url)\n const dirname = path.dirname(filename)\n\n const dir = payload.db.migrationDir\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir)\n }\n const predefinedMigration = await getPredefinedMigration({\n dirname,\n file,\n migrationName,\n payload,\n })\n\n const migrationFileContent = migrationTemplate(predefinedMigration)\n\n const [yyymmdd, hhmmss] = new Date().toISOString().split('T')\n\n const formattedDate = yyymmdd!.replace(/\\D/g, '')\n const formattedTime = hhmmss!.split('.')[0]!.replace(/\\D/g, '')\n\n const timestamp = `${formattedDate}_${formattedTime}`\n\n const formattedName = migrationName?.replace(/\\W/g, '_')\n const fileName = migrationName ? `${timestamp}_${formattedName}.ts` : `${timestamp}_migration.ts`\n const filePath = `${dir}/${fileName}`\n\n if (skipEmpty) {\n return { created: false }\n }\n\n fs.writeFileSync(filePath, migrationFileContent)\n\n writeMigrationIndex({ migrationsDir: payload.db.migrationDir })\n\n payload.logger.info({ msg: `Migration created at ${filePath}` })\n\n return { created: true, path: filePath }\n}\n"],"names":["fs","path","getPredefinedMigration","writeMigrationIndex","fileURLToPath","migrationTemplate","downSQL","imports","upSQL","createMigration","file","migrationName","payload","skipEmpty","filename","url","dirname","dir","db","migrationDir","existsSync","mkdirSync","predefinedMigration","migrationFileContent","yyymmdd","hhmmss","Date","toISOString","split","formattedDate","replace","formattedTime","timestamp","formattedName","fileName","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AMG,WAAW,GAAGlB,IAAI,CAAC,EAAEiB,UAAU;IAErC,IAAIrB,WAAW;QACb,OAAO;YAAEuB,SAAS;QAAM;IAC1B;IAEApC,GAAGqC,aAAa,CAACF,UAAUZ;IAE3BpB,oBAAoB;QAAEmC,eAAe1B,QAAQM,EAAE,CAACC,YAAY;IAAC;IAE7DP,QAAQ2B,MAAM,CAACC,IAAI,CAAC;QAAEC,KAAK,CAAC,qBAAqB,EAAEN,UAAU;IAAC;IAE9D,OAAO;QAAEC,SAAS;QAAMnC,MAAMkC;IAAS;AACzC,EAAC"}
|
package/dist/migrateFresh.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import type { MigrationResult } from 'payload';
|
|
1
2
|
import type { MongooseAdapter } from './index.js';
|
|
2
3
|
/**
|
|
3
4
|
* Drop the current database and run all migrate up functions
|
|
4
5
|
*/
|
|
5
|
-
export declare function migrateFresh(this: MongooseAdapter, { forceAcceptWarning }: {
|
|
6
|
+
export declare function migrateFresh(this: MongooseAdapter, { forceAcceptWarning, shouldPrompt, }: {
|
|
6
7
|
forceAcceptWarning?: boolean;
|
|
7
|
-
|
|
8
|
+
shouldPrompt?: boolean;
|
|
9
|
+
}): Promise<MigrationResult>;
|
|
8
10
|
//# sourceMappingURL=migrateFresh.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrateFresh.d.ts","sourceRoot":"","sources":["../src/migrateFresh.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"migrateFresh.d.ts","sourceRoot":"","sources":["../src/migrateFresh.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAK9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD;;GAEG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,eAAe,EACrB,EACE,kBAA0B,EAC1B,YAAmB,GACpB,EAAE;IAAE,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAAC,YAAY,CAAC,EAAE,OAAO,CAAA;CAAE,GAC1D,OAAO,CAAC,eAAe,CAAC,CAiE1B"}
|
package/dist/migrateFresh.js
CHANGED
|
@@ -2,21 +2,28 @@ import { commitTransaction, initTransaction, killTransaction, readMigrationFiles
|
|
|
2
2
|
import prompts from 'prompts';
|
|
3
3
|
/**
|
|
4
4
|
* Drop the current database and run all migrate up functions
|
|
5
|
-
*/ export async function migrateFresh({ forceAcceptWarning = false }) {
|
|
5
|
+
*/ export async function migrateFresh({ forceAcceptWarning = false, shouldPrompt = true }) {
|
|
6
6
|
const { payload } = this;
|
|
7
7
|
if (!forceAcceptWarning) {
|
|
8
|
+
if (!shouldPrompt) {
|
|
9
|
+
return {
|
|
10
|
+
cancelled: true,
|
|
11
|
+
migrated: [],
|
|
12
|
+
rolledBack: []
|
|
13
|
+
};
|
|
14
|
+
}
|
|
8
15
|
const { confirm: acceptWarning } = await prompts({
|
|
9
16
|
name: 'confirm',
|
|
10
17
|
type: 'confirm',
|
|
11
18
|
initial: false,
|
|
12
19
|
message: `WARNING: This will drop your database and run all migrations. Are you sure you want to proceed?`
|
|
13
|
-
}, {
|
|
14
|
-
onCancel: ()=>{
|
|
15
|
-
process.exit(0);
|
|
16
|
-
}
|
|
17
20
|
});
|
|
18
21
|
if (!acceptWarning) {
|
|
19
|
-
|
|
22
|
+
return {
|
|
23
|
+
cancelled: true,
|
|
24
|
+
migrated: [],
|
|
25
|
+
rolledBack: []
|
|
26
|
+
};
|
|
20
27
|
}
|
|
21
28
|
}
|
|
22
29
|
payload.logger.info({
|
|
@@ -32,6 +39,7 @@ import prompts from 'prompts';
|
|
|
32
39
|
const req = {
|
|
33
40
|
payload
|
|
34
41
|
};
|
|
42
|
+
const migrated = [];
|
|
35
43
|
// Run all migrate up
|
|
36
44
|
for (const migration of migrationFiles){
|
|
37
45
|
payload.logger.info({
|
|
@@ -53,6 +61,7 @@ import prompts from 'prompts';
|
|
|
53
61
|
req
|
|
54
62
|
});
|
|
55
63
|
await commitTransaction(req);
|
|
64
|
+
migrated.push(migration.name);
|
|
56
65
|
payload.logger.info({
|
|
57
66
|
msg: `Migrated: ${migration.name} (${Date.now() - start}ms)`
|
|
58
67
|
});
|
|
@@ -65,6 +74,11 @@ import prompts from 'prompts';
|
|
|
65
74
|
throw err;
|
|
66
75
|
}
|
|
67
76
|
}
|
|
77
|
+
return {
|
|
78
|
+
batch: 1,
|
|
79
|
+
migrated,
|
|
80
|
+
rolledBack: []
|
|
81
|
+
};
|
|
68
82
|
}
|
|
69
83
|
|
|
70
84
|
//# sourceMappingURL=migrateFresh.js.map
|
package/dist/migrateFresh.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/migrateFresh.ts"],"sourcesContent":["import { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload'\nimport prompts from 'prompts'\n\nimport type { MongooseAdapter } from './index.js'\n\n/**\n * Drop the current database and run all migrate up functions\n */\nexport async function migrateFresh(\n this: MongooseAdapter,\n {
|
|
1
|
+
{"version":3,"sources":["../src/migrateFresh.ts"],"sourcesContent":["import type { MigrationResult } from 'payload'\n\nimport { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload'\nimport prompts from 'prompts'\n\nimport type { MongooseAdapter } from './index.js'\n\n/**\n * Drop the current database and run all migrate up functions\n */\nexport async function migrateFresh(\n this: MongooseAdapter,\n {\n forceAcceptWarning = false,\n shouldPrompt = true,\n }: { forceAcceptWarning?: boolean; shouldPrompt?: boolean },\n): Promise<MigrationResult> {\n const { payload } = this\n\n if (!forceAcceptWarning) {\n if (!shouldPrompt) {\n return { cancelled: true, migrated: [], rolledBack: [] }\n }\n\n const { confirm: acceptWarning } = await prompts({\n name: 'confirm',\n type: 'confirm',\n initial: false,\n message: `WARNING: This will drop your database and run all migrations. Are you sure you want to proceed?`,\n })\n\n if (!acceptWarning) {\n return { cancelled: true, migrated: [], rolledBack: [] }\n }\n }\n\n payload.logger.info({\n msg: `Dropping database.`,\n })\n\n await this.connection.dropDatabase()\n\n const migrationFiles = await readMigrationFiles({ payload })\n payload.logger.debug({\n msg: `Found ${migrationFiles.length} migration files.`,\n })\n\n const req = { payload }\n const migrated: string[] = []\n\n // Run all migrate up\n for (const migration of migrationFiles) {\n payload.logger.info({ msg: `Migrating: ${migration.name}` })\n try {\n const start = Date.now()\n await initTransaction(req)\n await migration.up({ payload, req })\n await payload.create({\n collection: 'payload-migrations',\n data: {\n name: migration.name,\n batch: 1,\n },\n req,\n })\n\n await commitTransaction(req)\n migrated.push(migration.name)\n\n payload.logger.info({ msg: `Migrated: ${migration.name} (${Date.now() - start}ms)` })\n } catch (err: unknown) {\n await killTransaction(req)\n payload.logger.error({\n err,\n msg: `Error running migration ${migration.name}. Rolling back.`,\n })\n throw err\n }\n }\n\n return { batch: 1, migrated, rolledBack: [] }\n}\n"],"names":["commitTransaction","initTransaction","killTransaction","readMigrationFiles","prompts","migrateFresh","forceAcceptWarning","shouldPrompt","payload","cancelled","migrated","rolledBack","confirm","acceptWarning","name","type","initial","message","logger","info","msg","connection","dropDatabase","migrationFiles","debug","length","req","migration","start","Date","now","up","create","collection","data","batch","push","err","error"],"mappings":"AAEA,SAASA,iBAAiB,EAAEC,eAAe,EAAEC,eAAe,EAAEC,kBAAkB,QAAQ,UAAS;AACjG,OAAOC,aAAa,UAAS;AAI7B;;CAEC,GACD,OAAO,eAAeC,aAEpB,EACEC,qBAAqB,KAAK,EAC1BC,eAAe,IAAI,EACsC;IAE3D,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IAExB,IAAI,CAACF,oBAAoB;QACvB,IAAI,CAACC,cAAc;YACjB,OAAO;gBAAEE,WAAW;gBAAMC,UAAU,EAAE;gBAAEC,YAAY,EAAE;YAAC;QACzD;QAEA,MAAM,EAAEC,SAASC,aAAa,EAAE,GAAG,MAAMT,QAAQ;YAC/CU,MAAM;YACNC,MAAM;YACNC,SAAS;YACTC,SAAS,CAAC,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UAAUb,IAAI,CAAC,eAAe,CAAC;YACjE;YACA,MAAMuB;QACR;IACF;IAEA,OAAO;QAAEF,OAAO;QAAGzB;QAAUC,YAAY,EAAE;IAAC;AAC9C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/db-mongodb",
|
|
3
|
-
"version": "4.0.0-canary.
|
|
3
|
+
"version": "4.0.0-canary.32",
|
|
4
4
|
"description": "The officially supported MongoDB database adapter for Payload",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -54,10 +54,10 @@
|
|
|
54
54
|
"mongodb": "7.5.0",
|
|
55
55
|
"mongodb-memory-server": "10.1.4",
|
|
56
56
|
"@payloadcms/eslint-config": "3.28.0",
|
|
57
|
-
"payload": "4.0.0-canary.
|
|
57
|
+
"payload": "4.0.0-canary.32"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"payload": "4.0.0-canary.
|
|
60
|
+
"payload": "4.0.0-canary.32"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "pnpm build:types && pnpm build:swc",
|