-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-tables.sql
More file actions
62 lines (57 loc) · 1.82 KB
/
Copy pathcreate-tables.sql
File metadata and controls
62 lines (57 loc) · 1.82 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
-- Create the users table
CREATE TABLE IF NOT EXISTS users (
id VARCHAR PRIMARY KEY DEFAULT gen_random_uuid(),
email VARCHAR UNIQUE,
first_name VARCHAR,
last_name VARCHAR,
profile_image_url VARCHAR,
role VARCHAR NOT NULL DEFAULT 'landlord',
created_at TIMESTAMP DEFAULT NOW(),
updated_at TIMESTAMP DEFAULT NOW()
);
-- Create the sessions table for authentication
CREATE TABLE IF NOT EXISTS sessions (
sid VARCHAR PRIMARY KEY,
sess JSONB NOT NULL,
expire TIMESTAMP NOT NULL
);
-- Create index on sessions expire
CREATE INDEX IF NOT EXISTS IDX_session_expire ON sessions(expire);
-- Create the properties table
CREATE TABLE IF NOT EXISTS properties (
id VARCHAR PRIMARY KEY DEFAULT gen_random_uuid(),
name VARCHAR NOT NULL,
address TEXT NOT NULL,
property_type VARCHAR NOT NULL,
total_units INTEGER NOT NULL,
description TEXT,
image_url VARCHAR,
owner_id VARCHAR NOT NULL REFERENCES users(id),
created_at TIMESTAMP DEFAULT NOW(),
updated_at TIMESTAMP DEFAULT NOW()
);
-- Create other basic tables we might need
CREATE TABLE IF NOT EXISTS tenants (
id VARCHAR PRIMARY KEY DEFAULT gen_random_uuid(),
user_id VARCHAR NOT NULL REFERENCES users(id),
property_id VARCHAR NOT NULL REFERENCES properties(id),
unit_id VARCHAR,
lease_start_date DATE,
lease_end_date DATE,
monthly_rent DECIMAL(10,2),
security_deposit DECIMAL(10,2),
status VARCHAR DEFAULT 'active',
created_at TIMESTAMP DEFAULT NOW(),
updated_at TIMESTAMP DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS payments (
id VARCHAR PRIMARY KEY DEFAULT gen_random_uuid(),
tenant_id VARCHAR NOT NULL REFERENCES tenants(id),
amount DECIMAL(10,2) NOT NULL,
payment_date DATE NOT NULL,
payment_method VARCHAR,
status VARCHAR DEFAULT 'pending',
description TEXT,
created_at TIMESTAMP DEFAULT NOW(),
updated_at TIMESTAMP DEFAULT NOW()
);