1+ CREATE TYPE "public "." ab_test_status" AS ENUM(' draft' , ' running' , ' paused' , ' completed' );-- > statement-breakpoint
2+ CREATE TYPE "public "." ab_variant_type" AS ENUM(' visual' , ' redirect' , ' code' );-- > statement-breakpoint
3+ CREATE TYPE "public "." api_key_type" AS ENUM(' user' , ' sdk' , ' automation' );-- > statement-breakpoint
4+ CREATE TYPE "public "." api_scope" AS ENUM(' read:data' , ' write:data' , ' read:experiments' , ' track:events' , ' admin:apikeys' );-- > statement-breakpoint
5+ CREATE TYPE "public "." FunnelGoalType" AS ENUM(' COMPLETION' , ' STEP_CONVERSION' , ' TIME_TO_CONVERT' );-- > statement-breakpoint
6+ CREATE TYPE "public "." FunnelStepType" AS ENUM(' PAGE_VIEW' , ' EVENT' , ' CUSTOM' );-- > statement-breakpoint
7+ CREATE TYPE "public "." MemberRole" AS ENUM(' owner' , ' admin' , ' member' , ' viewer' );-- > statement-breakpoint
8+ CREATE TYPE "public "." OrganizationRole" AS ENUM(' admin' , ' owner' , ' member' , ' viewer' );-- > statement-breakpoint
9+ CREATE TYPE "public "." Role" AS ENUM(' ADMIN' , ' USER' , ' EARLY_ADOPTER' , ' INVESTOR' , ' BETA_TESTER' , ' GUEST' );-- > statement-breakpoint
10+ CREATE TYPE "public "." UserStatus" AS ENUM(' ACTIVE' , ' SUSPENDED' , ' INACTIVE' );-- > statement-breakpoint
11+ CREATE TYPE "public "." VerificationStatus" AS ENUM(' PENDING' , ' VERIFIED' , ' FAILED' );-- > statement-breakpoint
12+ CREATE TYPE "public "." WebsiteStatus" AS ENUM(' ACTIVE' , ' HEALTHY' , ' UNHEALTHY' , ' INACTIVE' , ' PENDING' );-- > statement-breakpoint
13+ CREATE TABLE "ab_experiments " (
14+ " id" text PRIMARY KEY NOT NULL ,
15+ " websiteId" text NOT NULL ,
16+ " name" text NOT NULL ,
17+ " description" text ,
18+ " status" " ab_test_status" DEFAULT ' draft' NOT NULL ,
19+ " trafficAllocation" integer DEFAULT 100 NOT NULL ,
20+ " startDate" timestamp (3 ),
21+ " endDate" timestamp (3 ),
22+ " primaryGoal" text ,
23+ " createdBy" text NOT NULL ,
24+ " createdAt" timestamp (3 ) DEFAULT CURRENT_TIMESTAMP NOT NULL ,
25+ " updatedAt" timestamp (3 ) DEFAULT CURRENT_TIMESTAMP NOT NULL ,
26+ " deletedAt" timestamp (3 )
27+ );
28+ -- > statement-breakpoint
29+ CREATE TABLE "ab_goals " (
30+ " id" text PRIMARY KEY NOT NULL ,
31+ " experimentId" text NOT NULL ,
32+ " name" text NOT NULL ,
33+ " type" text NOT NULL ,
34+ " target" text NOT NULL ,
35+ " description" text ,
36+ " createdAt" timestamp (3 ) DEFAULT CURRENT_TIMESTAMP NOT NULL ,
37+ " updatedAt" timestamp (3 ) DEFAULT CURRENT_TIMESTAMP NOT NULL
38+ );
39+ -- > statement-breakpoint
40+ CREATE TABLE "ab_variants " (
41+ " id" text PRIMARY KEY NOT NULL ,
42+ " experimentId" text NOT NULL ,
43+ " name" text NOT NULL ,
44+ " type" " ab_variant_type" DEFAULT ' visual' NOT NULL ,
45+ " content" jsonb NOT NULL ,
46+ " trafficWeight" integer DEFAULT 50 NOT NULL ,
47+ " isControl" boolean DEFAULT false NOT NULL ,
48+ " createdAt" timestamp (3 ) DEFAULT CURRENT_TIMESTAMP NOT NULL ,
49+ " updatedAt" timestamp (3 ) DEFAULT CURRENT_TIMESTAMP NOT NULL
50+ );
51+ -- > statement-breakpoint
52+ CREATE TABLE "account " (
53+ " id" text PRIMARY KEY NOT NULL ,
54+ " account_id" text NOT NULL ,
55+ " provider_id" text NOT NULL ,
56+ " user_id" text NOT NULL ,
57+ " access_token" text ,
58+ " refresh_token" text ,
59+ " id_token" text ,
60+ " access_token_expires_at" timestamp ,
61+ " refresh_token_expires_at" timestamp ,
62+ " scope" text ,
63+ " password" text ,
64+ " created_at" timestamp NOT NULL ,
65+ " updated_at" timestamp NOT NULL
66+ );
67+ -- > statement-breakpoint
68+ CREATE TABLE "apikey " (
69+ " id" text PRIMARY KEY NOT NULL ,
70+ " name" text NOT NULL ,
71+ " prefix" text NOT NULL ,
72+ " start" text NOT NULL ,
73+ " key" text NOT NULL ,
74+ " user_id" text ,
75+ " organization_id" text ,
76+ " type" " api_key_type" DEFAULT ' user' NOT NULL ,
77+ " scopes" " api_scope" [] DEFAULT ' {}' NOT NULL ,
78+ " enabled" boolean DEFAULT true NOT NULL ,
79+ " rate_limit_enabled" boolean DEFAULT true NOT NULL ,
80+ " rate_limit_time_window" integer ,
81+ " rate_limit_max" integer ,
82+ " request_count" integer DEFAULT 0 NOT NULL ,
83+ " remaining" integer ,
84+ " last_request" timestamp ,
85+ " last_refill_at" timestamp ,
86+ " refill_interval" integer ,
87+ " refill_amount" integer ,
88+ " expires_at" timestamp ,
89+ " metadata" jsonb DEFAULT ' {}' ::jsonb,
90+ " created_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL ,
91+ " updated_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL
92+ );
93+ -- > statement-breakpoint
94+ CREATE TABLE "funnel_definitions " (
95+ " id" text PRIMARY KEY NOT NULL ,
96+ " websiteId" text NOT NULL ,
97+ " name" text NOT NULL ,
98+ " description" text ,
99+ " steps" jsonb NOT NULL ,
100+ " filters" jsonb,
101+ " isActive" boolean DEFAULT true NOT NULL ,
102+ " createdBy" text NOT NULL ,
103+ " createdAt" timestamp (3 ) DEFAULT CURRENT_TIMESTAMP NOT NULL ,
104+ " updatedAt" timestamp (3 ) DEFAULT CURRENT_TIMESTAMP NOT NULL ,
105+ " deletedAt" timestamp (3 )
106+ );
107+ -- > statement-breakpoint
108+ CREATE TABLE "funnel_goals " (
109+ " id" text PRIMARY KEY NOT NULL ,
110+ " funnelId" text NOT NULL ,
111+ " goalType" " FunnelGoalType" NOT NULL ,
112+ " targetValue" text ,
113+ " description" text ,
114+ " isActive" boolean DEFAULT true NOT NULL ,
115+ " createdAt" timestamp (3 ) DEFAULT CURRENT_TIMESTAMP NOT NULL ,
116+ " updatedAt" timestamp (3 ) DEFAULT CURRENT_TIMESTAMP NOT NULL
117+ );
118+ -- > statement-breakpoint
119+ CREATE TABLE "goals " (
120+ " id" text PRIMARY KEY NOT NULL ,
121+ " websiteId" text NOT NULL ,
122+ " type" text NOT NULL ,
123+ " target" text NOT NULL ,
124+ " name" text NOT NULL ,
125+ " description" text ,
126+ " filters" jsonb,
127+ " isActive" boolean DEFAULT true NOT NULL ,
128+ " createdBy" text NOT NULL ,
129+ " createdAt" timestamp (3 ) DEFAULT CURRENT_TIMESTAMP NOT NULL ,
130+ " updatedAt" timestamp (3 ) DEFAULT CURRENT_TIMESTAMP NOT NULL ,
131+ " deletedAt" timestamp (3 )
132+ );
133+ -- > statement-breakpoint
134+ CREATE TABLE "invitation " (
135+ " id" text PRIMARY KEY NOT NULL ,
136+ " organization_id" text NOT NULL ,
137+ " email" text NOT NULL ,
138+ " role" text DEFAULT ' member' ,
139+ " team_id" text ,
140+ " status" text DEFAULT ' pending' NOT NULL ,
141+ " expires_at" timestamp NOT NULL ,
142+ " inviter_id" text NOT NULL
143+ );
144+ -- > statement-breakpoint
145+ CREATE TABLE "member " (
146+ " id" text PRIMARY KEY NOT NULL ,
147+ " organization_id" text NOT NULL ,
148+ " user_id" text NOT NULL ,
149+ " role" text DEFAULT ' member' NOT NULL ,
150+ " team_id" text ,
151+ " created_at" timestamp NOT NULL
152+ );
153+ -- > statement-breakpoint
154+ CREATE TABLE "organization " (
155+ " id" text PRIMARY KEY NOT NULL ,
156+ " name" text NOT NULL ,
157+ " slug" text ,
158+ " logo" text ,
159+ " created_at" timestamp NOT NULL ,
160+ " metadata" text ,
161+ CONSTRAINT " organization_slug_unique" UNIQUE(" slug" )
162+ );
163+ -- > statement-breakpoint
164+ CREATE TABLE "session " (
165+ " id" text PRIMARY KEY NOT NULL ,
166+ " expiresAt" timestamp (3 ) NOT NULL ,
167+ " token" text NOT NULL ,
168+ " createdAt" timestamp (3 ) DEFAULT CURRENT_TIMESTAMP NOT NULL ,
169+ " updatedAt" timestamp (3 ) NOT NULL ,
170+ " ipAddress" text ,
171+ " userAgent" text ,
172+ " userId" text ,
173+ " active_organization_id" text
174+ );
175+ -- > statement-breakpoint
176+ CREATE TABLE "team " (
177+ " id" text PRIMARY KEY NOT NULL ,
178+ " name" text NOT NULL ,
179+ " organization_id" text NOT NULL ,
180+ " created_at" timestamp NOT NULL ,
181+ " updated_at" timestamp
182+ );
183+ -- > statement-breakpoint
184+ CREATE TABLE "two_factor " (
185+ " id" text PRIMARY KEY NOT NULL ,
186+ " secret" text NOT NULL ,
187+ " backup_codes" text NOT NULL ,
188+ " user_id" text NOT NULL
189+ );
190+ -- > statement-breakpoint
191+ CREATE TABLE "user " (
192+ " id" text PRIMARY KEY NOT NULL ,
193+ " name" text NOT NULL ,
194+ " email" text NOT NULL ,
195+ " email_verified" boolean NOT NULL ,
196+ " image" text ,
197+ " firstName" text ,
198+ " lastName" text ,
199+ " status" " UserStatus" DEFAULT ' ACTIVE' NOT NULL ,
200+ " created_at" timestamp NOT NULL ,
201+ " updated_at" timestamp NOT NULL ,
202+ " deletedAt" timestamp (3 ),
203+ " role" " Role" DEFAULT ' USER' NOT NULL ,
204+ " two_factor_enabled" boolean ,
205+ CONSTRAINT " user_email_unique" UNIQUE(" email" )
206+ );
207+ -- > statement-breakpoint
208+ CREATE TABLE "user_preferences " (
209+ " id" text PRIMARY KEY NOT NULL ,
210+ " userId" text NOT NULL ,
211+ " timezone" text DEFAULT ' auto' NOT NULL ,
212+ " dateFormat" text DEFAULT ' MMM D, YYYY' NOT NULL ,
213+ " timeFormat" text DEFAULT ' h:mm a' NOT NULL ,
214+ " createdAt" timestamp (3 ) DEFAULT CURRENT_TIMESTAMP NOT NULL ,
215+ " updatedAt" timestamp (3 ) NOT NULL
216+ );
217+ -- > statement-breakpoint
218+ CREATE TABLE "user_stripe_config " (
219+ " id" text PRIMARY KEY NOT NULL ,
220+ " user_id" text NOT NULL ,
221+ " webhook_token" text NOT NULL ,
222+ " stripe_secret_key" text NOT NULL ,
223+ " stripe_publishable_key" text ,
224+ " webhook_secret" text NOT NULL ,
225+ " is_live_mode" boolean DEFAULT false NOT NULL ,
226+ " is_active" boolean DEFAULT true NOT NULL ,
227+ " last_webhook_at" timestamp ,
228+ " webhook_failure_count" integer DEFAULT 0 NOT NULL ,
229+ " created_at" timestamp NOT NULL ,
230+ " updated_at" timestamp NOT NULL
231+ );
232+ -- > statement-breakpoint
233+ CREATE TABLE "verification " (
234+ " id" text PRIMARY KEY NOT NULL ,
235+ " identifier" text NOT NULL ,
236+ " value" text NOT NULL ,
237+ " expires_at" timestamp NOT NULL ,
238+ " created_at" timestamp ,
239+ " updated_at" timestamp
240+ );
241+ -- > statement-breakpoint
242+ CREATE TABLE "websites " (
243+ " id" text PRIMARY KEY NOT NULL ,
244+ " domain" text NOT NULL ,
245+ " name" text ,
246+ " status" " WebsiteStatus" DEFAULT ' ACTIVE' NOT NULL ,
247+ " userId" text ,
248+ " isPublic" boolean DEFAULT false NOT NULL ,
249+ " createdAt" timestamp (3 ) DEFAULT CURRENT_TIMESTAMP NOT NULL ,
250+ " updatedAt" timestamp (3 ) DEFAULT CURRENT_TIMESTAMP NOT NULL ,
251+ " deletedAt" timestamp (3 ),
252+ " organization_id" text
253+ );
254+ -- > statement-breakpoint
255+ ALTER TABLE " ab_experiments" ADD CONSTRAINT " ab_experiments_websiteId_fkey" FOREIGN KEY (" websiteId" ) REFERENCES " public" ." websites" (" id" ) ON DELETE cascade ON UPDATE cascade;-- > statement-breakpoint
256+ ALTER TABLE " ab_experiments" ADD CONSTRAINT " ab_experiments_createdBy_fkey" FOREIGN KEY (" createdBy" ) REFERENCES " public" ." user" (" id" ) ON DELETE restrict ON UPDATE cascade;-- > statement-breakpoint
257+ ALTER TABLE " ab_goals" ADD CONSTRAINT " ab_goals_experimentId_fkey" FOREIGN KEY (" experimentId" ) REFERENCES " public" ." ab_experiments" (" id" ) ON DELETE cascade ON UPDATE cascade;-- > statement-breakpoint
258+ ALTER TABLE " ab_variants" ADD CONSTRAINT " ab_variants_experimentId_fkey" FOREIGN KEY (" experimentId" ) REFERENCES " public" ." ab_experiments" (" id" ) ON DELETE cascade ON UPDATE cascade;-- > statement-breakpoint
259+ ALTER TABLE " account" ADD CONSTRAINT " account_user_id_user_id_fk" FOREIGN KEY (" user_id" ) REFERENCES " public" ." user" (" id" ) ON DELETE cascade ON UPDATE no action;-- > statement-breakpoint
260+ ALTER TABLE " apikey" ADD CONSTRAINT " apikey_user_id_user_id_fk" FOREIGN KEY (" user_id" ) REFERENCES " public" ." user" (" id" ) ON DELETE cascade ON UPDATE no action;-- > statement-breakpoint
261+ ALTER TABLE " apikey" ADD CONSTRAINT " apikey_organization_id_organization_id_fk" FOREIGN KEY (" organization_id" ) REFERENCES " public" ." organization" (" id" ) ON DELETE cascade ON UPDATE no action;-- > statement-breakpoint
262+ ALTER TABLE " funnel_definitions" ADD CONSTRAINT " funnel_definitions_websiteId_fkey" FOREIGN KEY (" websiteId" ) REFERENCES " public" ." websites" (" id" ) ON DELETE cascade ON UPDATE cascade;-- > statement-breakpoint
263+ ALTER TABLE " funnel_definitions" ADD CONSTRAINT " funnel_definitions_createdBy_fkey" FOREIGN KEY (" createdBy" ) REFERENCES " public" ." user" (" id" ) ON DELETE restrict ON UPDATE cascade;-- > statement-breakpoint
264+ ALTER TABLE " funnel_goals" ADD CONSTRAINT " funnel_goals_funnelId_fkey" FOREIGN KEY (" funnelId" ) REFERENCES " public" ." funnel_definitions" (" id" ) ON DELETE cascade ON UPDATE cascade;-- > statement-breakpoint
265+ ALTER TABLE " goals" ADD CONSTRAINT " goals_websiteId_fkey" FOREIGN KEY (" websiteId" ) REFERENCES " public" ." websites" (" id" ) ON DELETE cascade ON UPDATE cascade;-- > statement-breakpoint
266+ ALTER TABLE " goals" ADD CONSTRAINT " goals_createdBy_fkey" FOREIGN KEY (" createdBy" ) REFERENCES " public" ." user" (" id" ) ON DELETE restrict ON UPDATE cascade;-- > statement-breakpoint
267+ ALTER TABLE " invitation" ADD CONSTRAINT " invitation_organization_id_organization_id_fk" FOREIGN KEY (" organization_id" ) REFERENCES " public" ." organization" (" id" ) ON DELETE cascade ON UPDATE no action;-- > statement-breakpoint
268+ ALTER TABLE " invitation" ADD CONSTRAINT " invitation_inviter_id_user_id_fk" FOREIGN KEY (" inviter_id" ) REFERENCES " public" ." user" (" id" ) ON DELETE cascade ON UPDATE no action;-- > statement-breakpoint
269+ ALTER TABLE " member" ADD CONSTRAINT " member_organization_id_organization_id_fk" FOREIGN KEY (" organization_id" ) REFERENCES " public" ." organization" (" id" ) ON DELETE cascade ON UPDATE no action;-- > statement-breakpoint
270+ ALTER TABLE " member" ADD CONSTRAINT " member_user_id_user_id_fk" FOREIGN KEY (" user_id" ) REFERENCES " public" ." user" (" id" ) ON DELETE cascade ON UPDATE no action;-- > statement-breakpoint
271+ ALTER TABLE " session" ADD CONSTRAINT " session_userId_fkey" FOREIGN KEY (" userId" ) REFERENCES " public" ." user" (" id" ) ON DELETE cascade ON UPDATE cascade;-- > statement-breakpoint
272+ ALTER TABLE " team" ADD CONSTRAINT " team_organization_id_organization_id_fk" FOREIGN KEY (" organization_id" ) REFERENCES " public" ." organization" (" id" ) ON DELETE cascade ON UPDATE no action;-- > statement-breakpoint
273+ ALTER TABLE " two_factor" ADD CONSTRAINT " two_factor_user_id_user_id_fk" FOREIGN KEY (" user_id" ) REFERENCES " public" ." user" (" id" ) ON DELETE cascade ON UPDATE no action;-- > statement-breakpoint
274+ ALTER TABLE " user_preferences" ADD CONSTRAINT " user_preferences_userId_fkey" FOREIGN KEY (" userId" ) REFERENCES " public" ." user" (" id" ) ON DELETE cascade ON UPDATE cascade;-- > statement-breakpoint
275+ ALTER TABLE " user_stripe_config" ADD CONSTRAINT " user_stripe_config_userId_fkey" FOREIGN KEY (" user_id" ) REFERENCES " public" ." user" (" id" ) ON DELETE cascade ON UPDATE cascade;-- > statement-breakpoint
276+ ALTER TABLE " websites" ADD CONSTRAINT " websites_userId_fkey" FOREIGN KEY (" userId" ) REFERENCES " public" ." user" (" id" ) ON DELETE set null ON UPDATE cascade;-- > statement-breakpoint
277+ ALTER TABLE " websites" ADD CONSTRAINT " websites_organization_id_organization_id_fk" FOREIGN KEY (" organization_id" ) REFERENCES " public" ." organization" (" id" ) ON DELETE cascade ON UPDATE no action;-- > statement-breakpoint
278+ ALTER TABLE " websites" ADD CONSTRAINT " websites_organizationId_fkey" FOREIGN KEY (" organization_id" ) REFERENCES " public" ." organization" (" id" ) ON DELETE cascade ON UPDATE cascade;-- > statement-breakpoint
279+ CREATE INDEX "ab_experiments_websiteId_idx " ON " ab_experiments" USING btree (" websiteId" );-- > statement-breakpoint
280+ CREATE INDEX "ab_experiments_createdBy_idx " ON " ab_experiments" USING btree (" createdBy" );-- > statement-breakpoint
281+ CREATE INDEX "ab_experiments_status_idx " ON " ab_experiments" USING btree (" status" );-- > statement-breakpoint
282+ CREATE INDEX "ab_goals_experimentId_idx " ON " ab_goals" USING btree (" experimentId" );-- > statement-breakpoint
283+ CREATE INDEX "ab_variants_experimentId_idx " ON " ab_variants" USING btree (" experimentId" );-- > statement-breakpoint
284+ CREATE INDEX "apikey_user_id_idx " ON " apikey" USING btree (" user_id" text_ops);-- > statement-breakpoint
285+ CREATE INDEX "apikey_organization_id_idx " ON " apikey" USING btree (" organization_id" text_ops);-- > statement-breakpoint
286+ CREATE INDEX "apikey_prefix_idx " ON " apikey" USING btree (" prefix" text_ops);-- > statement-breakpoint
287+ CREATE INDEX "apikey_enabled_idx " ON " apikey" USING btree (" enabled" );-- > statement-breakpoint
288+ CREATE INDEX "funnel_definitions_createdBy_idx " ON " funnel_definitions" USING btree (" createdBy" text_ops);-- > statement-breakpoint
289+ CREATE INDEX "funnel_definitions_websiteId_idx " ON " funnel_definitions" USING btree (" websiteId" text_ops);-- > statement-breakpoint
290+ CREATE INDEX "funnel_goals_funnelId_idx " ON " funnel_goals" USING btree (" funnelId" text_ops);-- > statement-breakpoint
291+ CREATE INDEX "goals_websiteId_idx " ON " goals" USING btree (" websiteId" text_ops);-- > statement-breakpoint
292+ CREATE INDEX "goals_createdBy_idx " ON " goals" USING btree (" createdBy" text_ops);-- > statement-breakpoint
293+ CREATE UNIQUE INDEX "session_token_key " ON " session" USING btree (" token" text_ops);-- > statement-breakpoint
294+ CREATE INDEX "session_userId_idx " ON " session" USING btree (" userId" text_ops);-- > statement-breakpoint
295+ CREATE UNIQUE INDEX "user_preferences_userId_key " ON " user_preferences" USING btree (" userId" text_ops);-- > statement-breakpoint
296+ CREATE UNIQUE INDEX "user_stripe_config_userId_key " ON " user_stripe_config" USING btree (" user_id" text_ops);-- > statement-breakpoint
297+ CREATE UNIQUE INDEX "user_stripe_config_webhookToken_key " ON " user_stripe_config" USING btree (" webhook_token" text_ops);-- > statement-breakpoint
298+ CREATE UNIQUE INDEX "websites_user_domain_unique " ON " websites" USING btree (" userId" ," domain" ) WHERE " websites" ." organization_id" is null ;-- > statement-breakpoint
299+ CREATE UNIQUE INDEX "websites_org_domain_unique " ON " websites" USING btree (" organization_id" ," domain" ) WHERE " websites" ." organization_id" is not null ;-- > statement-breakpoint
300+ CREATE INDEX "websites_userId_idx " ON " websites" USING btree (" userId" text_ops);
0 commit comments