Skip to content

Commit 589178f

Browse files
committed
postgres default
Signed-off-by: plutov <[email protected]>
1 parent 140746e commit 589178f

File tree

7 files changed

+104
-135
lines changed

7 files changed

+104
-135
lines changed

.github/workflows/fly-deploy.yml

-19
This file was deleted.

README.md

-6
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ This approach offers a number of advantages, including:
3232
- [ ] Advanced question types
3333
- [ ] Pipe answers into the following questions
3434

35-
## Demo
36-
37-
[Demo admin panel](https://formulosity.vercel.app/app). Credentials: `user` / `pass`
38-
3935
## Survey Structure
4036

4137
Each directory in `SURVEYS_DIR` is a survey. You can configure the source of your surveys by setting different `SURVEYS_DIR` env var.
@@ -295,8 +291,6 @@ You can deploy individual services to any cloud provider or self host them.
295291
- Next.js frontend. It's also packaged as a Docker container, but also can be deployed to Vercel for example.
296292
- [Optional] Postgres database. You can use managed Postgres services or deploy it yourself.
297293
298-
The demo service (links above) is deployed to Fly.io (Go, SQLite) and Vercel (Next.js) and are under the free tiers.
299-
300294
### Environment Variables
301295
302296
API:

api/migrations/postgres/000001_schema.up.sql

+39-43
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,50 @@ CREATE TYPE survey_parse_statuses AS ENUM ('success', 'error', 'deleted');
66

77
CREATE TYPE survey_delivery_statuses AS ENUM ('launched', 'stopped');
88

9-
CREATE TABLE
10-
surveys (
11-
id serial NOT NULL PRIMARY KEY,
12-
uuid uuid NOT NULL DEFAULT uuid_generate_v4 () UNIQUE,
13-
created_at timestamp without time zone default (now () at time zone 'utc'),
14-
parse_status survey_parse_statuses,
15-
delivery_status survey_delivery_statuses,
16-
error_log TEXT,
17-
name varchar(32) NOT NULL UNIQUE,
18-
url_slug varchar(1024) NOT NULL UNIQUE,
19-
config JSONB
20-
);
9+
CREATE TABLE surveys (
10+
id serial NOT NULL PRIMARY KEY,
11+
uuid uuid NOT NULL DEFAULT uuid_generate_v4 () UNIQUE,
12+
created_at timestamp without time zone default (now () at time zone 'utc'),
13+
parse_status survey_parse_statuses,
14+
delivery_status survey_delivery_statuses,
15+
error_log TEXT,
16+
name varchar(32) NOT NULL UNIQUE,
17+
url_slug varchar(1024) NOT NULL UNIQUE,
18+
config JSONB
19+
);
2120

2221
CREATE TYPE surveys_sessions_status AS ENUM ('in_progress', 'completed');
2322

24-
CREATE TABLE
25-
surveys_sessions (
26-
id serial NOT NULL PRIMARY KEY,
27-
uuid uuid NOT NULL DEFAULT uuid_generate_v4 () UNIQUE,
28-
created_at timestamp without time zone default (now () at time zone 'utc'),
29-
completed_at timestamp without time zone,
30-
status surveys_sessions_status,
31-
survey_id integer NOT NULL,
32-
ip_addr varchar(512) NULL,
33-
CONSTRAINT fk_surveys_sessions1 FOREIGN KEY (survey_id) REFERENCES surveys (id) ON DELETE CASCADE
34-
);
35-
36-
CREATE TABLE
37-
surveys_questions (
38-
id serial NOT NULL PRIMARY KEY,
39-
uuid uuid NOT NULL DEFAULT uuid_generate_v4 () UNIQUE,
40-
survey_id integer NOT NULL,
41-
question_id varchar(256) NOT NULL,
42-
CONSTRAINT fk_surveys_questions1 FOREIGN KEY (survey_id) REFERENCES surveys (id) ON DELETE CASCADE
43-
);
23+
CREATE TABLE surveys_sessions (
24+
id serial NOT NULL PRIMARY KEY,
25+
uuid uuid NOT NULL DEFAULT uuid_generate_v4 () UNIQUE,
26+
created_at timestamp without time zone default (now () at time zone 'utc'),
27+
completed_at timestamp without time zone,
28+
status surveys_sessions_status,
29+
survey_id integer NOT NULL,
30+
ip_addr varchar(512) NULL,
31+
CONSTRAINT fk_surveys_sessions1 FOREIGN KEY (survey_id) REFERENCES surveys (id) ON DELETE CASCADE
32+
);
33+
34+
CREATE TABLE surveys_questions (
35+
id serial NOT NULL PRIMARY KEY,
36+
uuid uuid NOT NULL DEFAULT uuid_generate_v4 () UNIQUE,
37+
survey_id integer NOT NULL,
38+
question_id varchar(256) NOT NULL,
39+
CONSTRAINT fk_surveys_questions1 FOREIGN KEY (survey_id) REFERENCES surveys (id) ON DELETE CASCADE
40+
);
4441

4542
CREATE UNIQUE INDEX surveys_questions_id ON surveys_questions (survey_id, question_id);
4643

47-
CREATE TABLE
48-
surveys_answers (
49-
id serial NOT NULL PRIMARY KEY,
50-
uuid uuid NOT NULL DEFAULT uuid_generate_v4 () UNIQUE,
51-
created_at timestamp without time zone default (now () at time zone 'utc'),
52-
session_id integer NOT NULL,
53-
question_id integer NOT NULL,
54-
answer JSONB,
55-
CONSTRAINT fk_surveys_answers1 FOREIGN KEY (session_id) REFERENCES surveys_sessions (id) ON DELETE CASCADE,
56-
CONSTRAINT fk_surveys_answers2 FOREIGN KEY (question_id) REFERENCES surveys_questions (id) ON DELETE CASCADE
57-
);
44+
CREATE TABLE surveys_answers (
45+
id serial NOT NULL PRIMARY KEY,
46+
uuid uuid NOT NULL DEFAULT uuid_generate_v4 () UNIQUE,
47+
created_at timestamp without time zone default (now () at time zone 'utc'),
48+
session_id integer NOT NULL,
49+
question_id integer NOT NULL,
50+
answer JSONB,
51+
CONSTRAINT fk_surveys_answers1 FOREIGN KEY (session_id) REFERENCES surveys_sessions (id) ON DELETE CASCADE,
52+
CONSTRAINT fk_surveys_answers2 FOREIGN KEY (question_id) REFERENCES surveys_questions (id) ON DELETE CASCADE
53+
);
5854

5955
CREATE UNIQUE INDEX surveys_answers_unique ON surveys_answers (session_id, question_id);
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
CREATE TABLE
2-
surveys_webhook_responses (
3-
id serial NOT NULL PRIMARY KEY,
4-
created_at timestamp without time zone default (now () at time zone 'utc'),
5-
session_id integer NOT NULL,
6-
response_status integer NOT NULL,
7-
response TEXT,
8-
CONSTRAINT fk_surveys_webhooks1 FOREIGN KEY (session_id) REFERENCES surveys_sessions (id) ON DELETE CASCADE,
9-
);
1+
CREATE TABLE surveys_webhook_responses (
2+
id serial NOT NULL PRIMARY KEY,
3+
created_at timestamp without time zone default (now () at time zone 'utc'),
4+
session_id integer NOT NULL,
5+
response_status integer NOT NULL,
6+
response TEXT,
7+
CONSTRAINT fk_surveys_webhooks1 FOREIGN KEY (session_id) REFERENCES surveys_sessions (id) ON DELETE CASCADE
8+
);
9+
+30-30
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
CREATE TABLE surveys (
2-
id INTEGER PRIMARY KEY AUTOINCREMENT,
3-
uuid TEXT NOT NULL UNIQUE,
4-
created_at TEXT,
5-
parse_status TEXT,
6-
delivery_status TEXT,
7-
error_log TEXT,
8-
name TEXT NOT NULL UNIQUE,
9-
url_slug TEXT NOT NULL UNIQUE,
10-
config TEXT
2+
id INTEGER PRIMARY KEY AUTOINCREMENT,
3+
uuid TEXT NOT NULL UNIQUE,
4+
created_at TEXT,
5+
parse_status TEXT,
6+
delivery_status TEXT,
7+
error_log TEXT,
8+
name TEXT NOT NULL UNIQUE,
9+
url_slug TEXT NOT NULL UNIQUE,
10+
config TEXT
1111
);
1212

1313
CREATE TABLE surveys_sessions (
14-
id INTEGER PRIMARY KEY AUTOINCREMENT,
15-
uuid TEXT NOT NULL UNIQUE,
16-
created_at TEXT,
17-
completed_at TEXT,
18-
status TEXT,
19-
survey_id INTEGER NOT NULL,
20-
ip_addr TEXT,
21-
FOREIGN KEY (survey_id) REFERENCES surveys (id) ON DELETE CASCADE
14+
id INTEGER PRIMARY KEY AUTOINCREMENT,
15+
uuid TEXT NOT NULL UNIQUE,
16+
created_at TEXT,
17+
completed_at TEXT,
18+
status TEXT,
19+
survey_id INTEGER NOT NULL,
20+
ip_addr TEXT,
21+
FOREIGN KEY (survey_id) REFERENCES surveys (id) ON DELETE CASCADE
2222
);
2323

2424
CREATE TABLE surveys_questions (
25-
id INTEGER PRIMARY KEY AUTOINCREMENT,
26-
uuid TEXT NOT NULL UNIQUE,
27-
survey_id INTEGER NOT NULL,
28-
question_id TEXT NOT NULL,
29-
FOREIGN KEY (survey_id) REFERENCES surveys (id) ON DELETE CASCADE
25+
id INTEGER PRIMARY KEY AUTOINCREMENT,
26+
uuid TEXT NOT NULL UNIQUE,
27+
survey_id INTEGER NOT NULL,
28+
question_id TEXT NOT NULL,
29+
FOREIGN KEY (survey_id) REFERENCES surveys (id) ON DELETE CASCADE
3030
);
3131

3232
CREATE UNIQUE INDEX surveys_questions_id ON surveys_questions (survey_id, question_id);
3333

3434
CREATE TABLE surveys_answers (
35-
id INTEGER PRIMARY KEY AUTOINCREMENT,
36-
uuid TEXT NOT NULL UNIQUE,
37-
created_at TEXT,
38-
session_id INTEGER NOT NULL,
39-
question_id INTEGER NOT NULL,
40-
answer TEXT,
41-
FOREIGN KEY (session_id) REFERENCES surveys_sessions (id) ON DELETE CASCADE,
42-
FOREIGN KEY (question_id) REFERENCES surveys_questions (id) ON DELETE CASCADE
35+
id INTEGER PRIMARY KEY AUTOINCREMENT,
36+
uuid TEXT NOT NULL UNIQUE,
37+
created_at TEXT,
38+
session_id INTEGER NOT NULL,
39+
question_id INTEGER NOT NULL,
40+
answer TEXT,
41+
FOREIGN KEY (session_id) REFERENCES surveys_sessions (id) ON DELETE CASCADE,
42+
FOREIGN KEY (question_id) REFERENCES surveys_questions (id) ON DELETE CASCADE
4343
);
4444

4545
CREATE UNIQUE INDEX surveys_answers_unique ON surveys_answers (session_id, question_id);
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
CREATE TABLE surveys_webhook_responses (
2-
id INTEGER PRIMARY KEY AUTOINCREMENT,
3-
created_at TEXT,
4-
session_id INTEGER NOT NULL,
5-
response_status INTEGER NOT NULL,
6-
response TEXT,
7-
FOREIGN KEY (session_id) REFERENCES surveys_sessions (id) ON DELETE CASCADE
8-
);
2+
id INTEGER PRIMARY KEY AUTOINCREMENT,
3+
created_at TEXT,
4+
session_id INTEGER NOT NULL,
5+
response_status INTEGER NOT NULL,
6+
response TEXT,
7+
FOREIGN KEY (session_id) REFERENCES surveys_sessions (id) ON DELETE CASCADE
8+
);
9+

