@@ -4,17 +4,17 @@ CREATE EXTENSION IF NOT EXISTS "citext";
4
4
5
5
CREATE TABLE IF NOT EXISTS " logins" (" login_id" bigserial NOT NULL , " email" text NOT NULL UNIQUE, " password_hash" text NOT NULL , " phone_number" text , " is_enabled" boolean NOT NULL , " is_email_verified" boolean NOT NULL , " is_phone_verified" boolean NOT NULL , PRIMARY KEY (" login_id" ), UNIQUE (" email" ));
6
6
7
- CREATE TABLE IF NOT EXISTS " registrations" (" registration_id" uuid NOT NULL DEFAULT ' uuid_generate_v4()' , " login_id" bigint NOT NULL , " date_created" timestamptz NOT NULL , " date_expires" timestamptz NOT NULL , PRIMARY KEY (" registration_id" ), FOREIGN KEY (" login_id" ) REFERENCES " logins" (" login_id" ) ON DELETE CASCADE );
7
+ CREATE TABLE IF NOT EXISTS " registrations" (" registration_id" uuid NOT NULL DEFAULT uuid_generate_v4(), " login_id" bigint NOT NULL , " is_complete " boolean NOT NULL , " date_created" timestamptz NOT NULL , " date_expires" timestamptz NOT NULL , PRIMARY KEY (" registration_id" ), FOREIGN KEY (" login_id" ) REFERENCES " logins" (" login_id" ) ON DELETE CASCADE );
8
8
9
9
CREATE TABLE IF NOT EXISTS " email_verifications" (" email_verification_id" bigserial NOT NULL , " login_id" bigint NOT NULL , " email_address" text NOT NULL , " is_verified" boolean NOT NULL , " created_at" timestamptz NOT NULL DEFAULT now(), " expires_at" timestamptz NOT NULL , " verified_at" timestamptz , PRIMARY KEY (" email_verification_id" ), UNIQUE (" login_id" , " email_address" ), FOREIGN KEY (" login_id" ) REFERENCES " logins" (" login_id" ) ON DELETE CASCADE );
10
10
11
11
CREATE TABLE IF NOT EXISTS " phone_verifications" (" phone_verification_id" bigserial NOT NULL , " login_id" bigint NOT NULL , " code" text NOT NULL , " phone_number" text NOT NULL , " is_verified" boolean NOT NULL , " created_at" timestamptz NOT NULL DEFAULT now(), " expires_at" timestamptz NOT NULL , " verified_at" timestamptz , PRIMARY KEY (" phone_verification_id" ), UNIQUE (" login_id" , " code" ), UNIQUE (" login_id" , " phone_number" ), FOREIGN KEY (" login_id" ) REFERENCES " logins" (" login_id" ) ON DELETE CASCADE );
12
12
13
13
CREATE TABLE IF NOT EXISTS " accounts" (" account_id" bigserial NOT NULL , " timezone" text NOT NULL DEFAULT ' UTC' , PRIMARY KEY (" account_id" ));
14
14
15
- CREATE TABLE IF NOT EXISTS " users" (" user_id" bigserial NOT NULL , " login_id" bigint NOT NULL , " account_id" bigint NOT NULL , " stripe_customer_id" text , " first_name" text NOT NULL , " last_name" text , PRIMARY KEY (" user_id" ), FOREIGN KEY (" login_id " ) REFERENCES " logins " (" login_id " ) ON DELETE CASCADE , FOREIGN KEY (" account_id " ) REFERENCES " accounts " (" account_id " ) ON DELETE CASCADE );
15
+ CREATE TABLE IF NOT EXISTS " users" (" user_id" bigserial NOT NULL , " login_id" bigint NOT NULL , " account_id" bigint NOT NULL , " stripe_customer_id" text , " first_name" text NOT NULL , " last_name" text , PRIMARY KEY (" user_id" ), FOREIGN KEY (" account_id " ) REFERENCES " accounts " (" account_id " ) ON DELETE CASCADE , FOREIGN KEY (" login_id " ) REFERENCES " logins " (" login_id " ) ON DELETE CASCADE );
16
16
17
- CREATE TABLE IF NOT EXISTS " links" (" link_id" bigserial NOT NULL , " account_id" bigint NOT NULL , " plaid_item_id" text NOT NULL , " plaid_access_token" text NOT NULL , " plaid_products" text [] NOT NULL , " webhook_url" text , " institution_id" text NOT NULL , " institution_name" text NOT NULL , " custom_institution_name" text , " created_by_user_id" bigint NOT NULL , PRIMARY KEY (" link_id" , " account_id" ), FOREIGN KEY (" created_by_user_id " ) REFERENCES " users " (" user_id " ) ON DELETE CASCADE , FOREIGN KEY (" account_id " ) REFERENCES " accounts " (" account_id " ) ON DELETE CASCADE );
17
+ CREATE TABLE IF NOT EXISTS " links" (" link_id" bigserial NOT NULL , " account_id" bigint NOT NULL , " plaid_item_id" text NOT NULL , " plaid_access_token" text NOT NULL , " plaid_products" text [] NOT NULL , " webhook_url" text , " institution_id" text NOT NULL , " institution_name" text NOT NULL , " custom_institution_name" text , " created_by_user_id" bigint NOT NULL , PRIMARY KEY (" link_id" , " account_id" ), FOREIGN KEY (" account_id " ) REFERENCES " accounts " (" account_id " ) ON DELETE CASCADE , FOREIGN KEY (" created_by_user_id " ) REFERENCES " users " (" user_id " ) ON DELETE CASCADE );
18
18
19
19
CREATE TABLE IF NOT EXISTS " bank_accounts" (" bank_account_id" bigserial NOT NULL , " account_id" bigserial NOT NULL , " link_id" bigint NOT NULL , " plaid_account_id" text NOT NULL , " available_balance" bigint NOT NULL , " current_balance" bigint NOT NULL , " mask" text NOT NULL , " name" text , " original_name" text NOT NULL , " official_name" text NOT NULL , " account_type" text NOT NULL , " account_sub_type" text NOT NULL , PRIMARY KEY (" bank_account_id" , " account_id" ), FOREIGN KEY (" account_id" ) REFERENCES " accounts" (" account_id" ) ON DELETE CASCADE , FOREIGN KEY (" link_id" , " account_id" ) REFERENCES " links" (" link_id" , " account_id" ) ON DELETE CASCADE );
20
20
0 commit comments