Add bridge migrations

This commit is contained in:
Darren Clarke 2024-04-23 10:31:26 +02:00
parent e05fdef4ad
commit 2c43e81436
14 changed files with 847 additions and 7 deletions

View file

@ -0,0 +1,72 @@
import { Kysely, sql } from "kysely";
export async function up(db: Kysely<any>): Promise<void> {
await db.schema
.createTable("User")
.addColumn("id", "uuid", (col) =>
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
)
.addColumn("name", "text")
.addColumn("email", "text", (col) => col.unique().notNull())
.addColumn("emailVerified", "timestamptz")
.addColumn("image", "text")
.execute();
await db.schema
.createTable("Account")
.addColumn("id", "uuid", (col) =>
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
)
.addColumn("userId", "uuid", (col) =>
col.references("User.id").onDelete("cascade").notNull(),
)
.addColumn("type", "text", (col) => col.notNull())
.addColumn("provider", "text", (col) => col.notNull())
.addColumn("providerAccountId", "text", (col) => col.notNull())
.addColumn("refresh_token", "text")
.addColumn("access_token", "text")
.addColumn("expires_at", "bigint")
.addColumn("token_type", "text")
.addColumn("scope", "text")
.addColumn("id_token", "text")
.addColumn("session_state", "text")
.execute();
await db.schema
.createTable("Session")
.addColumn("id", "uuid", (col) =>
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
)
.addColumn("userId", "uuid", (col) =>
col.references("User.id").onDelete("cascade").notNull(),
)
.addColumn("sessionToken", "text", (col) => col.notNull().unique())
.addColumn("expires", "timestamptz", (col) => col.notNull())
.execute();
await db.schema
.createTable("VerificationToken")
.addColumn("identifier", "text", (col) => col.notNull())
.addColumn("token", "text", (col) => col.notNull().unique())
.addColumn("expires", "timestamptz", (col) => col.notNull())
.execute();
await db.schema
.createIndex("Account_userId_index")
.on("Account")
.column("userId")
.execute();
await db.schema
.createIndex("Session_userId_index")
.on("Session")
.column("userId")
.execute();
}
export async function down(db: Kysely<any>): Promise<void> {
await db.schema.dropTable("Account").ifExists().execute();
await db.schema.dropTable("Session").ifExists().execute();
await db.schema.dropTable("User").ifExists().execute();
await db.schema.dropTable("VerificationToken").ifExists().execute();
}

View file

@ -0,0 +1,34 @@
import { Kysely, sql } from "kysely";
export async function up(db: Kysely<any>): Promise<void> {
await db.schema
.createTable("SignalBot")
.addColumn("id", "uuid", (col) =>
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
)
.addColumn("phone_number", "text")
.addColumn("token", "text", (col) => col.unique().notNull())
.addColumn("user_id", "uuid")
.addColumn("description", "text")
.addColumn("auth_info", "text")
.addColumn("is_verified", "boolean", (col) =>
col.notNull().defaultTo(false),
)
.addColumn("created_at", "timestamptz", (col) =>
col.notNull().defaultTo(sql`now()`),
)
.addColumn("updated_at", "timestamptz", (col) =>
col.notNull().defaultTo(sql`now()`),
)
.execute();
await db.schema
.createIndex("SignalBotToken")
.on("SignalBot")
.column("token")
.execute();
}
export async function down(db: Kysely<any>): Promise<void> {
await db.schema.dropTable("SignalBot").ifExists().execute();
}

View file

@ -0,0 +1,34 @@
import { Kysely, sql } from "kysely";
export async function up(db: Kysely<any>): Promise<void> {
await db.schema
.createTable("WhatsappBot")
.addColumn("id", "uuid", (col) =>
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
)
.addColumn("phone_number", "text")
.addColumn("token", "text", (col) => col.unique().notNull())
.addColumn("user_id", "uuid")
.addColumn("description", "text")
.addColumn("auth_info", "text")
.addColumn("is_verified", "boolean", (col) =>
col.notNull().defaultTo(false),
)
.addColumn("created_at", "timestamptz", (col) =>
col.notNull().defaultTo(sql`now()`),
)
.addColumn("updated_at", "timestamptz", (col) =>
col.notNull().defaultTo(sql`now()`),
)
.execute();
await db.schema
.createIndex("WhatsappBotToken")
.on("WhatsappBot")
.column("token")
.execute();
}
export async function down(db: Kysely<any>): Promise<void> {
await db.schema.dropTable("WhatsappBot").ifExists().execute();
}

View file

