1+ CREATE TYPE "public "." note_type" AS ENUM(' note' , ' todo' , ' label' , ' file' );-- > statement-breakpoint
2+ CREATE TYPE "public "." subscription_type" AS ENUM(' free' , ' plus' , ' pro' );-- > statement-breakpoint
3+ CREATE TABLE "notes " (
4+ " id" bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name " notes_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 CACHE 1 ),
5+ " user_id" bigint NOT NULL ,
6+ " clientside_id" varchar (36 ) NOT NULL ,
7+ " type" " note_type" DEFAULT ' note' NOT NULL ,
8+ " cipher_text" text ,
9+ " iv" varchar (16 ),
10+ " version" integer DEFAULT 1 NOT NULL ,
11+ " serverside_created_at" bigint NOT NULL ,
12+ " serverside_updated_at" bigint NOT NULL ,
13+ " clientside_created_at" bigint NOT NULL ,
14+ " clientside_updated_at" bigint NOT NULL ,
15+ " clientside_deleted_at" bigint ,
16+ " committed_size" integer DEFAULT 0 NOT NULL ,
17+ CONSTRAINT " user_client_id" UNIQUE(" user_id" ," clientside_id" )
18+ );
19+ -- > statement-breakpoint
20+ CREATE TABLE "sessions " (
21+ " id" bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name " sessions_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 CACHE 1 ),
22+ " user_id" bigint NOT NULL ,
23+ " access_token_hash" varchar (64 ) NOT NULL ,
24+ " access_token_salt" varchar (32 ) NOT NULL ,
25+ " created_at" bigint NOT NULL
26+ );
27+ -- > statement-breakpoint
28+ CREATE TABLE "users " (
29+ " id" bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name " users_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 CACHE 1 ),
30+ " email" varchar (255 ) NOT NULL ,
31+ " password_hash" varchar (255 ),
32+ " is_admin" boolean DEFAULT false NOT NULL ,
33+ " login_code" varchar (6 ),
34+ " login_code_created_at" bigint ,
35+ " login_tries_left" integer DEFAULT 0 NOT NULL ,
36+ " created_at" bigint NOT NULL ,
37+ " updated_at" bigint NOT NULL ,
38+ " sync_token" varchar (24 ),
39+ " confirm_code" varchar (6 ),
40+ " confirm_code_created_at" bigint ,
41+ " confirm_code_tries_left" integer DEFAULT 0 NOT NULL ,
42+ " new_email" varchar (255 ),
43+ " subscription" " subscription_type" DEFAULT ' free' NOT NULL ,
44+ " successful_login_at" bigint ,
45+ CONSTRAINT " users_email_unique" UNIQUE(" email" )
46+ );
47+ -- > statement-breakpoint
48+ ALTER TABLE " notes" ADD CONSTRAINT " notes_user_id_users_id_fk" FOREIGN KEY (" user_id" ) REFERENCES " public" ." users" (" id" ) ON DELETE no action ON UPDATE no action;-- > statement-breakpoint
49+ ALTER TABLE " sessions" ADD CONSTRAINT " sessions_user_id_users_id_fk" FOREIGN KEY (" user_id" ) REFERENCES " public" ." users" (" id" ) ON DELETE no action ON UPDATE no action;
0 commit comments