Skip to content

Commit ff82bb5

Browse files
authored
fix(db-postgres)!: create predefined migration missing json schema output (#6641)
## Description fixes #6630 # BREAKING CHANGES This only applies to you if you using db-postgres and have created the `v2-v3-relationships` migration released in [v3.0.0-beta.39](https://github.com/payloadcms/payload/releases/tag/v3.0.0-beta.39) from @payloadcms/db-postgres <= v3.0.0-beta.40. ### Steps to fix - Delete the existing v2-v3-relationships migration file. - If changes were made to your config since the previous migration was made, you will need to revert those by checking out a previous commit in your version control. - Recreate the migration using `payload migrate:create --file @payloadcms/db-postgres/relationships-v2-v3` to make the migration with the snapshot .json file.
1 parent 8a78134 commit ff82bb5

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

packages/db-postgres/src/createMigration.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ export const createMigration: CreateMigration = async function createMigration(
121121
process.exit(0)
122122
}
123123
}
124-
125-
// write schema
126-
fs.writeFileSync(`${filePath}.json`, JSON.stringify(drizzleJsonAfter, null, 2))
127124
}
128125

126+
// write schema
127+
fs.writeFileSync(`${filePath}.json`, JSON.stringify(drizzleJsonAfter, null, 2))
128+
129129
// write migration
130130
fs.writeFileSync(
131131
`${filePath}.ts`,

packages/db-postgres/src/predefinedMigrations/v2-v3/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,21 @@ export const migratePostgresV2toV3 = async ({ debug, payload, req }: Args) => {
4646
const { generateDrizzleJson, generateMigration } = require('drizzle-kit/payload')
4747
const drizzleJsonAfter = generateDrizzleJson(adapter.schema)
4848

49-
// Get latest migration snapshot
50-
const latestSnapshot = fs
49+
// Get the previous migration snapshot
50+
const previousSnapshot = fs
5151
.readdirSync(dir)
52-
.filter((file) => file.endsWith('.json'))
52+
.filter((file) => file.endsWith('.json') && !file.endsWith('relationships_v2_v3.json'))
5353
.sort()
5454
.reverse()?.[0]
5555

56-
if (!latestSnapshot) {
56+
if (!previousSnapshot) {
5757
throw new Error(
5858
`No previous migration schema file found! A prior migration from v2 is required to migrate to v3.`,
5959
)
6060
}
6161

6262
const drizzleJsonBefore = JSON.parse(
63-
fs.readFileSync(`${dir}/${latestSnapshot}`, 'utf8'),
63+
fs.readFileSync(`${dir}/${previousSnapshot}`, 'utf8'),
6464
) as DrizzleSnapshotJSON
6565

6666
const generatedSQL = await generateMigration(drizzleJsonBefore, drizzleJsonAfter)

packages/db-postgres/src/utilities/pushDevSchema.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ export const pushDevSchema = async (db: PostgresAdapter) => {
1717
const { pushSchema } = require('drizzle-kit/payload')
1818

1919
// This will prompt if clarifications are needed for Drizzle to push new schema
20-
const { apply, hasDataLoss, statementsToExecute, warnings } = await pushSchema(
21-
db.schema,
22-
db.drizzle,
23-
)
20+
const { apply, hasDataLoss, warnings } = await pushSchema(db.schema, db.drizzle)
2421

2522
if (warnings.length) {
2623
let message = `Warnings detected during schema push: \n\n${warnings.join('\n')}\n\n`

0 commit comments

Comments
 (0)