-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdb_setup.js
More file actions
168 lines (148 loc) · 4.48 KB
/
db_setup.js
File metadata and controls
168 lines (148 loc) · 4.48 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
const { Client } = require('pg');
// require('dotenv').config({ path: '.env' });
// const connectionString = 'postgresql://postgres.hboerklcnkmdehpodemx:Blackcoat_password897@aws-1-ap-southeast-1.pooler.supabase.com:5432/postgres';
// const connectionString = 'postgresql://postgres.hboerklcnkmdehpodemx:Blackcoat_password897@aws-1-ap-southeast-1.pooler.supabase.com:5432/postgres';
//
const connectionString =
"postgresql://postgres.hboerklcnkmdehpodemx:Blackcoat_password897@aws-1-ap-southeast-1.pooler.supabase.com:5432/postgres";
const client = new Client({
connectionString,
// connectionTimeoutMillis: 10000, // 10 second timeout
ssl: {
rejectUnauthorized: false,
},
});
const schema = `
-- Enable uuid-ossp if not enabled
create extension if not exists "uuid-ossp";
-- Profiles
create table if not exists profiles (
id uuid references auth.users not null primary key,
first_name text,
last_name text,
avatar_url text,
email text
);
-- Organizations
create table if not exists organizations (
id uuid default gen_random_uuid() primary key,
name text not null,
slug text unique not null,
created_at timestamptz default now()
);
-- Org Members
create table if not exists organization_members (
organization_id uuid references organizations not null,
user_id uuid references profiles not null,
role text default 'member',
primary key (organization_id, user_id)
);
-- Projects
create table if not exists projects (
id uuid default gen_random_uuid() primary key,
organization_id uuid references organizations not null,
name text not null,
key text not null,
description text,
status text default 'Active',
start_date date,
target_date date,
lead_id uuid references profiles,
created_at timestamptz default now()
);
-- Task Statuses
create table if not exists task_statuses (
id uuid default gen_random_uuid() primary key,
project_id uuid references projects not null,
name text not null,
color text,
position int,
is_default boolean default false,
created_at timestamptz default now()
);
-- Tasks
create table if not exists tasks (
id uuid default gen_random_uuid() primary key,
project_id uuid references projects not null,
parent_id uuid references tasks,
title text not null,
description text,
status_id uuid references task_statuses,
priority text default 'Medium',
type text default 'Task',
story_points int,
assignee_id uuid references profiles,
reporter_id uuid references profiles,
due_date timestamptz,
tags text[],
backlog_order float,
created_at timestamptz default now()
);
-- Comments
create table if not exists comments (
id uuid default gen_random_uuid() primary key,
task_id uuid references tasks not null,
user_id uuid references profiles not null,
content text not null,
created_at timestamptz default now()
);
-- Startup OS: Metrics
create table if not exists metrics (
id uuid default gen_random_uuid() primary key,
project_id uuid references projects not null,
name text not null,
unit text,
target_value float,
direction text default 'Higher',
frequency text default 'Daily',
created_at timestamptz default now()
);
create table if not exists metric_entries (
id uuid default gen_random_uuid() primary key,
metric_id uuid references metrics not null,
value float not null,
notes text,
date date default CURRENT_DATE,
user_id uuid references profiles,
created_at timestamptz default now()
);
-- Startup OS: Recurring Tasks
create table if not exists recurring_tasks (
id uuid default gen_random_uuid() primary key,
project_id uuid references projects not null,
cron_schedule text not null,
prompt_text text not null,
created_at timestamptz default now()
);
-- Dashboard
create table if not exists dashboard_layouts (
user_id uuid references profiles primary key,
layout jsonb
);
-- Suggestions
create table if not exists suggestions (
id uuid default gen_random_uuid() primary key,
project_id uuid references projects not null,
content text not null,
referrer_id uuid references profiles,
upvotes int default 0,
status text default 'Open',
created_at timestamptz default now()
);
`;
async function run() {
try {
await client.connect();
console.log('Connected to database');
// await client.query('BEGIN');
// await client.query(schema);
// await client.query('COMMIT');
console.log('Schema applied successfully');
} catch (e) {
console.error('Error applying schema:', e);
console.log(e)
} finally {
await client.end();
}
}
run();