Skip to content

Commit 54b2245

Browse files
committed
adjust remediation that suggest editing to watch out for applied migrations
1 parent fbfd8e9 commit 54b2245

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

packages/database/dev/src/lib/migrations.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ const buildApplyFailureIssue = (options: {
134134
`or in the cumulative database state left by previously applied migrations ` +
135135
`(for example, the migration tries to create an object that an earlier migration already created, ` +
136136
`or references one that was never created).${codeNote} ` +
137-
`Resolve the issue in the failing migration or in the prior ones before deploying.`,
137+
`If the failing migration (or a prior one whose state is implicated) has not yet been applied to any database, ` +
138+
`fix its SQL. If it has already been applied, you likely edited the file after the fact — applied migrations ` +
139+
`are immutable, so restore it to its applied version (for example via version control or ` +
140+
`\`netlify database migrations pull --force\`). If neither situation matches, this may indicate a divergence ` +
141+
`between Postgres and the embedded engine used for this check — please file a bug.`,
138142
}
139143
}
140144

@@ -151,7 +155,10 @@ const buildMigrationFileIssue = (options: {
151155
migrationName: options.migrationName,
152156
sqlPath: options.sqlPath,
153157
summary: `Migration "${options.migrationName}" is missing its SQL file at ${options.sqlPath}.`,
154-
remediation: `Create the file at ${options.sqlPath}, or remove the migration's directory if it isn't intended.`,
158+
remediation:
159+
`Create the file at ${options.sqlPath}, or remove the migration's directory if it isn't intended. ` +
160+
`Only remove the directory if the migration has not yet been applied to any database — if it was applied, ` +
161+
`restore the file from version control instead.`,
155162
cause: options.cause,
156163
}
157164
}

packages/database/dev/src/lib/testMigrationsInEphemeralDatabase.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ test('Returns failure with migration-file-error (missing) when a migration direc
139139
/^Migration "0001_create_users" is missing its SQL file at .+0001_create_users[/\\]migration\.sql\.$/,
140140
)
141141
expect(issue.remediation).toMatch(
142-
/^Create the file at .+0001_create_users[/\\]migration\.sql, or remove the migration's directory if it isn't intended\.$/,
142+
/^Create the file at .+0001_create_users[/\\]migration\.sql, or remove the migration's directory if it isn't intended\. Only remove the directory if the migration has not yet been applied to any database if it was applied, restore the file from version control instead\.$/,
143143
)
144144
})
145145

@@ -169,7 +169,11 @@ test('Returns failure with apply-failure issue when a migration has a syntax err
169169
'or in the cumulative database state left by previously applied migrations ' +
170170
'(for example, the migration tries to create an object that an earlier migration already created, ' +
171171
'or references one that was never created). Postgres returned SQLSTATE 42601; look that up for common causes. ' +
172-
'Resolve the issue in the failing migration or in the prior ones before deploying.',
172+
'If the failing migration (or a prior one whose state is implicated) has not yet been applied to any database, ' +
173+
'fix its SQL. If it has already been applied, you likely edited the file after the fact — applied migrations ' +
174+
'are immutable, so restore it to its applied version (for example via version control or ' +
175+
'`netlify database migrations pull --force`). If neither situation matches, this may indicate a divergence ' +
176+
'between Postgres and the embedded engine used for this check — please file a bug.',
173177
)
174178
})
175179

@@ -196,6 +200,10 @@ test('Returns failure with apply-failure issue when a migration creates a relati
196200
'or in the cumulative database state left by previously applied migrations ' +
197201
'(for example, the migration tries to create an object that an earlier migration already created, ' +
198202
'or references one that was never created). Postgres returned SQLSTATE 42P07; look that up for common causes. ' +
199-
'Resolve the issue in the failing migration or in the prior ones before deploying.',
203+
'If the failing migration (or a prior one whose state is implicated) has not yet been applied to any database, ' +
204+
'fix its SQL. If it has already been applied, you likely edited the file after the fact — applied migrations ' +
205+
'are immutable, so restore it to its applied version (for example via version control or ' +
206+
'`netlify database migrations pull --force`). If neither situation matches, this may indicate a divergence ' +
207+
'between Postgres and the embedded engine used for this check — please file a bug.',
200208
)
201209
})

0 commit comments

Comments
 (0)