Path: blob/master/src/packages/database/postgres/schema/drop-deprecated-tables.ts
1503 views
/*1Drop ancient deprecated tables in some cases.23This doesn't work via any generic schema, but is some very specific code.4*/56import type { Client } from "@cocalc/database/pool";78export async function dropDeprecatedTables(db: Client) {9// There was a table compute_servers used from 2013-2016 with a primary key host.10// We drop that table from the database if it exists *with that primary key*.11// During sync we will then create the new compute_servers table, which has12// primary key "id", is modern, and does something completely different.1314const result = await db.query(`SELECT EXISTS (15SELECT FROM pg_class c16JOIN pg_namespace n on n.oid = c.relnamespace17WHERE c.relkind = 'r'18AND n.nspname = 'public'19AND c.relname = 'compute_servers'20AND exists (21SELECT 122FROM pg_attribute attr23JOIN pg_index idx on idx.indrelid = attr.attrelid24and idx.indkey[0] = attr.attnum25WHERE idx.indrelid = c.oid26AND idx.indisprimary27AND attr.attname = 'host'28));`);2930if (result.rows[0].exists) {31await db.query(`DROP TABLE compute_servers;`);32}33}343536