compose.yaml

+18-21
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@ services:
55
context: ./api
66
ports:
77
- "9900:8080"
8-
# depends_on:
9-
# - postgres
8+
depends_on:
9+
- postgres
1010
environment:
11-
- DATABASE_TYPE=sqlite # postgres|sqlite
12-
# - DATABASE_URL=postgres://postgres:postgres@postgres:5432/formulosity?sslmode=disable
13-
- DATABASE_URL=/root/sqlite3/formulosity.db
11+
- DATABASE_TYPE=postgres # postgres|sqlite
12+
- DATABASE_URL=postgres://user:pass@postgres:5432/formulosity?sslmode=disable
13+
# - DATABASE_URL=/root/sqlite3/formulosity.db
1414
- SURVEYS_DIR=/root/surveys
1515
- UPLOADS_DIR=/root/uploads
1616
volumes:
1717
- ./api/surveys:/root/surveys
1818
- ./api/sqlite3:/root/sqlite3
1919
- ./api/uploads:/root/uploads
20-
2120
ui:
2221
restart: always
2322
build:
@@ -31,21 +30,19 @@ services:
3130
- HTTP_BASIC_AUTH=user:pass
3231
depends_on:
3332
- api
34-
35-
# postgres:
36-
# image: postgres:16.0-alpine
37-
# restart: always
38-
# environment:
39-
# - POSTGRES_USER=postgres
40-
# - POSTGRES_PASSWORD=postgres
41-
# - POSTGRES_DB=formulosity
42-
# ports:
43-
# - "5432:5432"
44-
# volumes:
45-
# - ./api/postgres-data:/var/lib/postgresql/data
46-
# logging:
47-
# driver: none
48-
33+
postgres:
34+
image: postgres:16.0-alpine
35+
restart: always
36+
environment:
37+
- POSTGRES_USER=user
38+
- POSTGRES_PASSWORD=pass
39+
- POSTGRES_DB=formulosity
40+
ports:
41+
- "5432:5432"
42+
volumes:
43+
- ./api/postgres-data:/var/lib/postgresql/data
44+
logging:
45+
driver: none
4946
volumes:
5047
dbvolume:
5148
driver: local

0 commit comments

Comments
 (0)