Skip to content

Commit 2a5052a

Browse files
committed
fix: migrations erreor, redesign migrations
1 parent f3f9e87 commit 2a5052a

35 files changed

Lines changed: 3280 additions & 12864 deletions

drizzle.config.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@ export default defineConfig({
66
dialect: 'postgresql',
77
breakpoints: false,
88
casing: 'snake_case',
9-
migrations: {
10-
prefix: 'index',
11-
table: 'migrations',
12-
schema: 'drizzle',
13-
},
149
strict: true,
1510
verbose: true,
1611
dbCredentials: {
1712
url: process.env.DATABASE_URL!,
1813
},
14+
introspect: { casing: 'camel' },
15+
schemaFilter: ['*'],
1916
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
DROP SCHEMA IF EXISTS "base" CASCADE;
2+
3+
CREATE SCHEMA "base";
4+
5+
CREATE TYPE "base"."team_role" AS ENUM (
6+
'owner',
7+
'admin',
8+
'lead',
9+
'moderator',
10+
'member',
11+
'viewer'
12+
);
13+
14+
CREATE TYPE "base"."member_status" AS ENUM ('active', 'banned', 'inactive');
15+
16+
CREATE TYPE "base"."layout_type" AS ENUM ('kanban', 'list', 'calendar', 'gantt');
17+
18+
CREATE TYPE "base"."project_status" AS ENUM ('active', 'archived', 'template', 'deleted');
19+
20+
CREATE TYPE "base"."project_visibility" AS ENUM ('public', 'private');
21+
22+
CREATE TYPE "base"."state_category" AS ENUM (
23+
'backlog',
24+
'active',
25+
'review',
26+
'completed',
27+
'archived'
28+
);
29+
30+
CREATE TYPE "base"."state_type" AS ENUM (
31+
'backlog',
32+
'todo',
33+
'in_progress',
34+
'review',
35+
'done',
36+
'archived',
37+
'custom'
38+
);

migrations/0000_stale_sunspot.sql

Lines changed: 0 additions & 1 deletion
This file was deleted.

migrations/0001_add_user.sql

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
CREATE TABLE
2+
"base"."user_activity" (
3+
"id" text PRIMARY KEY NOT NULL,
4+
"user_id" text NOT NULL,
5+
"event_type" varchar(50) NOT NULL,
6+
"entity_id" varchar,
7+
"metadata" jsonb,
8+
"created_at" timestamp
9+
with
10+
time zone DEFAULT now () NOT NULL
11+
);
12+
13+
CREATE TABLE "base"."user_notifications" (
14+
"user_id" text PRIMARY KEY NOT NULL,
15+
"settings" jsonb DEFAULT '{"email":{"task_assigned":true,"mentions":true,"daily_summary":false},"push":{"task_assigned":true,"reminders":true}}'::jsonb NOT NULL
16+
);
17+
18+
CREATE TABLE
19+
"base"."user_preferences" (
20+
"user_id" text PRIMARY KEY NOT NULL,
21+
"theme" text DEFAULT 'system',
22+
"timezone" varchar(50) DEFAULT 'UTC' NOT NULL,
23+
"language" varchar(5) DEFAULT 'ru' NOT NULL
24+
);
25+
26+
CREATE TABLE
27+
"base"."user_security" (
28+
"user_id" text PRIMARY KEY NOT NULL,
29+
"password_hash" varchar(255),
30+
"recovery_email" varchar(255),
31+
"is_2fa_enabled" boolean DEFAULT false NOT NULL,
32+
"two_factor_secret" text,
33+
"last_login_at" timestamp
34+
with
35+
time zone,
36+
"last_password_change" timestamp
37+
with
38+
time zone DEFAULT now () NOT NULL
39+
);
40+
41+
CREATE TABLE
42+
"base"."users" (
43+
"id" text PRIMARY KEY NOT NULL,
44+
"username" varchar(50),
45+
"headline" varchar(200),
46+
"location" varchar(255),
47+
"first_name" varchar(50) NOT NULL,
48+
"last_name" varchar(50) NOT NULL,
49+
"middle_name" varchar(50),
50+
"email" varchar(255) NOT NULL,
51+
"bio" text,
52+
"phone" varchar(20),
53+
"vacation_start" timestamp
54+
with
55+
time zone,
56+
"vacation_end" timestamp
57+
with
58+
time zone,
59+
"vacation_message" varchar(255),
60+
"gender" text DEFAULT 'none',
61+
"pronouns" text DEFAULT 'none',
62+
"pronouns_custom" varchar(50),
63+
"avatar_url" varchar(512),
64+
"email_verified" boolean DEFAULT false NOT NULL,
65+
"email_verified_at" timestamp
66+
with
67+
time zone,
68+
"last_team_id" text,
69+
"deleted_at" timestamp
70+
with
71+
time zone,
72+
"created_at" timestamp
73+
with
74+
time zone DEFAULT now () NOT NULL,
75+
"updated_at" timestamp
76+
with
77+
time zone DEFAULT now () NOT NULL,
78+
CONSTRAINT "users_username_unique" UNIQUE ("username"),
79+
CONSTRAINT "users_email_unique" UNIQUE ("email")
80+
);
81+
82+
CREATE TABLE
83+
"base"."user_identities" (
84+
"id" text PRIMARY KEY NOT NULL,
85+
"user_id" text NOT NULL,
86+
"provider" varchar(50) NOT NULL,
87+
"provider_user_id" varchar(255) NOT NULL,
88+
"email" varchar(255) NOT NULL,
89+
"avatar_url" varchar(255),
90+
"created_at" timestamp
91+
with
92+
time zone DEFAULT now () NOT NULL,
93+
CONSTRAINT "provider_user_id_idx" UNIQUE ("provider", "provider_user_id")
94+
);
95+
96+
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;
97+
98+
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;
99+
100+
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;
101+
102+
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;
103+
104+
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;

migrations/0001_solid_kronos.sql

Lines changed: 0 additions & 57 deletions
This file was deleted.

migrations/0002_add_session.sql

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
CREATE TABLE
2+
"base"."sessions" (
3+
"id" text PRIMARY KEY NOT NULL,
4+
"user_id" text NOT NULL,
5+
"device_type" varchar(20),
6+
"browser" varchar(50),
7+
"os" varchar(50),
8+
"user_agent" text NOT NULL,
9+
"ip" varchar(45) NOT NULL,
10+
"city" varchar(100),
11+
"country_code" varchar(5),
12+
"created_at" timestamp
13+
with
14+
time zone DEFAULT now () NOT NULL,
15+
"updated_at" timestamp
16+
with
17+
time zone DEFAULT now () NOT NULL,
18+
"expires_at" timestamp
19+
with
20+
time zone NOT NULL,
21+
"is_revoked" boolean DEFAULT false NOT NULL
22+
);
23+
24+
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;

migrations/0002_pink_krista_starr.sql

Lines changed: 0 additions & 56 deletions
This file was deleted.

migrations/0003_add_team.sql

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
CREATE TABLE
2+
"base"."team_members" (
3+
"team_id" text NOT NULL,
4+
"user_id" text NOT NULL,
5+
"role" "base"."team_role" DEFAULT 'member' NOT NULL,
6+
"status" "base"."member_status" DEFAULT 'inactive' NOT NULL,
7+
"joined_at" timestamp
8+
with
9+
time zone,
10+
"created_at" timestamp
11+
with
12+
time zone DEFAULT now () NOT NULL,
13+
CONSTRAINT "team_members_team_id_user_id_pk" PRIMARY KEY ("team_id", "user_id")
14+
);
15+
16+
CREATE TABLE
17+
"base"."teams" (
18+
"id" text PRIMARY KEY NOT NULL,
19+
"name" varchar(100) NOT NULL,
20+
"description" text,
21+
"avatar_url" text,
22+
"cover_url" text,
23+
"owner_id" text,
24+
"created_at" timestamp
25+
with
26+
time zone DEFAULT now () NOT NULL,
27+
"updated_at" timestamp
28+
with
29+
time zone DEFAULT now () NOT NULL,
30+
"deleted_at" timestamp
31+
with
32+
time zone
33+
);
34+
35+
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;
36+
37+
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;
38+
39+
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;
40+
41+
CREATE INDEX "member_status_idx" ON "base"."team_members" USING btree ("status");
42+
43+
CREATE INDEX "member_role_idx" ON "base"."team_members" USING btree ("user_id", "role");
44+
45+
CREATE INDEX "team_owner_idx" ON "base"."teams" USING btree ("owner_id");
46+
47+
CREATE INDEX "team_deleted_at_idx" ON "base"."teams" USING btree ("deleted_at");

migrations/0003_open_oracle.sql

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)