Files
germantax-e2e-mrg0vbxr/db/sqlite/0003-ba-organization.sql
2026-07-11 09:07:34 +02:00

34 lines
1.3 KiB
SQL

-- Better Auth organization plugin tables.
-- Adds organization, member, invitation tables used by the organization() plugin.
CREATE TABLE IF NOT EXISTS "organization" (
"id" text not null primary key,
"name" text not null,
"slug" text unique,
"logo" text,
"created_at" date not null,
"metadata" text
);
CREATE TABLE IF NOT EXISTS "member" (
"id" text not null primary key,
"organization_id" text not null references "organization" ("id") on delete cascade,
"user_id" text not null references "user" ("id") on delete cascade,
"role" text not null,
"created_at" date not null
);
CREATE TABLE IF NOT EXISTS "invitation" (
"id" text not null primary key,
"organization_id" text not null references "organization" ("id") on delete cascade,
"email" text not null,
"role" text,
"status" text not null,
"expires_at" date not null,
"inviter_id" text not null references "user" ("id") on delete cascade
);
CREATE INDEX IF NOT EXISTS "member_organization_id_idx" ON "member" ("organization_id");
CREATE INDEX IF NOT EXISTS "member_user_id_idx" ON "member" ("user_id");
CREATE INDEX IF NOT EXISTS "invitation_organization_id_idx" ON "invitation" ("organization_id");