Skip to content

Commit 30997a0

Browse files
feat: telegram plugin for linking account (#6)
* feat: telegram plugin for linking account * release: v0.5.0 * fix: table migration * fix: missing unique
1 parent cba5a0d commit 30997a0

File tree

16 files changed

+1595
-10
lines changed

16 files changed

+1595
-10
lines changed

backend/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ RUN corepack enable
77
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
88
RUN pnpm run build
99
EXPOSE 3000
10-
CMD ["sh","-c", "pnpm run db:push && pnpm run start"]
10+
CMD ["sh","-c", "pnpm run db:migrate && pnpm run start"]
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
CREATE TABLE "auth_accounts" (
2+
"id" text PRIMARY KEY NOT NULL,
3+
"account_id" text NOT NULL,
4+
"provider_id" text NOT NULL,
5+
"user_id" text NOT NULL,
6+
"access_token" text,
7+
"refresh_token" text,
8+
"id_token" text,
9+
"access_token_expires_at" timestamp,
10+
"refresh_token_expires_at" timestamp,
11+
"scope" text,
12+
"password" text,
13+
"created_at" timestamp NOT NULL,
14+
"updated_at" timestamp NOT NULL
15+
);
16+
--> statement-breakpoint
17+
CREATE TABLE "auth_sessions" (
18+
"id" text PRIMARY KEY NOT NULL,
19+
"expires_at" timestamp NOT NULL,
20+
"token" text NOT NULL,
21+
"created_at" timestamp NOT NULL,
22+
"updated_at" timestamp NOT NULL,
23+
"ip_address" text,
24+
"user_agent" text,
25+
"user_id" text NOT NULL,
26+
CONSTRAINT "auth_sessions_token_unique" UNIQUE("token")
27+
);
28+
--> statement-breakpoint
29+
CREATE TABLE "auth_users" (
30+
"id" text PRIMARY KEY NOT NULL,
31+
"name" text NOT NULL,
32+
"email" text NOT NULL,
33+
"email_verified" boolean NOT NULL,
34+
"image" text,
35+
"created_at" timestamp NOT NULL,
36+
"updated_at" timestamp NOT NULL,
37+
CONSTRAINT "auth_users_email_unique" UNIQUE("email")
38+
);
39+
--> statement-breakpoint
40+
CREATE TABLE "auth_verifications" (
41+
"id" text PRIMARY KEY NOT NULL,
42+
"identifier" text NOT NULL,
43+
"value" text NOT NULL,
44+
"expires_at" timestamp NOT NULL,
45+
"created_at" timestamp,
46+
"updated_at" timestamp
47+
);
48+
--> statement-breakpoint
49+
CREATE TABLE "tg_groups" (
50+
"id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "tg_groups_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
51+
"telegram_id" bigint NOT NULL,
52+
"title" varchar NOT NULL,
53+
"link" varchar(128),
54+
"updated_at" timestamp (3),
55+
"created_at" timestamp (3) DEFAULT now() NOT NULL,
56+
CONSTRAINT "tg_groups_telegram_id_unique" UNIQUE("telegram_id")
57+
);
58+
--> statement-breakpoint
59+
CREATE TABLE "tg_group_admins" (
60+
"user_id" bigint NOT NULL,
61+
"group_id" bigint NOT NULL,
62+
"added_by_id" bigint NOT NULL,
63+
"updated_at" timestamp (3),
64+
"created_at" timestamp (3) DEFAULT now() NOT NULL,
65+
CONSTRAINT "tg_group_admins_user_id_group_id_pk" PRIMARY KEY("user_id","group_id")
66+
);
67+
--> statement-breakpoint
68+
CREATE TABLE "tg_permissions" (
69+
"user_id" bigint PRIMARY KEY NOT NULL,
70+
"role" varchar(128) DEFAULT 'admin' NOT NULL,
71+
"added_by_id" bigint NOT NULL,
72+
"modified_by_id" bigint,
73+
"updated_at" timestamp (3),
74+
"created_at" timestamp (3) DEFAULT now() NOT NULL
75+
);
76+
--> statement-breakpoint
77+
CREATE TABLE "tg_test" (
78+
"id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "tg_test_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
79+
"text" varchar NOT NULL
80+
);
81+
--> statement-breakpoint
82+
CREATE TABLE "web_test" (
83+
"id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "web_test_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
84+
"text" varchar NOT NULL
85+
);
86+
--> statement-breakpoint
87+
ALTER TABLE "auth_accounts" ADD CONSTRAINT "auth_accounts_user_id_auth_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."auth_users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
88+
ALTER TABLE "auth_sessions" ADD CONSTRAINT "auth_sessions_user_id_auth_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."auth_users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
89+
CREATE INDEX "telegram_id_idx" ON "tg_groups" USING btree ("telegram_id");--> statement-breakpoint
90+
CREATE INDEX "user_id_idx" ON "tg_group_admins" USING btree ("user_id");
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CREATE TABLE "tg_link" (
2+
"code" text PRIMARY KEY NOT NULL,
3+
"ttl" integer NOT NULL,
4+
"user_id" text NOT NULL,
5+
"tg_username" text NOT NULL,
6+
"tg_id" bigint,
7+
"updated_at" timestamp (3),
8+
"created_at" timestamp (3) DEFAULT now() NOT NULL,
9+
CONSTRAINT "tg_link_tg_id_unique" UNIQUE("tg_id")
10+
);
11+
--> statement-breakpoint
12+
ALTER TABLE "auth_users" ADD COLUMN "tg_id" bigint;--> statement-breakpoint
13+
ALTER TABLE "auth_users" ADD COLUMN "tg_username" text;--> statement-breakpoint
14+
ALTER TABLE "tg_link" ADD CONSTRAINT "tg_link_user_id_auth_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."auth_users"("id") ON DELETE no action ON UPDATE no action;

0 commit comments

Comments
 (0)