Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 2 additions & 5 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ export default defineConfig({
dialect: 'postgresql',
breakpoints: false,
casing: 'snake_case',
migrations: {
prefix: 'index',
table: 'migrations',
schema: 'drizzle',
},
strict: true,
verbose: true,
dbCredentials: {
url: process.env.DATABASE_URL!,
},
introspect: { casing: 'camel' },
schemaFilter: ['*'],
});
38 changes: 38 additions & 0 deletions migrations/0000_initial_migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
DROP SCHEMA IF EXISTS "base" CASCADE;

CREATE SCHEMA "base";

CREATE TYPE "base"."team_role" AS ENUM (
'owner',
'admin',
'lead',
'moderator',
'member',
'viewer'
);

CREATE TYPE "base"."member_status" AS ENUM ('active', 'banned', 'inactive');

CREATE TYPE "base"."layout_type" AS ENUM ('kanban', 'list', 'calendar', 'gantt');

CREATE TYPE "base"."project_status" AS ENUM ('active', 'archived', 'template', 'deleted');

CREATE TYPE "base"."project_visibility" AS ENUM ('public', 'private');

CREATE TYPE "base"."state_category" AS ENUM (
'backlog',
'active',
'review',
'completed',
'archived'
);

CREATE TYPE "base"."state_type" AS ENUM (
'backlog',
'todo',
'in_progress',
'review',
'done',
'archived',
'custom'
);
1 change: 0 additions & 1 deletion migrations/0000_stale_sunspot.sql

This file was deleted.

104 changes: 104 additions & 0 deletions migrations/0001_add_user.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
CREATE TABLE
"base"."user_activity" (
"id" text PRIMARY KEY NOT NULL,
"user_id" text NOT NULL,
"event_type" varchar(50) NOT NULL,
"entity_id" varchar,
"metadata" jsonb,
"created_at" timestamp
with
time zone DEFAULT now () NOT NULL
);

CREATE TABLE "base"."user_notifications" (
"user_id" text PRIMARY KEY NOT NULL,
"settings" jsonb DEFAULT '{"email":{"task_assigned":true,"mentions":true,"daily_summary":false},"push":{"task_assigned":true,"reminders":true}}'::jsonb NOT NULL
);

CREATE TABLE
"base"."user_preferences" (
"user_id" text PRIMARY KEY NOT NULL,
"theme" text DEFAULT 'system',
"timezone" varchar(50) DEFAULT 'UTC' NOT NULL,
"language" varchar(5) DEFAULT 'ru' NOT NULL
);

CREATE TABLE
"base"."user_security" (
"user_id" text PRIMARY KEY NOT NULL,
"password_hash" varchar(255),
"recovery_email" varchar(255),
"is_2fa_enabled" boolean DEFAULT false NOT NULL,
"two_factor_secret" text,
"last_login_at" timestamp
with
time zone,
"last_password_change" timestamp
with
time zone DEFAULT now () NOT NULL
);

CREATE TABLE
"base"."users" (
"id" text PRIMARY KEY NOT NULL,
"username" varchar(50),
"headline" varchar(200),
"location" varchar(255),
"first_name" varchar(50) NOT NULL,
"last_name" varchar(50) NOT NULL,
"middle_name" varchar(50),
"email" varchar(255) NOT NULL,
"bio" text,
"phone" varchar(20),
"vacation_start" timestamp
with
time zone,
"vacation_end" timestamp
with
time zone,
"vacation_message" varchar(255),
"gender" text DEFAULT 'none',
"pronouns" text DEFAULT 'none',
"pronouns_custom" varchar(50),
"avatar_url" varchar(512),
"email_verified" boolean DEFAULT false NOT NULL,
"email_verified_at" timestamp
with
time zone,
"last_team_id" text,
"deleted_at" timestamp
with
time zone,
"created_at" timestamp
with
time zone DEFAULT now () NOT NULL,
"updated_at" timestamp
with
time zone DEFAULT now () NOT NULL,
CONSTRAINT "users_username_unique" UNIQUE ("username"),
CONSTRAINT "users_email_unique" UNIQUE ("email")
);