@ -0,0 +1,74 @@
import { Kysely, sql } from "kysely";
export async function up(db: Kysely<any>): Promise<void> {
await db.schema
.createTable("VoiceProvider")
.addColumn("id", "uuid", (col) =>
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
)
.addColumn("kind", "text", (col) => col.notNull())
.addColumn("name", "text", (col) => col.notNull())
.addColumn("credentials", "jsonb", (col) => col.notNull())
.addColumn("created_at", "timestamptz", (col) =>
col.notNull().defaultTo(sql`now()`),
)
.addColumn("updated_at", "timestamptz", (col) =>
col.notNull().defaultTo(sql`now()`),
)
.execute();
await db.schema
.createIndex("VoiceProviderName")
.on("VoiceProvider")
.column("name")
.execute();
await db.schema
.createTable("VoiceLine")
.addColumn("id", "uuid", (col) =>
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
)
.addColumn("provider_id", "uuid", (col) =>
col.notNull().references("VoiceProvider.id").onDelete("cascade"),
)
.addColumn("provider_line_sid", "text", (col) => col.notNull())
.addColumn("number", "text", (col) => col.notNull())
.addColumn("language", "text", (col) => col.notNull())
.addColumn("voice", "text", (col) => col.notNull())
.addColumn("prompt_text", "text")
.addColumn("prompt_audio", "jsonb")
.addColumn("audio_prompt_enabled", "boolean", (col) =>
col.notNull().defaultTo(false),
)
.addColumn("audio_converted_at", "timestamptz")
.addColumn("created_at", "timestamptz", (col) =>
col.notNull().defaultTo(sql`now()`),
)
.addColumn("updated_at", "timestamptz", (col) =>
col.notNull().defaultTo(sql`now()`),
)
.execute();
await db.schema
.createIndex("VoiceLineProviderId")
.on("VoiceLine")
.column("provider_id")
.execute();
await db.schema
.createIndex("VoiceLineProviderLineSid")
.on("VoiceLine")
.column("provider_line_sid")
.execute();
await db.schema
.createIndex("VoiceLineNumber")
.on("VoiceLine")
.column("number")
.execute();
}
export async function down(db: Kysely<any>): Promise<void> {
await db.schema.dropTable("VoiceLine").ifExists().execute();
await db.schema.dropTable("VoiceProvider").ifExists().execute();
}

View file

@ -0,0 +1,34 @@
import { Kysely, sql } from "kysely";
export async function up(db: Kysely<any>): Promise<void> {
await db.schema
.createTable("FacebookBot")
.addColumn("id", "uuid", (col) =>
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
)
.addColumn("phone_number", "text")
.addColumn("token", "text", (col) => col.unique().notNull())
.addColumn("user_id", "uuid")
.addColumn("description", "text")
.addColumn("auth_info", "text")
.addColumn("is_verified", "boolean", (col) =>
col.notNull().defaultTo(false),
)
.addColumn("created_at", "timestamptz", (col) =>
col.notNull().defaultTo(sql`now()`),
)
.addColumn("updated_at", "timestamptz", (col) =>
col.notNull().defaultTo(sql`now()`),
)
.execute();
await db.schema
.createIndex("FacebookBotToken")
.on("FacebookBot")
.column("token")
.execute();
}
export async function down(db: Kysely<any>): Promise<void> {
await db.schema.dropTable("FacebookBot").ifExists().execute();
}

View file

@ -0,0 +1,40 @@
import { Kysely, sql } from "kysely";
export async function up(db: Kysely<any>): Promise<void> {
await db.schema
.createTable("Webhook")
.addColumn("id", "uuid", (col) =>
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
)
.addColumn("backend_type", "text", (col) => col.notNull())
.addColumn("backend_id", "uuid", (col) => col.notNull())
.addColumn("name", "text", (col) => col.notNull())
.addColumn("endpoint_url", "text", (col) =>
col.notNull().check(sql`endpoint_url ~ '^https?://[^/]+'`),
)
.addColumn("http_method", "text", (col) =>
col
.notNull()
.defaultTo("post")
.check(sql`http_method in ('post', 'put')`),
)
.addColumn("headers", "jsonb")
.addColumn("created_at", "timestamptz", (col) =>
col.notNull().defaultTo(sql`now()`),
)
.addColumn("updated_at", "timestamptz", (col) =>
col.notNull().defaultTo(sql`now()`),
)
.execute();
await db.schema
.createIndex("WebhookBackendTypeBackendId")
.on("Webhook")
.column("backend_type")
.column("backend_id")
.execute();
}
export async function down(db: Kysely<any>): Promise<void> {
await db.schema.dropTable("Webhook").ifExists().execute();
}

View file

@ -0,0 +1,28 @@
import { Kysely, sql } from "kysely";
export async function up(db: Kysely<any>): Promise<void> {
await db.schema
.createTable("Setting")
.addColumn("id", "uuid", (col) =>
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
)
.addColumn("name", "text")
.addColumn("value", "jsonb")
.addColumn("created_at", "timestamptz", (col) =>
col.notNull().defaultTo(sql`now()`),
)
.addColumn("updated_at", "timestamptz", (col) =>
col.notNull().defaultTo(sql`now()`),
)
.execute();
await db.schema
.createIndex("SettingName")
.on("Setting")
.column("name")
.execute();
}
export async function down(db: Kysely<any>): Promise<void> {
await db.schema.dropTable("Setting").ifExists().execute();
}