backend/config/setup/tables/guilds/index.ts
creations 0cb7ebb245
All checks were successful
Code quality checks / biome (push) Successful in 8s
add user info, add table drop for dev env, fix invite route
2025-05-04 08:59:36 -04:00

46 lines
880 B
TypeScript

import { cassandra } from "@lib/cassandra";
async function createTable() {
const client = cassandra.getClient();
// main guilds table
await client.execute(`
CREATE TABLE IF NOT EXISTS guilds (
id TEXT PRIMARY KEY,
name TEXT,
icon TEXT,
owner_id TEXT,
system_channel_id TEXT,
rules_channel_id TEXT,
announcements_channel_id TEXT,
created_at TIMESTAMP,
updated_at TIMESTAMP
);
`);
// lookup table to enforce unique guild names per user
await client.execute(`
CREATE TABLE IF NOT EXISTS guilds_by_owner (
owner_id TEXT,
name TEXT,
guild_id TEXT,
PRIMARY KEY ((owner_id), name)
);
`);
}
async function dropTable() {
const client = cassandra.getClient();
await client.execute(`
DROP TABLE IF EXISTS guilds;
`);
await client.execute(`
DROP TABLE IF EXISTS guilds_by_owner;
`);
}
export { createTable, dropTable };