0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

Provide better messaging when renaming a table (#10600)

* Provide better messaging when renaming a table

* Update based on review
This commit is contained in:
Matthew Phillips 2024-04-08 09:21:41 -04:00 committed by GitHub
parent fa0f593890
commit 28e7535e5c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 28 additions and 6 deletions

View file

@ -0,0 +1,5 @@
---
"@astrojs/db": patch
---
Provide better messaging when renaming a table

View file

@ -12,6 +12,7 @@ import {
getMigrationQueries,
getProductionCurrentSnapshot,
} from '../../migration-queries.js';
import prompts from 'prompts';
export async function cmd({
dbConfig,
@ -41,6 +42,18 @@ export async function cmd({
}
if (isForceReset) {
const { begin } = await prompts({
type: "confirm",
name: "begin",
message: `Reset your database? All of your data will be erased and your schema created from scratch.`,
initial: false
});
if(!begin) {
console.log("Canceled.");
process.exit(0);
}
console.log(`Force-pushing to the database. All existing data will be erased.`);
} else if (confirmations.length > 0) {
console.log('\n' + formatDataLossMessage(confirmations) + '\n');

View file

@ -64,9 +64,9 @@ export async function getMigrationQueries({
Object.entries(droppedTables).filter(([, table]) => !table.deprecated)
);
if (!isEmpty(addedTables) && !isEmpty(notDeprecatedDroppedTables)) {
throw new Error(
RENAME_TABLE_ERROR(Object.keys(addedTables)[0], Object.keys(notDeprecatedDroppedTables)[0])
);
const oldTable = Object.keys(notDeprecatedDroppedTables)[0];
const newTable = Object.keys(addedTables)[0];
throw new Error(RENAME_TABLE_ERROR(oldTable, newTable));
}
for (const [tableName, table] of Object.entries(addedTables)) {

View file

@ -16,9 +16,13 @@ export const MISSING_EXECUTE_PATH_ERROR = `${red(
export const RENAME_TABLE_ERROR = (oldTable: string, newTable: string) => {
return (
red('▶ Potential table rename detected: ' + oldTable + ', ' + newTable) +
`\n You cannot add and remove tables in the same schema update batch.` +
`\n To resolve, add a 'deprecated: true' flag to '${oldTable}' instead.`
red("\u25B6 Potential table rename detected: " + oldTable + " -> " + newTable) + `
You cannot add and remove tables in the same schema update batch.
1. Use "deprecated: true" to deprecate a table before renaming.
2. Use "--force-reset" to ignore this warning and reset the database (deleting all of your data).
Visit https://docs.astro.build/en/guides/astro-db/#renaming-tables to learn more.`
);
};