-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdefault.nix
108 lines (89 loc) · 3.05 KB
/
default.nix
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
{ pkgs ? import <nixpkgs> {} }:
let
python = pkgs.python3;
in pkgs.mkShell {
buildInputs = [
pkgs.just
pkgs.poetry
pkgs.postgresql # Add PostgreSQL Database
];
shellHook = ''
# SETUP POSTGRES SERVER
echo "Loading environment variables from .env"
if [ -f .env ]; then
export $(cat .env | xargs)
else
echo ".env file not found! Exiting."
exit 1
fi
# Define PGDATA and LOGFILE based on environment variables
export PGDATA=$(pwd)/pgdata
LOGFILE=$(pwd)/pgdata/postgresql.log
echo "Initializing PostgreSQL data directory at $PGDATA"
echo "PGDATA: $PGDATA"
if [ ! -d "$PGDATA" ]; then
initdb -D "$PGDATA" | tee -a $LOGFILE
fi
echo "Stopping any existing PostgreSQL server..."
pg_ctl -D "$PGDATA" stop || echo "No existing server to stop."
echo "Starting PostgreSQL server..."
pg_ctl -D "$PGDATA" -l $LOGFILE start
# Wait for PostgreSQL to start
sleep 2
# Set up the test database, role, and tables
psql -d $POSTGRES_DB <<SQL | tee -a $LOGFILE
-- Create the conversation table
CREATE TABLE IF NOT EXISTS conversation (
message_id VARCHAR PRIMARY KEY,
conv_id VARCHAR NOT NULL,
userid VARCHAR NOT NULL,
timestamp TIMESTAMP NOT NULL,
name VARCHAR,
role VARCHAR NOT NULL,
message TEXT NOT NULL
);
-- Create the utterance_token_info table
CREATE TABLE IF NOT EXISTS utterance_token_info (
message_id VARCHAR PRIMARY KEY,
conv_id VARCHAR NOT NULL,
userid VARCHAR NOT NULL,
name VARCHAR,
role VARCHAR NOT NULL,
timestamp TIMESTAMP NOT NULL,
ents JSONB
);
-- Create the utterance_text_info table
CREATE TABLE IF NOT EXISTS utterance_text_info (
message_id VARCHAR PRIMARY KEY,
conv_id VARCHAR NOT NULL,
userid VARCHAR NOT NULL,
name VARCHAR,
role VARCHAR NOT NULL,
timestamp TIMESTAMP NOT NULL,
moderator JSONB,
mod_label VARCHAR,
tern_sent JSONB,
tern_label VARCHAR,
emo_27 JSONB,
emo_27_label VARCHAR
);
CREATE ROLE $POSTGRES_USER WITH LOGIN PASSWORD '$POSTGRES_PASSWORD';
GRANT ALL PRIVILEGES ON DATABASE $POSTGRES_DB TO $POSTGRES_USER;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO $POSTGRES_USER;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO $POSTGRES_USER;
GRANT ALL PRIVILEGES ON SCHEMA public TO $POSTGRES_USER;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO $POSTGRES_USER;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO $POSTGRES_USER;
-- If you're using PostgreSQL 14 or later, you can also add these:
GRANT pg_read_all_data TO $POSTGRES_USER;
GRANT pg_write_all_data TO $POSTGRES_USER;
SQL
echo "PostgreSQL setup complete. Logs can be found at $LOGFILE"
# FINISH POSTGRES SERVER
# BUILD TOPOS PROJECT
echo "Running just build"
just build
echo "Starting the topos server..."
topos run
'';
}