Skip to content

Commit 7b2af8b

Browse files
committed
feat: initial drizzle setup
1 parent c15bf27 commit 7b2af8b

File tree

7 files changed

+3066
-0
lines changed

7 files changed

+3066
-0
lines changed

drizzle.config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import 'dotenv/config';
2+
import { defineConfig } from 'drizzle-kit';
3+
4+
export default defineConfig({
5+
dialect: 'postgresql',
6+
out: './src/drizzle',
7+
schema: './src/drizzle/schema.ts',
8+
dbCredentials: {
9+
url: process.env.DATABASE_URL as string,
10+
},
11+
verbose: true,
12+
strict: true,
13+
});

src/drizzle/0000_bouncy_mantis.sql

Lines changed: 287 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,287 @@
1+
CREATE TYPE "public"."IncompleteFileStatus" AS ENUM('PENDING', 'PROCESSING', 'COMPLETE', 'FAILED');--> statement-breakpoint
2+
CREATE TYPE "public"."OAuthProviderType" AS ENUM('DISCORD', 'GOOGLE', 'GITHUB', 'OIDC');--> statement-breakpoint
3+
CREATE TYPE "public"."Role" AS ENUM('USER', 'ADMIN', 'SUPERADMIN');--> statement-breakpoint
4+
CREATE TYPE "public"."UserFilesQuota" AS ENUM('BY_BYTES', 'BY_FILES');--> statement-breakpoint
5+
6+
--> statement-breakpoint
7+
CREATE TABLE "Zipline" (
8+
"id" text PRIMARY KEY NOT NULL,
9+
"createdAt" timestamp(3) DEFAULT CURRENT_TIMESTAMP NOT NULL,
10+
"updatedAt" timestamp(3) NOT NULL,
11+
"firstSetup" boolean DEFAULT true NOT NULL,
12+
"coreReturnHttpsUrls" boolean DEFAULT false NOT NULL,
13+
"coreDefaultDomain" text,
14+
"coreTempDirectory" text NOT NULL,
15+
"chunksEnabled" boolean DEFAULT true NOT NULL,
16+
"chunksMax" text DEFAULT '95mb' NOT NULL,
17+
"chunksSize" text DEFAULT '25mb' NOT NULL,
18+
"tasksDeleteInterval" text DEFAULT '30m' NOT NULL,
19+
"tasksClearInvitesInterval" text DEFAULT '30m' NOT NULL,
20+
"tasksMaxViewsInterval" text DEFAULT '30m' NOT NULL,
21+
"tasksThumbnailsInterval" text DEFAULT '30m' NOT NULL,
22+
"tasksMetricsInterval" text DEFAULT '30m' NOT NULL,
23+
"filesRoute" text DEFAULT '/u' NOT NULL,
24+
"filesLength" integer DEFAULT 6 NOT NULL,
25+
"filesDefaultFormat" text DEFAULT 'random' NOT NULL,
26+
"filesDisabledExtensions" text[],
27+
"filesMaxFileSize" text DEFAULT '100mb' NOT NULL,
28+
"filesDefaultExpiration" text,
29+
"filesAssumeMimetypes" boolean DEFAULT false NOT NULL,
30+
"filesDefaultDateFormat" text DEFAULT 'YYYY-MM-DD_HH:mm:ss' NOT NULL,
31+
"filesRemoveGpsMetadata" boolean DEFAULT false NOT NULL,
32+
"urlsRoute" text DEFAULT '/go' NOT NULL,
33+
"urlsLength" integer DEFAULT 6 NOT NULL,
34+
"featuresImageCompression" boolean DEFAULT true NOT NULL,
35+
"featuresRobotsTxt" boolean DEFAULT true NOT NULL,
36+
"featuresHealthcheck" boolean DEFAULT true NOT NULL,
37+
"featuresUserRegistration" boolean DEFAULT false NOT NULL,
38+
"featuresOauthRegistration" boolean DEFAULT false NOT NULL,
39+
"featuresDeleteOnMaxViews" boolean DEFAULT true NOT NULL,
40+
"featuresThumbnailsEnabled" boolean DEFAULT true NOT NULL,
41+
"featuresThumbnailsNumberThreads" integer DEFAULT 4 NOT NULL,
42+
"featuresMetricsEnabled" boolean DEFAULT true NOT NULL,
43+
"featuresMetricsAdminOnly" boolean DEFAULT false NOT NULL,
44+
"featuresMetricsShowUserSpecific" boolean DEFAULT true NOT NULL,
45+
"invitesEnabled" boolean DEFAULT true NOT NULL,
46+
"invitesLength" integer DEFAULT 6 NOT NULL,
47+
"websiteTitle" text DEFAULT 'Zipline' NOT NULL,
48+
"websiteTitleLogo" text,
49+
"websiteExternalLinks" jsonb DEFAULT '[{"url":"https://github.com/diced/zipline","name":"GitHub"},{"url":"https://zipline.diced.sh/","name":"Documentation"}]'::jsonb NOT NULL,
50+
"websiteLoginBackground" text,
51+
"websiteDefaultAvatar" text,
52+
"websiteTos" text,
53+
"websiteThemeDefault" text DEFAULT 'system' NOT NULL,
54+
"websiteThemeDark" text DEFAULT 'builtin:dark_gray' NOT NULL,
55+
"websiteThemeLight" text DEFAULT 'builtin:light_gray' NOT NULL,
56+
"oauthBypassLocalLogin" boolean DEFAULT false NOT NULL,
57+
"oauthLoginOnly" boolean DEFAULT false NOT NULL,
58+
"oauthDiscordClientId" text,
59+
"oauthDiscordClientSecret" text,
60+
"oauthDiscordRedirectUri" text,
61+
"oauthGoogleClientId" text,
62+
"oauthGoogleClientSecret" text,
63+
"oauthGoogleRedirectUri" text,
64+
"oauthGithubClientId" text,
65+
"oauthGithubClientSecret" text,
66+
"oauthGithubRedirectUri" text,
67+
"oauthOidcClientId" text,
68+
"oauthOidcClientSecret" text,
69+
"oauthOidcAuthorizeUrl" text,
70+
"oauthOidcTokenUrl" text,
71+
"oauthOidcUserinfoUrl" text,
72+
"oauthOidcRedirectUri" text,
73+
"mfaTotpEnabled" boolean DEFAULT false NOT NULL,
74+
"mfaTotpIssuer" text DEFAULT 'Zipline' NOT NULL,
75+
"mfaPasskeys" boolean DEFAULT false NOT NULL,
76+
"ratelimitEnabled" boolean DEFAULT true NOT NULL,
77+
"ratelimitMax" integer DEFAULT 10 NOT NULL,
78+
"ratelimitWindow" integer,
79+
"ratelimitAdminBypass" boolean DEFAULT true NOT NULL,
80+
"ratelimitAllowList" text[],
81+
"httpWebhookOnUpload" text,
82+
"httpWebhookOnShorten" text,
83+
"discordWebhookUrl" text,
84+
"discordUsername" text,
85+
"discordAvatarUrl" text,
86+
"discordOnUploadWebhookUrl" text,
87+
"discordOnUploadUsername" text,
88+
"discordOnUploadAvatarUrl" text,
89+
"discordOnUploadContent" text,
90+
"discordOnUploadEmbed" jsonb,
91+
"discordOnShortenWebhookUrl" text,
92+
"discordOnShortenUsername" text,
93+
"discordOnShortenAvatarUrl" text,
94+
"discordOnShortenContent" text,
95+
"discordOnShortenEmbed" jsonb,
96+
"pwaEnabled" boolean DEFAULT false NOT NULL,
97+
"pwaTitle" text DEFAULT 'Zipline' NOT NULL,
98+
"pwaShortName" text DEFAULT 'Zipline' NOT NULL,
99+
"pwaDescription" text DEFAULT 'Zipline' NOT NULL,
100+
"pwaThemeColor" text DEFAULT '#000000' NOT NULL,
101+
"pwaBackgroundColor" text DEFAULT '#000000' NOT NULL,
102+
"websiteLoginBackgroundBlur" boolean DEFAULT true NOT NULL,
103+
"filesRandomWordsNumAdjectives" integer DEFAULT 2 NOT NULL,
104+
"filesRandomWordsSeparator" text DEFAULT '-' NOT NULL,
105+
"featuresVersionAPI" text DEFAULT 'https://zipline-version.diced.sh' NOT NULL,
106+
"featuresVersionChecking" boolean DEFAULT true NOT NULL,
107+
"oauthDiscordAllowedIds" text[] DEFAULT '{"RAY"}',
108+
"oauthDiscordDeniedIds" text[] DEFAULT '{"RAY"}',
109+
"domains" text[] DEFAULT '{"RAY"}',
110+
"filesDefaultCompressionFormat" text DEFAULT 'jpg',
111+
"featuresThumbnailsFormat" text DEFAULT 'jpg' NOT NULL
112+
);
113+
--> statement-breakpoint
114+
CREATE TABLE "Metric" (
115+
"id" text PRIMARY KEY NOT NULL,
116+
"createdAt" timestamp(3) DEFAULT CURRENT_TIMESTAMP NOT NULL,
117+
"updatedAt" timestamp(3) NOT NULL,
118+
"data" jsonb NOT NULL
119+
);
120+
--> statement-breakpoint
121+
CREATE TABLE "Url" (
122+
"id" text PRIMARY KEY NOT NULL,
123+
"createdAt" timestamp(3) DEFAULT CURRENT_TIMESTAMP NOT NULL,
124+
"updatedAt" timestamp(3) NOT NULL,
125+
"code" text NOT NULL,
126+
"vanity" text,
127+
"destination" text NOT NULL,
128+
"views" integer DEFAULT 0 NOT NULL,
129+
"maxViews" integer,
130+
"password" text,
131+
"userId" text,
132+
"enabled" boolean DEFAULT true NOT NULL
133+
);
134+
--> statement-breakpoint
135+
CREATE TABLE "Folder" (
136+
"id" text PRIMARY KEY NOT NULL,
137+
"createdAt" timestamp(3) DEFAULT CURRENT_TIMESTAMP NOT NULL,
138+
"updatedAt" timestamp(3) NOT NULL,
139+
"name" text NOT NULL,
140+
"public" boolean DEFAULT false NOT NULL,
141+
"userId" text NOT NULL,
142+
"allowUploads" boolean DEFAULT false NOT NULL
143+
);
144+
--> statement-breakpoint
145+
CREATE TABLE "User" (
146+
"id" text PRIMARY KEY NOT NULL,
147+
"createdAt" timestamp(3) DEFAULT CURRENT_TIMESTAMP NOT NULL,
148+
"updatedAt" timestamp(3) NOT NULL,
149+
"username" text NOT NULL,
150+
"password" text,
151+
"avatar" text,
152+
"token" text NOT NULL,
153+
"role" "Role" DEFAULT 'USER' NOT NULL,
154+
"view" jsonb DEFAULT '{}'::jsonb NOT NULL,
155+
"totpSecret" text,
156+
"sessions" text[]
157+
);
158+
--> statement-breakpoint
159+
CREATE TABLE "Export" (
160+
"id" text PRIMARY KEY NOT NULL,
161+
"createdAt" timestamp(3) DEFAULT CURRENT_TIMESTAMP NOT NULL,
162+
"updatedAt" timestamp(3) NOT NULL,
163+
"completed" boolean DEFAULT false NOT NULL,
164+
"path" text NOT NULL,
165+
"files" integer NOT NULL,
166+
"size" text NOT NULL,
167+
"userId" text NOT NULL
168+
);
169+
--> statement-breakpoint
170+
CREATE TABLE "UserQuota" (
171+
"id" text PRIMARY KEY NOT NULL,
172+
"createdAt" timestamp(3) DEFAULT CURRENT_TIMESTAMP NOT NULL,
173+
"updatedAt" timestamp(3) NOT NULL,
174+
"filesQuota" "UserFilesQuota" NOT NULL,
175+
"maxBytes" text,
176+
"maxFiles" integer,
177+
"maxUrls" integer,
178+
"userId" text
179+
);
180+
--> statement-breakpoint
181+
CREATE TABLE "UserPasskey" (
182+
"id" text PRIMARY KEY NOT NULL,
183+
"createdAt" timestamp(3) DEFAULT CURRENT_TIMESTAMP NOT NULL,
184+
"updatedAt" timestamp(3) NOT NULL,
185+
"lastUsed" timestamp(3),
186+
"name" text NOT NULL,
187+
"reg" jsonb NOT NULL,
188+
"userId" text NOT NULL
189+
);
190+
--> statement-breakpoint
191+
CREATE TABLE "OAuthProvider" (
192+
"id" text PRIMARY KEY NOT NULL,
193+
"createdAt" timestamp(3) DEFAULT CURRENT_TIMESTAMP NOT NULL,
194+
"updatedAt" timestamp(3) NOT NULL,
195+
"userId" text NOT NULL,
196+
"provider" "OAuthProviderType" NOT NULL,
197+
"username" text NOT NULL,
198+
"accessToken" text NOT NULL,
199+
"refreshToken" text,
200+
"oauthId" text
201+
);
202+
--> statement-breakpoint
203+
CREATE TABLE "File" (
204+
"id" text PRIMARY KEY NOT NULL,
205+
"createdAt" timestamp(3) DEFAULT CURRENT_TIMESTAMP NOT NULL,
206+
"updatedAt" timestamp(3) NOT NULL,
207+
"deletesAt" timestamp(3),
208+
"name" text NOT NULL,
209+
"originalName" text,
210+
"size" bigint NOT NULL,
211+
"type" text NOT NULL,
212+
"views" integer DEFAULT 0 NOT NULL,
213+
"maxViews" integer,
214+
"favorite" boolean DEFAULT false NOT NULL,
215+
"password" text,
216+
"userId" text,
217+
"folderId" text
218+
);
219+
--> statement-breakpoint
220+
CREATE TABLE "Thumbnail" (
221+
"id" text PRIMARY KEY NOT NULL,
222+
"createdAt" timestamp(3) DEFAULT CURRENT_TIMESTAMP NOT NULL,
223+
"updatedAt" timestamp(3) NOT NULL,
224+
"path" text NOT NULL,
225+
"fileId" text NOT NULL
226+
);
227+
--> statement-breakpoint
228+
CREATE TABLE "IncompleteFile" (
229+
"id" text PRIMARY KEY NOT NULL,
230+
"createdAt" timestamp(3) DEFAULT CURRENT_TIMESTAMP NOT NULL,
231+
"updatedAt" timestamp(3) NOT NULL,
232+
"status" "IncompleteFileStatus" NOT NULL,
233+
"chunksTotal" integer NOT NULL,
234+
"chunksComplete" integer NOT NULL,
235+
"metadata" jsonb NOT NULL,
236+
"userId" text NOT NULL
237+
);
238+
--> statement-breakpoint
239+
CREATE TABLE "Tag" (
240+
"id" text PRIMARY KEY NOT NULL,
241+
"createdAt" timestamp(3) DEFAULT CURRENT_TIMESTAMP NOT NULL,
242+
"updatedAt" timestamp(3) NOT NULL,
243+
"name" text NOT NULL,
244+
"color" text NOT NULL,
245+
"userId" text
246+
);
247+
--> statement-breakpoint
248+
CREATE TABLE "Invite" (
249+
"id" text PRIMARY KEY NOT NULL,
250+
"createdAt" timestamp(3) DEFAULT CURRENT_TIMESTAMP NOT NULL,
251+
"updatedAt" timestamp(3) NOT NULL,
252+
"expiresAt" timestamp(3),
253+
"code" text NOT NULL,
254+
"uses" integer DEFAULT 0 NOT NULL,
255+
"maxUses" integer,
256+
"inviterId" text NOT NULL
257+
);
258+
--> statement-breakpoint
259+
CREATE TABLE "_FileToTag" (
260+
"A" text NOT NULL,
261+
"B" text NOT NULL,
262+
CONSTRAINT "_FileToTag_AB_pkey" PRIMARY KEY("A","B")
263+
);
264+
--> statement-breakpoint
265+
ALTER TABLE "Url" ADD CONSTRAINT "Url_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE set null ON UPDATE cascade;--> statement-breakpoint
266+
ALTER TABLE "Folder" ADD CONSTRAINT "Folder_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
267+
ALTER TABLE "Export" ADD CONSTRAINT "Export_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
268+
ALTER TABLE "UserQuota" ADD CONSTRAINT "UserQuota_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
269+
ALTER TABLE "UserPasskey" ADD CONSTRAINT "UserPasskey_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
270+
ALTER TABLE "OAuthProvider" ADD CONSTRAINT "OAuthProvider_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE restrict ON UPDATE cascade;--> statement-breakpoint
271+
ALTER TABLE "File" ADD CONSTRAINT "File_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE set null ON UPDATE cascade;--> statement-breakpoint
272+
ALTER TABLE "File" ADD CONSTRAINT "File_folderId_fkey" FOREIGN KEY ("folderId") REFERENCES "public"."Folder"("id") ON DELETE set null ON UPDATE cascade;--> statement-breakpoint
273+
ALTER TABLE "Thumbnail" ADD CONSTRAINT "Thumbnail_fileId_fkey" FOREIGN KEY ("fileId") REFERENCES "public"."File"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
274+
ALTER TABLE "IncompleteFile" ADD CONSTRAINT "IncompleteFile_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
275+
ALTER TABLE "Tag" ADD CONSTRAINT "Tag_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE set null ON UPDATE cascade;--> statement-breakpoint
276+
ALTER TABLE "Invite" ADD CONSTRAINT "Invite_inviterId_fkey" FOREIGN KEY ("inviterId") REFERENCES "public"."User"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
277+
ALTER TABLE "_FileToTag" ADD CONSTRAINT "_FileToTag_A_fkey" FOREIGN KEY ("A") REFERENCES "public"."File"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
278+
ALTER TABLE "_FileToTag" ADD CONSTRAINT "_FileToTag_B_fkey" FOREIGN KEY ("B") REFERENCES "public"."Tag"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
279+
CREATE UNIQUE INDEX "Url_code_vanity_key" ON "Url" USING btree ("code" text_ops,"vanity" text_ops);--> statement-breakpoint
280+
CREATE UNIQUE INDEX "User_token_key" ON "User" USING btree ("token" text_ops);--> statement-breakpoint
281+
CREATE UNIQUE INDEX "User_username_key" ON "User" USING btree ("username" text_ops);--> statement-breakpoint
282+
CREATE UNIQUE INDEX "UserQuota_userId_key" ON "UserQuota" USING btree ("userId" text_ops);--> statement-breakpoint
283+
CREATE UNIQUE INDEX "OAuthProvider_provider_oauthId_key" ON "OAuthProvider" USING btree ("provider" text_ops,"oauthId" text_ops);--> statement-breakpoint
284+
CREATE UNIQUE INDEX "Thumbnail_fileId_key" ON "Thumbnail" USING btree ("fileId" text_ops);--> statement-breakpoint
285+
CREATE UNIQUE INDEX "Tag_name_key" ON "Tag" USING btree ("name" text_ops);--> statement-breakpoint
286+
CREATE UNIQUE INDEX "Invite_code_key" ON "Invite" USING btree ("code" text_ops);--> statement-breakpoint
287+
CREATE INDEX "_FileToTag_B_index" ON "_FileToTag" USING btree ("B" text_ops);

0 commit comments

Comments
 (0)