summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/old-planes-walk.md5
-rw-r--r--packages/db/src/core/cli/commands/push/index.ts13
-rw-r--r--packages/db/src/core/cli/migration-queries.ts6
-rw-r--r--packages/db/src/core/errors.ts10
4 files changed, 28 insertions, 6 deletions
diff --git a/.changeset/old-planes-walk.md b/.changeset/old-planes-walk.md
new file mode 100644
index 000000000..46c7da3f4
--- /dev/null
+++ b/.changeset/old-planes-walk.md
@@ -0,0 +1,5 @@
+---
+"@astrojs/db": patch
+---
+
+Provide better messaging when renaming a table
diff --git a/packages/db/src/core/cli/commands/push/index.ts b/packages/db/src/core/cli/commands/push/index.ts
index ba4a5392f..40c3e795b 100644
--- a/packages/db/src/core/cli/commands/push/index.ts
+++ b/packages/db/src/core/cli/commands/push/index.ts
@@ -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');
diff --git a/packages/db/src/core/cli/migration-queries.ts b/packages/db/src/core/cli/migration-queries.ts
index bf89a579c..d5fe959cb 100644
--- a/packages/db/src/core/cli/migration-queries.ts
+++ b/packages/db/src/core/cli/migration-queries.ts
@@ -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)) {
diff --git a/packages/db/src/core/errors.ts b/packages/db/src/core/errors.ts
index 64ff271d8..c27b0cba7 100644
--- a/packages/db/src/core/errors.ts
+++ b/packages/db/src/core/errors.ts
@@ -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.`
);
};