-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema_test.sql
More file actions
39 lines (34 loc) · 1.23 KB
/
Copy pathschema_test.sql
File metadata and controls
39 lines (34 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
-- Test Schema for DB Seed CLI Verification
-- Drop existing tables if they exist
DROP TABLE IF EXISTS orders CASCADE;
DROP TABLE IF EXISTS profiles CASCADE;
DROP TABLE IF EXISTS users CASCADE;
DROP TYPE IF EXISTS user_role CASCADE;
-- Create enum type
CREATE TYPE user_role AS ENUM ('admin', 'user', 'manager');
-- Create users table
CREATE TABLE users (
id SERIAL PRIMARY KEY,
full_name VARCHAR(255) NOT NULL,
phone VARCHAR(50) UNIQUE NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL,
role user_role NOT NULL DEFAULT 'user',
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-- Create profiles table (has a 1-to-1 relationship with users)
CREATE TABLE profiles (
id SERIAL PRIMARY KEY,
user_id INTEGER UNIQUE NOT NULL REFERENCES users(id) ON DELETE CASCADE,
iin VARCHAR(12) UNIQUE NOT NULL,
balance_kzt DECIMAL(15, 2) NOT NULL DEFAULT 0.00,
company_bin VARCHAR(12),
bio TEXT
);
-- Create orders table (has a many-to-1 relationship with users)
CREATE TABLE orders (
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
amount DECIMAL(10, 2) NOT NULL,
description VARCHAR(500),
created_at TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT NOW()
);