small fix
This commit is contained in:
parent
2163053d97
commit
c65ab77386
|
|
@ -75,11 +75,16 @@ DROP TYPE IF EXISTS ua_registaration_type;
|
||||||
|
|
||||||
-- Drop FortuneBet
|
-- Drop FortuneBet
|
||||||
DROP TABLE IF EXISTS tickets;
|
DROP TABLE IF EXISTS tickets;
|
||||||
|
DROP TABLE IF EXISTS ticket_outcomes;
|
||||||
DROP TABLE IF EXISTS bets;
|
DROP TABLE IF EXISTS bets;
|
||||||
|
DROP TABLE IF EXISTS bet_outcomes;
|
||||||
DROP TABLE IF EXISTS wallets;
|
DROP TABLE IF EXISTS wallets;
|
||||||
|
DROP TABLE IF EXISTS customer_wallets;
|
||||||
DROP TABLE IF EXISTS wallet_transfer;
|
DROP TABLE IF EXISTS wallet_transfer;
|
||||||
DROP TABLE IF EXISTS transactions;
|
DROP TABLE IF EXISTS transactions;
|
||||||
DROP TABLE IF EXISTS customer_wallets;
|
|
||||||
DROP TABLE IF EXISTS branches;
|
DROP TABLE IF EXISTS branches;
|
||||||
|
DROP TABLE IF EXISTS supported_operations;
|
||||||
|
DROP TABLE IF EXISTS refresh_tokens;
|
||||||
|
DROP TABLE IF EXISTS otps;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,31 +2,34 @@ CREATE TABLE IF NOT EXISTS users (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGSERIAL PRIMARY KEY,
|
||||||
first_name VARCHAR(255) NOT NULL,
|
first_name VARCHAR(255) NOT NULL,
|
||||||
last_name VARCHAR(255) NOT NULL,
|
last_name VARCHAR(255) NOT NULL,
|
||||||
email VARCHAR(255) UNIQUE ,
|
email VARCHAR(255) UNIQUE,
|
||||||
phone_number VARCHAR(20) UNIQUE,
|
phone_number VARCHAR(20) UNIQUE,
|
||||||
role VARCHAR(50) NOT NULL,
|
role VARCHAR(50) NOT NULL,
|
||||||
password BYTEA NOT NULL,
|
password BYTEA NOT NULL,
|
||||||
email_verified BOOLEAN NOT NULL DEFAULT FALSE,
|
email_verified BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
phone_verified BOOLEAN NOT NULL DEFAULT FALSE,
|
phone_verified BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
updated_at TIMESTAMPTZ ,
|
updated_at TIMESTAMPTZ,
|
||||||
--
|
--
|
||||||
suspended_at TIMESTAMPTZ NULL, -- this can be NULL if the user is not suspended
|
suspended_at TIMESTAMPTZ NULL, -- this can be NULL if the user is not suspended
|
||||||
suspended BOOLEAN NOT NULL DEFAULT FALSE,
|
suspended BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
CHECK (email IS NOT NULL OR phone_number IS NOT NULL)
|
CHECK (
|
||||||
|
email IS NOT NULL
|
||||||
|
OR phone_number IS NOT NULL
|
||||||
|
)
|
||||||
);
|
);
|
||||||
CREATE TABLE refresh_tokens (
|
CREATE TABLE refresh_tokens (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGSERIAL PRIMARY KEY,
|
||||||
user_id BIGINT NOT NULL,
|
user_id BIGINT NOT NULL,
|
||||||
token TEXT NOT NULL UNIQUE,
|
token TEXT NOT NULL UNIQUE,
|
||||||
expires_at TIMESTAMPTZ NOT NULL,
|
expires_at TIMESTAMPTZ NOT NULL,
|
||||||
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||||
revoked BOOLEAN DEFAULT FALSE NOT NULL,
|
revoked BOOLEAN DEFAULT FALSE NOT NULL,
|
||||||
CONSTRAINT unique_token UNIQUE (token)
|
CONSTRAINT unique_token UNIQUE (token)
|
||||||
);
|
);
|
||||||
-----
|
-----
|
||||||
CREATE TABLE otps (
|
CREATE TABLE otps (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGSERIAL PRIMARY KEY,
|
||||||
sent_to VARCHAR(255) NOT NULL,
|
sent_to VARCHAR(255) NOT NULL,
|
||||||
medium VARCHAR(50) NOT NULL,
|
medium VARCHAR(50) NOT NULL,
|
||||||
otp_for VARCHAR(50) NOT NULL,
|
otp_for VARCHAR(50) NOT NULL,
|
||||||
|
|
@ -36,11 +39,10 @@ CREATE TABLE refresh_tokens (
|
||||||
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
expires_at TIMESTAMPTZ NOT NULL
|
expires_at TIMESTAMPTZ NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS bets (
|
CREATE TABLE IF NOT EXISTS bets (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGSERIAL PRIMARY KEY,
|
||||||
amount BIGINT NOT NULL,
|
amount BIGINT NOT NULL,
|
||||||
total_odds REAL NOT NULL,
|
total_odds REAL NOT NULL,
|
||||||
status INT NOT NULL,
|
status INT NOT NULL,
|
||||||
full_name VARCHAR(255) NOT NULL,
|
full_name VARCHAR(255) NOT NULL,
|
||||||
phone_number VARCHAR(255) NOT NULL,
|
phone_number VARCHAR(255) NOT NULL,
|
||||||
|
|
@ -48,34 +50,39 @@ CREATE TABLE IF NOT EXISTS bets (
|
||||||
user_id BIGINT,
|
user_id BIGINT,
|
||||||
cashed_out BOOLEAN DEFAULT FALSE NOT NULL,
|
cashed_out BOOLEAN DEFAULT FALSE NOT NULL,
|
||||||
cashout_id VARCHAR(255) NOT NULL,
|
cashout_id VARCHAR(255) NOT NULL,
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
is_shop_bet BOOLEAN NOT NULL,
|
is_shop_bet BOOLEAN NOT NULL,
|
||||||
CHECK (user_id IS NOT NULL OR branch_id IS NOT NULL)
|
CHECK (
|
||||||
|
user_id IS NOT NULL
|
||||||
|
OR branch_id IS NOT NULL
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
CREATE TABLE IF NOT EXISTS tickets (
|
||||||
CREATE TABLE IF NOT EXISTS `tickets` (
|
id BIGSERIAL PRIMARY KEY,
|
||||||
id BIGSERIAL PRIMARY KEY,
|
amount BIGINT NULL,
|
||||||
amount BIGINT NULL,
|
total_odds REAL NOT NULL,
|
||||||
total_odds REAL NOT NULL,
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
);
|
);
|
||||||
|
CREATE TABLE IF NOT EXISTS bet_outcomes (
|
||||||
-- CREATE TABLE IF NOT EXISTS bet_outcomes (
|
id BIGSERIAL PRIMARY KEY,
|
||||||
-- id BIGSERIAL PRIMARY KEY,
|
bet_id BIGINT NOT NULL,
|
||||||
-- bet_id BIGINT NOT NULL,
|
event_id bigint not null,
|
||||||
-- event_id bigint not null,
|
odd_id BIGINT NOT NULL,
|
||||||
-- odd_id BIGINT NOT NULL,
|
);
|
||||||
-- );
|
CREATE TABLE IF NOT EXISTS ticket_outcomes (
|
||||||
|
id BIGSERIAL PRIMARY KEY,
|
||||||
-- CREATE TABLE IF NOT EXISTS ticket_outcomes (
|
ticket_id BIGINT NOT NULL,
|
||||||
-- id BIGSERIAL PRIMARY KEY,
|
event_id bigint not null,
|
||||||
-- ticket_id BIGINT NOT NULL,
|
odd_id BIGINT NOT NULL,
|
||||||
-- event_id bigint not null,
|
);
|
||||||
-- odd_id BIGINT NOT NULL,
|
ALTER TABLE bets
|
||||||
-- );
|
ADD CONSTRAINT fk_bets_users FOREIGN KEY (user_id) REFERENCES users(id);
|
||||||
|
ALTER TABLE bets
|
||||||
|
ADD CONSTRAINT fk_bets_branches FOREIGN KEY (branch_id) REFERENCES branches(id);
|
||||||
|
ALTER TABLE bet_outcomes
|
||||||
|
ADD CONSTRAINT fk_bet_outcomes_bet FOREIGN KEY (bet_id) REFERENCES bets(id);
|
||||||
CREATE TABLE IF NOT EXISTS wallets (
|
CREATE TABLE IF NOT EXISTS wallets (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGSERIAL PRIMARY KEY,
|
||||||
balance BIGINT NOT NULL DEFAULT 0,
|
balance BIGINT NOT NULL DEFAULT 0,
|
||||||
|
|
@ -87,8 +94,6 @@ CREATE TABLE IF NOT EXISTS wallets (
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS customer_wallets (
|
CREATE TABLE IF NOT EXISTS customer_wallets (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGSERIAL PRIMARY KEY,
|
||||||
customer_id BIGINT NOT NULL,
|
customer_id BIGINT NOT NULL,
|
||||||
|
|
@ -99,7 +104,6 @@ CREATE TABLE IF NOT EXISTS customer_wallets (
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
UNIQUE (customer_id, company_id)
|
UNIQUE (customer_id, company_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS wallet_transfer (
|
CREATE TABLE IF NOT EXISTS wallet_transfer (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGSERIAL PRIMARY KEY,
|
||||||
amount BIGINT NOT NULL,
|
amount BIGINT NOT NULL,
|
||||||
|
|
@ -112,7 +116,6 @@ CREATE TABLE IF NOT EXISTS wallet_transfer (
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS transactions (
|
CREATE TABLE IF NOT EXISTS transactions (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGSERIAL PRIMARY KEY,
|
||||||
amount BIGINT NOT NULL,
|
amount BIGINT NOT NULL,
|
||||||
|
|
@ -132,7 +135,6 @@ CREATE TABLE IF NOT EXISTS transactions (
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS branches (
|
CREATE TABLE IF NOT EXISTS branches (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGSERIAL PRIMARY KEY,
|
||||||
name VARCHAR(255) NOT NULL,
|
name VARCHAR(255) NOT NULL,
|
||||||
|
|
@ -144,20 +146,17 @@ CREATE TABLE IF NOT EXISTS branches (
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE VIEW branch_details AS
|
CREATE VIEW branch_details AS
|
||||||
SELECT branches.*,
|
SELECT branches.*,
|
||||||
CONCAT(users.first_name, ' ', users.last_name) AS manager_name,
|
CONCAT(users.first_name, ' ', users.last_name) AS manager_name,
|
||||||
users.phone_number AS manager_phone_number
|
users.phone_number AS manager_phone_number
|
||||||
FROM branches
|
FROM branches
|
||||||
LEFT JOIN users ON branches.branch_manager_id = users.id;
|
LEFT JOIN users ON branches.branch_manager_id = users.id;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS supported_operations (
|
CREATE TABLE IF NOT EXISTS supported_operations (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGSERIAL PRIMARY KEY,
|
||||||
name VARCHAR(255) NOT NULL,
|
name VARCHAR(255) NOT NULL,
|
||||||
description VARCHAR(255) NOT NULL
|
description VARCHAR(255) NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS branch_operations (
|
CREATE TABLE IF NOT EXISTS branch_operations (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGSERIAL PRIMARY KEY,
|
||||||
operation_id BIGINT NOT NULL,
|
operation_id BIGINT NOT NULL,
|
||||||
|
|
@ -165,55 +164,66 @@ CREATE TABLE IF NOT EXISTS branch_operations (
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
||||||
----------------------------------------------seed data-------------------------------------------------------------
|
----------------------------------------------seed data-------------------------------------------------------------
|
||||||
-------------------------------------- DO NOT USE IN PRODUCTION-------------------------------------------------
|
-------------------------------------- DO NOT USE IN PRODUCTION-------------------------------------------------
|
||||||
|
|
||||||
CREATE EXTENSION IF NOT EXISTS pgcrypto;
|
CREATE EXTENSION IF NOT EXISTS pgcrypto;
|
||||||
|
|
||||||
INSERT INTO users (
|
INSERT INTO users (
|
||||||
first_name, last_name, email, phone_number, password, role,
|
first_name,
|
||||||
email_verified, phone_verified, created_at, updated_at,
|
last_name,
|
||||||
suspended_at, suspended
|
email,
|
||||||
) VALUES (
|
phone_number,
|
||||||
'John',
|
password,
|
||||||
'Doe',
|
role,
|
||||||
'john.doe@example.com',
|
email_verified,
|
||||||
NULL,
|
phone_verified,
|
||||||
crypt('password123', gen_salt('bf'))::bytea,
|
created_at,
|
||||||
'customer',
|
updated_at,
|
||||||
TRUE,
|
suspended_at,
|
||||||
FALSE,
|
suspended
|
||||||
CURRENT_TIMESTAMP,
|
)
|
||||||
CURRENT_TIMESTAMP,
|
VALUES (
|
||||||
NULL,
|
'John',
|
||||||
FALSE
|
'Doe',
|
||||||
);
|
'john.doe@example.com',
|
||||||
|
NULL,
|
||||||
|
crypt('password123', gen_salt('bf'))::bytea,
|
||||||
|
'customer',
|
||||||
|
TRUE,
|
||||||
|
FALSE,
|
||||||
|
CURRENT_TIMESTAMP,
|
||||||
|
CURRENT_TIMESTAMP,
|
||||||
|
NULL,
|
||||||
|
FALSE
|
||||||
|
);
|
||||||
INSERT INTO users (
|
INSERT INTO users (
|
||||||
first_name, last_name, email, phone_number, password, role,
|
first_name,
|
||||||
email_verified, phone_verified, created_at, updated_at,
|
last_name,
|
||||||
suspended_at, suspended
|
email,
|
||||||
) VALUES (
|
phone_number,
|
||||||
'Samuel',
|
password,
|
||||||
'Tariku',
|
role,
|
||||||
'cybersamt@gmail.com',
|
email_verified,
|
||||||
NULL,
|
phone_verified,
|
||||||
crypt('password@123', gen_salt('bf'))::bytea,
|
created_at,
|
||||||
'cashier',
|
updated_at,
|
||||||
TRUE,
|
suspended_at,
|
||||||
FALSE,
|
suspended
|
||||||
CURRENT_TIMESTAMP,
|
)
|
||||||
CURRENT_TIMESTAMP,
|
VALUES (
|
||||||
NULL,
|
'Samuel',
|
||||||
FALSE
|
'Tariku',
|
||||||
);
|
'cybersamt@gmail.com',
|
||||||
|
NULL,
|
||||||
|
crypt('password@123', gen_salt('bf'))::bytea,
|
||||||
INSERT INTO supported_operations (
|
'cashier',
|
||||||
name, description
|
TRUE,
|
||||||
) VALUES
|
FALSE,
|
||||||
('SportBook', 'Sportbook operations'),
|
CURRENT_TIMESTAMP,
|
||||||
('Virtual', 'Virtual operations'),
|
CURRENT_TIMESTAMP,
|
||||||
('GameZone', 'GameZone operations')
|
NULL,
|
||||||
;
|
FALSE
|
||||||
|
);
|
||||||
|
INSERT INTO supported_operations (name, description)
|
||||||
|
VALUES ('SportBook', 'Sportbook operations'),
|
||||||
|
('Virtual', 'Virtual operations'),
|
||||||
|
('GameZone', 'GameZone operations');
|
||||||
Loading…
Reference in New Issue
Block a user