small fix

This commit is contained in:
Samuel Tariku 2025-04-10 16:34:00 +03:00
parent 2163053d97
commit c65ab77386
2 changed files with 115 additions and 100 deletions

View File

@ -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;

View File

@ -2,18 +2,21 @@ 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,
@ -25,7 +28,7 @@ CREATE TABLE refresh_tokens (
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,
@ -36,7 +39,6 @@ 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,
@ -51,31 +53,36 @@ CREATE TABLE IF NOT EXISTS bets (
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,17 +164,24 @@ 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,
password,
role,
email_verified,
phone_verified,
created_at,
updated_at,
suspended_at,
suspended
)
VALUES (
'John', 'John',
'Doe', 'Doe',
'john.doe@example.com', 'john.doe@example.com',
@ -188,13 +194,22 @@ INSERT INTO users (
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,
NULL, NULL,
FALSE 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,
password,
role,
email_verified,
phone_verified,
created_at,
updated_at,
suspended_at,
suspended
)
VALUES (
'Samuel', 'Samuel',
'Tariku', 'Tariku',
'cybersamt@gmail.com', 'cybersamt@gmail.com',
@ -207,13 +222,8 @@ INSERT INTO users (
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,
NULL, NULL,
FALSE FALSE
); );
INSERT INTO supported_operations (name, description)
VALUES ('SportBook', 'Sportbook operations'),
INSERT INTO supported_operations ( ('Virtual', 'Virtual operations'),
name, description ('GameZone', 'GameZone operations');
) VALUES
('SportBook', 'Sportbook operations'),
('Virtual', 'Virtual operations'),
('GameZone', 'GameZone operations')
;