CREATE TABLE
"base"."user_identities" (
"id" text PRIMARY KEY NOT NULL,
"user_id" text NOT NULL,
"provider" varchar(50) NOT NULL,
"provider_user_id" varchar(255) NOT NULL,
"email" varchar(255) NOT NULL,
"avatar_url" varchar(255),
"created_at" timestamp
with
time zone DEFAULT now () NOT NULL,
CONSTRAINT "provider_user_id_idx" UNIQUE ("provider", "provider_user_id")
);

ALTER TABLE "base"."user_activity" ADD CONSTRAINT "user_activity_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "base"."users" ("id") ON DELETE cascade ON UPDATE no action;

ALTER TABLE "base"."user_notifications" ADD CONSTRAINT "user_notifications_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "base"."users" ("id") ON DELETE cascade ON UPDATE no action;

ALTER TABLE "base"."user_preferences" ADD CONSTRAINT "user_preferences_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "base"."users" ("id") ON DELETE cascade ON UPDATE no action;

ALTER TABLE "base"."user_security" ADD CONSTRAINT "user_security_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "base"."users" ("id") ON DELETE cascade ON UPDATE no action;

ALTER TABLE "base"."user_identities" ADD CONSTRAINT "user_identities_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "base"."users" ("id") ON DELETE cascade ON UPDATE no action;
57 changes: 0 additions & 57 deletions migrations/0001_solid_kronos.sql

This file was deleted.

24 changes: 24 additions & 0 deletions migrations/0002_add_session.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
CREATE TABLE
"base"."sessions" (
"id" text PRIMARY KEY NOT NULL,
"user_id" text NOT NULL,
"device_type" varchar(20),
"browser" varchar(50),
"os" varchar(50),
"user_agent" text NOT NULL,
"ip" varchar(45) NOT NULL,
"city" varchar(100),
"country_code" varchar(5),
"created_at" timestamp
with
time zone DEFAULT now () NOT NULL,
"updated_at" timestamp
with
time zone DEFAULT now () NOT NULL,
"expires_at" timestamp
with
time zone NOT NULL,
"is_revoked" boolean DEFAULT false NOT NULL
);

ALTER TABLE "base"."sessions" ADD CONSTRAINT "sessions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "base"."users" ("id") ON DELETE cascade ON UPDATE no action;
56 changes: 0 additions & 56 deletions migrations/0002_pink_krista_starr.sql

This file was deleted.

47 changes: 47 additions & 0 deletions migrations/0003_add_team.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
CREATE TABLE
"base"."team_members" (
"team_id" text NOT NULL,
"user_id" text NOT NULL,
"role" "base"."team_role" DEFAULT 'member' NOT NULL,
"status" "base"."member_status" DEFAULT 'inactive' NOT NULL,
"joined_at" timestamp
with
time zone,
"created_at" timestamp
with
time zone DEFAULT now () NOT NULL,
CONSTRAINT "team_members_team_id_user_id_pk" PRIMARY KEY ("team_id", "user_id")
);

CREATE TABLE
"base"."teams" (
"id" text PRIMARY KEY NOT NULL,
"name" varchar(100) NOT NULL,
"description" text,
"avatar_url" text,
"cover_url" text,
"owner_id" text,
"created_at" timestamp
with
time zone DEFAULT now () NOT NULL,
"updated_at" timestamp
with
time zone DEFAULT now () NOT NULL,
"deleted_at" timestamp
with
time zone
);

ALTER TABLE "base"."team_members" ADD CONSTRAINT "team_members_team_id_teams_id_fk" FOREIGN KEY ("team_id") REFERENCES "base"."teams" ("id") ON DELETE cascade ON UPDATE no action;

ALTER TABLE "base"."team_members" ADD CONSTRAINT "team_members_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "base"."users" ("id") ON DELETE cascade ON UPDATE no action;

ALTER TABLE "base"."teams" ADD CONSTRAINT "teams_owner_id_users_id_fk" FOREIGN KEY ("owner_id") REFERENCES "base"."users" ("id") ON DELETE set null ON UPDATE no action;

CREATE INDEX "member_status_idx" ON "base"."team_members" USING btree ("status");

CREATE INDEX "member_role_idx" ON "base"."team_members" USING btree ("user_id", "role");

CREATE INDEX "team_owner_idx" ON "base"."teams" USING btree ("owner_id");

CREATE INDEX "team_deleted_at_idx" ON "base"."teams" USING btree ("deleted_at");
18 changes: 0 additions & 18 deletions migrations/0003_open_oracle.sql

This file was deleted.

Loading
Loading