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 TABLE IF EXISTS tickets;
|
||||
DROP TABLE IF EXISTS ticket_outcomes;
|
||||
DROP TABLE IF EXISTS bets;
|
||||
DROP TABLE IF EXISTS bet_outcomes;
|
||||
DROP TABLE IF EXISTS wallets;
|
||||
DROP TABLE IF EXISTS customer_wallets;
|
||||
DROP TABLE IF EXISTS wallet_transfer;
|
||||
DROP TABLE IF EXISTS transactions;
|
||||
DROP TABLE IF EXISTS customer_wallets;
|
||||
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,
|
||||
first_name VARCHAR(255) NOT NULL,
|
||||
last_name VARCHAR(255) NOT NULL,
|
||||
email VARCHAR(255) UNIQUE ,
|
||||
email VARCHAR(255) UNIQUE,
|
||||
phone_number VARCHAR(20) UNIQUE,
|
||||
role VARCHAR(50) NOT NULL,
|
||||
password BYTEA NOT NULL,
|
||||
email_verified BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
phone_verified BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMPTZ ,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMPTZ,
|
||||
--
|
||||
suspended_at TIMESTAMPTZ NULL, -- this can be NULL if the user is not suspended
|
||||
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 (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
user_id BIGINT NOT NULL,
|
||||
token TEXT NOT NULL UNIQUE,
|
||||
expires_at TIMESTAMPTZ NOT NULL,
|
||||
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
expires_at TIMESTAMPTZ NOT NULL,
|
||||
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
revoked BOOLEAN DEFAULT FALSE NOT NULL,
|
||||
CONSTRAINT unique_token UNIQUE (token)
|
||||
);
|
||||
-----
|
||||
CREATE TABLE otps (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
CREATE TABLE otps (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
sent_to VARCHAR(255) NOT NULL,
|
||||
medium 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,
|
||||
expires_at TIMESTAMPTZ NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS bets (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
amount BIGINT NOT NULL,
|
||||
total_odds REAL NOT NULL,
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
amount BIGINT NOT NULL,
|
||||
total_odds REAL NOT NULL,
|
||||
status INT NOT NULL,
|
||||
full_name VARCHAR(255) NOT NULL,
|
||||
phone_number VARCHAR(255) NOT NULL,
|
||||
|
|
@ -48,34 +50,39 @@ CREATE TABLE IF NOT EXISTS bets (
|
|||
user_id BIGINT,
|
||||
cashed_out BOOLEAN DEFAULT FALSE 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,
|
||||
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` (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
amount BIGINT NULL,
|
||||
total_odds REAL NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
CREATE TABLE IF NOT EXISTS tickets (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
amount BIGINT NULL,
|
||||
total_odds REAL NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- CREATE TABLE IF NOT EXISTS bet_outcomes (
|
||||
-- id BIGSERIAL PRIMARY KEY,
|
||||
-- bet_id BIGINT NOT NULL,
|
||||
-- event_id bigint not null,
|
||||
-- odd_id BIGINT NOT NULL,
|
||||
-- );
|
||||
|
||||
-- CREATE TABLE IF NOT EXISTS ticket_outcomes (
|
||||
-- id BIGSERIAL PRIMARY KEY,
|
||||
-- ticket_id BIGINT NOT NULL,
|
||||
-- event_id bigint not null,
|
||||
-- odd_id BIGINT NOT NULL,
|
||||
-- );
|
||||
|
||||
CREATE TABLE IF NOT EXISTS bet_outcomes (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
bet_id BIGINT NOT NULL,
|
||||
event_id bigint not null,
|
||||
odd_id BIGINT NOT NULL,
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS ticket_outcomes (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
ticket_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 (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
balance BIGINT NOT NULL DEFAULT 0,
|
||||
|
|
@ -87,8 +94,6 @@ CREATE TABLE IF NOT EXISTS wallets (
|
|||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS customer_wallets (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
customer_id BIGINT NOT NULL,
|
||||
|
|
@ -99,7 +104,6 @@ CREATE TABLE IF NOT EXISTS customer_wallets (
|
|||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE (customer_id, company_id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS wallet_transfer (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
amount BIGINT NOT NULL,
|
||||
|
|
@ -112,7 +116,6 @@ CREATE TABLE IF NOT EXISTS wallet_transfer (
|
|||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS transactions (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
amount BIGINT NOT NULL,
|
||||
|
|
@ -132,7 +135,6 @@ CREATE TABLE IF NOT EXISTS transactions (
|
|||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS branches (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
|
|
@ -144,20 +146,17 @@ CREATE TABLE IF NOT EXISTS branches (
|
|||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE VIEW branch_details AS
|
||||
SELECT branches.*,
|
||||
CONCAT(users.first_name, ' ', users.last_name) AS manager_name,
|
||||
users.phone_number AS manager_phone_number
|
||||
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 (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
description VARCHAR(255) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS branch_operations (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
operation_id BIGINT NOT NULL,
|
||||
|
|
@ -165,55 +164,66 @@ CREATE TABLE IF NOT EXISTS branch_operations (
|
|||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
----------------------------------------------seed data-------------------------------------------------------------
|
||||
-------------------------------------- DO NOT USE IN PRODUCTION-------------------------------------------------
|
||||
|
||||
CREATE EXTENSION IF NOT EXISTS pgcrypto;
|
||||
|
||||
INSERT INTO users (
|
||||
first_name, last_name, email, phone_number, password, role,
|
||||
email_verified, phone_verified, created_at, updated_at,
|
||||
suspended_at, suspended
|
||||
) VALUES (
|
||||
'John',
|
||||
'Doe',
|
||||
'john.doe@example.com',
|
||||
NULL,
|
||||
crypt('password123', gen_salt('bf'))::bytea,
|
||||
'customer',
|
||||
TRUE,
|
||||
FALSE,
|
||||
CURRENT_TIMESTAMP,
|
||||
CURRENT_TIMESTAMP,
|
||||
NULL,
|
||||
FALSE
|
||||
);
|
||||
|
||||
first_name,
|
||||
last_name,
|
||||
email,
|
||||
phone_number,
|
||||
password,
|
||||
role,
|
||||
email_verified,
|
||||
phone_verified,
|
||||
created_at,
|
||||
updated_at,
|
||||
suspended_at,
|
||||
suspended
|
||||
)
|
||||
VALUES (
|
||||
'John',
|
||||
'Doe',
|
||||
'john.doe@example.com',
|
||||
NULL,
|
||||
crypt('password123', gen_salt('bf'))::bytea,
|
||||
'customer',
|
||||
TRUE,
|
||||
FALSE,
|
||||
CURRENT_TIMESTAMP,
|
||||
CURRENT_TIMESTAMP,
|
||||
NULL,
|
||||
FALSE
|
||||
);
|
||||
INSERT INTO users (
|
||||
first_name, last_name, email, phone_number, password, role,
|
||||
email_verified, phone_verified, created_at, updated_at,
|
||||
suspended_at, suspended
|
||||
) VALUES (
|
||||
'Samuel',
|
||||
'Tariku',
|
||||
'cybersamt@gmail.com',
|
||||
NULL,
|
||||
crypt('password@123', gen_salt('bf'))::bytea,
|
||||
'cashier',
|
||||
TRUE,
|
||||
FALSE,
|
||||
CURRENT_TIMESTAMP,
|
||||
CURRENT_TIMESTAMP,
|
||||
NULL,
|
||||
FALSE
|
||||
);
|
||||
|
||||
|
||||
INSERT INTO supported_operations (
|
||||
name, description
|
||||
) VALUES
|
||||
('SportBook', 'Sportbook operations'),
|
||||
('Virtual', 'Virtual operations'),
|
||||
('GameZone', 'GameZone operations')
|
||||
;
|
||||
first_name,
|
||||
last_name,
|
||||
email,
|
||||
phone_number,
|
||||
password,
|
||||
role,
|
||||
email_verified,
|
||||
phone_verified,
|
||||
created_at,
|
||||
updated_at,
|
||||
suspended_at,
|
||||
suspended
|
||||
)
|
||||
VALUES (
|
||||
'Samuel',
|
||||
'Tariku',
|
||||
'cybersamt@gmail.com',
|
||||
NULL,
|
||||
crypt('password@123', gen_salt('bf'))::bytea,
|
||||
'cashier',
|
||||
TRUE,
|
||||
FALSE,
|
||||
CURRENT_TIMESTAMP,
|
||||
CURRENT_TIMESTAMP,
|
||||
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