Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 61 additions & 1 deletion templates/cli/lib/commands/push.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ const {
tablesDBUpdateTable,
tablesDBList,
tablesDBDelete,
tablesDBListTables
tablesDBListTables,
tablesDBDeleteTable
} = require("./tables-db");
const {
storageGetBucket, storageUpdateBucket, storageCreateBucket
Expand Down Expand Up @@ -1884,6 +1885,65 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
console.log();
}

log('Checking for deleted tables ...');
const localTablesDBs = localConfig.getTablesDBs();
const localTables = localConfig.getTables();
const tablesToDelete = [];

for (const db of localTablesDBs) {
try {
const { tables: remoteTables } = await paginate(tablesDBListTables, {
databaseId: db.$id,
parseOutput: false
}, 100, 'tables');

for (const remoteTable of remoteTables) {
const localTable = localTables.find(t => t.$id === remoteTable.$id && t.databaseId === db.$id);
if (!localTable) {
tablesToDelete.push({
...remoteTable,
databaseId: db.$id,
databaseName: db.name
});
}
}
} catch (e) {
// Skip if database doesn't exist or other errors
}
}

if (tablesToDelete.length > 0) {
log('Found tables that exist remotely but not locally:');
const deletionChanges = tablesToDelete.map(table => ({
id: table.$id,
action: chalk.red('deleting'),
key: 'Table',
database: table.databaseName,
remote: table.name,
local: '(deleted locally)'
}));
drawTable(deletionChanges);

if ((await getConfirmation()) === true) {
for (const table of tablesToDelete) {
try {
log(`Deleting table ${table.name} ( ${table.$id} ) from database ${table.databaseName} ...`);
await tablesDBDeleteTable({
databaseId: table.databaseId,
tableId: table.$id,
parseOutput: false
});
success(`Deleted ${table.name} ( ${table.$id} )`);
} catch (e) {
error(`Failed to delete table ${table.name} ( ${table.$id} ): ${e.message}`);
}
}
}
} else {
console.log('No tables found to delete');
}
console.log();

if (cliConfig.all) {
checkDeployConditions(localConfig);
tables.push(...localConfig.getTables());
Expand Down
Loading