Skip to content

Commit 3c1b4fd

Browse files
committed
Added migrations for mysql and postgres, added ci testing suites for them
1 parent e0773b1 commit 3c1b4fd

13 files changed

+1266
-41
lines changed

Jenkinsfile

Lines changed: 69 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -125,35 +125,87 @@ pipeline {
125125
}
126126
}
127127
}
128-
stage('Test') {
128+
stage('Test Sqlite') {
129+
environment {
130+
COMPOSE_PROJECT_NAME = "npm_${BRANCH_LOWER}_${BUILD_NUMBER}_sqlite"
131+
COMPOSE_FILE = 'docker/docker-compose.ci.yml'
132+
}
133+
when {
134+
not {
135+
equals expected: 'UNSTABLE', actual: currentBuild.result
136+
}
137+
}
138+
steps {
139+
sh 'rm -rf ./test/results/junit/*'
140+
sh './scripts/ci/fulltest-cypress'
141+
}
142+
post {
143+
always {
144+
// Dumps to analyze later
145+
sh 'mkdir -p debug/sqlite'
146+
sh 'docker logs $(docker-compose ps --all -q fullstack) > debug/sqlite/docker_fullstack.log 2>&1'
147+
sh 'docker logs $(docker-compose ps --all -q stepca) > debug/sqlite/docker_stepca.log 2>&1'
148+
sh 'docker logs $(docker-compose ps --all -q pdns) > debug/sqlite/docker_pdns.log 2>&1'
149+
sh 'docker logs $(docker-compose ps --all -q pdns-db) > debug/sqlite/docker_pdns-db.log 2>&1'
150+
sh 'docker logs $(docker-compose ps --all -q dnsrouter) > debug/sqlite/docker_dnsrouter.log 2>&1'
151+
junit 'test/results/junit/*'
152+
sh 'docker-compose down --rmi all --remove-orphans --volumes -t 30 || true'
153+
}
154+
}
155+
}
156+
stage('Test Mysql') {
157+
environment {
158+
COMPOSE_PROJECT_NAME = "npm_${BRANCH_LOWER}_${BUILD_NUMBER}_mysql"
159+
COMPOSE_FILE = 'docker/docker-compose.ci.mysql.yml'
160+
}
161+
when {
162+
not {
163+
equals expected: 'UNSTABLE', actual: currentBuild.result
164+
}
165+
}
166+
steps {
167+
sh 'rm -rf ./test/results/junit/*'
168+
sh './scripts/ci/fulltest-cypress'
169+
}
170+
post {
171+
always {
172+
// Dumps to analyze later
173+
sh 'mkdir -p debug/mysql'
174+
sh 'docker logs $(docker-compose ps --all -q fullstack) > debug/mysql/docker_fullstack.log 2>&1'
175+
sh 'docker logs $(docker-compose ps --all -q stepca) > debug/mysql/docker_stepca.log 2>&1'
176+
sh 'docker logs $(docker-compose ps --all -q pdns) > debug/mysql/docker_pdns.log 2>&1'
177+
sh 'docker logs $(docker-compose ps --all -q pdns-db) > debug/mysql/docker_pdns-db.log 2>&1'
178+
sh 'docker logs $(docker-compose ps --all -q dnsrouter) > debug/mysql/docker_dnsrouter.log 2>&1'
179+
junit 'test/results/junit/*'
180+
sh 'docker-compose down --rmi all --remove-orphans --volumes -t 30 || true'
181+
}
182+
}
183+
}
184+
stage('Test Postgres') {
185+
environment {
186+
COMPOSE_PROJECT_NAME = "npm_${BRANCH_LOWER}_${BUILD_NUMBER}_postgres"
187+
COMPOSE_FILE = 'docker/docker-compose.ci.postgres.yml'
188+
}
129189
when {
130190
not {
131191
equals expected: 'UNSTABLE', actual: currentBuild.result
132192
}
133193
}
134194
steps {
135-
// Docker image check
136-
/*
137-
sh '''docker run --rm \
138-
-v /var/run/docker.sock:/var/run/docker.sock \
139-
-v "$(pwd)/docker:/app" \
140-
-e CI=true \
141-
wagoodman/dive:latest --ci-config /app/.dive-ci \
142-
"${IMAGE}:${BRANCH_LOWER}-ci-${BUILD_NUMBER}"
143-
'''
144-
*/
195+
sh 'rm -rf ./test/results/junit/*'
145196
sh './scripts/ci/fulltest-cypress'
146197
}
147198
post {
148199
always {
149200
// Dumps to analyze later
150-
sh 'mkdir -p debug'
151-
sh 'docker logs $(docker-compose ps --all -q fullstack) > debug/docker_fullstack.log 2>&1'
152-
sh 'docker logs $(docker-compose ps --all -q stepca) > debug/docker_stepca.log 2>&1'
153-
sh 'docker logs $(docker-compose ps --all -q pdns) > debug/docker_pdns.log 2>&1'
154-
sh 'docker logs $(docker-compose ps --all -q pdns-db) > debug/docker_pdns-db.log 2>&1'
155-
sh 'docker logs $(docker-compose ps --all -q dnsrouter) > debug/docker_dnsrouter.log 2>&1'
201+
sh 'mkdir -p debug/postgres'
202+
sh 'docker logs $(docker-compose ps --all -q fullstack) > debug/postgres/docker_fullstack.log 2>&1'
203+
sh 'docker logs $(docker-compose ps --all -q stepca) > debug/postgres/docker_stepca.log 2>&1'
204+
sh 'docker logs $(docker-compose ps --all -q pdns) > debug/postgres/docker_pdns.log 2>&1'
205+
sh 'docker logs $(docker-compose ps --all -q pdns-db) > debug/postgres/docker_pdns-db.log 2>&1'
206+
sh 'docker logs $(docker-compose ps --all -q dnsrouter) > debug/postgres/docker_dnsrouter.log 2>&1'
156207
junit 'test/results/junit/*'
208+
sh 'docker-compose down --rmi all --remove-orphans --volumes -t 30 || true'
157209
}
158210
}
159211
}
@@ -226,7 +278,6 @@ pipeline {
226278
}
227279
post {
228280
always {
229-
sh 'docker-compose down --rmi all --remove-orphans --volumes -t 30 || true'
230281
sh './scripts/ci/build-cleanup'
231282
echo 'Reverting ownership'
232283
sh 'docker run --rm -v $(pwd):/data jc21/gotools:latest chown -R "$(id -u):$(id -g)" /data'

backend/cmd/server/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ func checkSetup() {
6969

7070
if db != nil {
7171
db.Model(&user.Model{}).
72-
Where("is_disabled = ?", false).
73-
Where("is_system = ?", false).
72+
Where("is_disabled = ?", 0).
73+
Where("is_system = ?", 0).
7474
Count(&count)
7575

7676
if count == 0 {
Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
-- migrate:up
2+
3+
CREATE TABLE IF NOT EXISTS `jwt_keys`
4+
(
5+
`id` INT AUTO_INCREMENT PRIMARY KEY,
6+
`created_at` BIGINT NOT NULL DEFAULT 0,
7+
`updated_at` BIGINT NOT NULL DEFAULT 0,
8+
`is_deleted` INT NOT NULL DEFAULT 0,
9+
`public_key` TEXT NOT NULL,
10+
`private_key` TEXT NOT NULL
11+
);
12+
13+
CREATE TABLE IF NOT EXISTS `user`
14+
(
15+
`id` INT AUTO_INCREMENT PRIMARY KEY,
16+
`created_at` BIGINT NOT NULL DEFAULT 0,
17+
`updated_at` BIGINT NOT NULL DEFAULT 0,
18+
`is_deleted` INT NOT NULL DEFAULT 0,
19+
`name` VARCHAR(50) NOT NULL,
20+
`nickname` VARCHAR(50) NOT NULL,
21+
`email` VARCHAR(255) NOT NULL,
22+
`is_system` INT NOT NULL DEFAULT 0,
23+
`is_disabled` INT NOT NULL DEFAULT 0
24+
);
25+
26+
CREATE TABLE IF NOT EXISTS `capability`
27+
(
28+
`name` VARCHAR(50) PRIMARY KEY,
29+
UNIQUE (`name`)
30+
);
31+
32+
CREATE TABLE IF NOT EXISTS `user_has_capability`
33+
(
34+
`user_id` INT NOT NULL,
35+
`capability_name` VARCHAR(50) NOT NULL,
36+
UNIQUE (`user_id`, `capability_name`),
37+
FOREIGN KEY (`capability_name`) REFERENCES `capability`(`name`)
38+
);
39+
40+
CREATE TABLE IF NOT EXISTS `auth`
41+
(
42+
`id` INT AUTO_INCREMENT PRIMARY KEY,
43+
`created_at` BIGINT NOT NULL DEFAULT 0,
44+
`updated_at` BIGINT NOT NULL DEFAULT 0,
45+
`is_deleted` INT NOT NULL DEFAULT 0,
46+
`user_id` INT NOT NULL,
47+
`type` VARCHAR(50) NOT NULL,
48+
`secret` VARCHAR(255) NOT NULL,
49+
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`),
50+
UNIQUE (`user_id`, `type`)
51+
);
52+
53+
CREATE TABLE IF NOT EXISTS `setting`
54+
(
55+
`id` INT AUTO_INCREMENT PRIMARY KEY,
56+
`created_at` BIGINT NOT NULL DEFAULT 0,
57+
`updated_at` BIGINT NOT NULL DEFAULT 0,
58+
`is_deleted` INT NOT NULL DEFAULT 0,
59+
`name` VARCHAR(50) NOT NULL,
60+
`description` VARCHAR(255) NOT NULL DEFAULT '',
61+
`value` TEXT NOT NULL,
62+
UNIQUE (`name`)
63+
);
64+
65+
CREATE TABLE IF NOT EXISTS `audit_log`
66+
(
67+
`id` INT AUTO_INCREMENT PRIMARY KEY,
68+
`created_at` BIGINT NOT NULL DEFAULT 0,
69+
`updated_at` BIGINT NOT NULL DEFAULT 0,
70+
`is_deleted` INT NOT NULL DEFAULT 0,
71+
`user_id` INT NOT NULL,
72+
`object_type` VARCHAR(50) NOT NULL,
73+
`object_id` INT NOT NULL,
74+
`action` VARCHAR(50) NOT NULL,
75+
`meta` TEXT NOT NULL,
76+
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`)
77+
);
78+
79+
CREATE TABLE IF NOT EXISTS `certificate_authority`
80+
(
81+
`id` INT AUTO_INCREMENT PRIMARY KEY,
82+
`created_at` BIGINT NOT NULL DEFAULT 0,
83+
`updated_at` BIGINT NOT NULL DEFAULT 0,
84+
`is_deleted` INT NOT NULL DEFAULT 0,
85+
`name` VARCHAR(50) NOT NULL,
86+
`acmesh_server` VARCHAR(255) NOT NULL DEFAULT '',
87+
`ca_bundle` VARCHAR(255) NOT NULL DEFAULT '',
88+
`is_wildcard_supported` INT NOT NULL DEFAULT 0, -- specific to each CA, acme v1 doesn't usually have wildcards
89+
`max_domains` INT NOT NULL DEFAULT 5, -- per request
90+
`is_readonly` INT NOT NULL DEFAULT 0
91+
);
92+
93+
CREATE TABLE IF NOT EXISTS `dns_provider`
94+
(
95+
`id` INT AUTO_INCREMENT PRIMARY KEY,
96+
`created_at` BIGINT NOT NULL DEFAULT 0,
97+
`updated_at` BIGINT NOT NULL DEFAULT 0,
98+
`is_deleted` INT NOT NULL DEFAULT 0,
99+
`user_id` INT NOT NULL,
100+
`name` VARCHAR(50) NOT NULL,
101+
`acmesh_name` VARCHAR(50) NOT NULL,
102+
`dns_sleep` INT NOT NULL DEFAULT 0,
103+
`meta` TEXT NOT NULL,
104+
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`)
105+
);
106+
107+
CREATE TABLE IF NOT EXISTS certificate
108+
(
109+
`id` INT AUTO_INCREMENT PRIMARY KEY,
110+
`created_at` BIGINT NOT NULL DEFAULT 0,
111+
`updated_at` BIGINT NOT NULL DEFAULT 0,
112+
`is_deleted` INT NOT NULL DEFAULT 0,
113+
`user_id` INT NOT NULL,
114+
`type` VARCHAR(50) NOT NULL, -- custom,dns,http
115+
`certificate_authority_id` INT, -- 0 for a custom cert
116+
`dns_provider_id` INT, -- 0, for a http or custom cert
117+
`name` VARCHAR(50) NOT NULL,
118+
`domain_names` TEXT NOT NULL,
119+
`expires_on` INT DEFAULT 0,
120+
`status` VARCHAR(50) NOT NULL, -- ready,requesting,failed,provided
121+
`error_message` TEXT NOT NULL,
122+
`meta` TEXT NOT NULL,
123+
`is_ecc` INT NOT NULL DEFAULT 0,
124+
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`),
125+
FOREIGN KEY (`certificate_authority_id`) REFERENCES `certificate_authority`(`id`),
126+
FOREIGN KEY (`dns_provider_id`) REFERENCES `dns_provider`(`id`)
127+
);
128+
129+
CREATE TABLE IF NOT EXISTS `stream`
130+
(
131+
`id` INT AUTO_INCREMENT PRIMARY KEY,
132+
`created_at` BIGINT NOT NULL DEFAULT 0,
133+
`updated_at` BIGINT NOT NULL DEFAULT 0,
134+
`is_deleted` INT NOT NULL DEFAULT 0,
135+
`user_id` INT NOT NULL,
136+
`listen_interface` VARCHAR(50) NOT NULL,
137+
`incoming_port` INT NOT NULL,
138+
`tcp_forwarding` INT NOT NULL DEFAULT 0,
139+
`udp_forwarding` INT NOT NULL DEFAULT 0,
140+
`advanced_config` TEXT NOT NULL,
141+
`is_disabled` INT NOT NULL DEFAULT 0,
142+
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`)
143+
);
144+
145+
CREATE TABLE IF NOT EXISTS `nginx_template`
146+
(
147+
`id` INT AUTO_INCREMENT PRIMARY KEY,
148+
`created_at` BIGINT NOT NULL DEFAULT 0,
149+
`updated_at` BIGINT NOT NULL DEFAULT 0,
150+
`is_deleted` INT NOT NULL DEFAULT 0,
151+
`user_id` INT NOT NULL,
152+
`name` VARCHAR(50) NOT NULL,
153+
`type` VARCHAR(50) NOT NULL,
154+
`template` TEXT NOT NULL,
155+
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`)
156+
);
157+
158+
CREATE TABLE IF NOT EXISTS `upstream`
159+
(
160+
`id` INT AUTO_INCREMENT PRIMARY KEY,
161+
`created_at` BIGINT NOT NULL DEFAULT 0,
162+
`updated_at` BIGINT NOT NULL DEFAULT 0,
163+
`is_deleted` INT NOT NULL DEFAULT 0,
164+
`user_id` INT NOT NULL,
165+
`name` VARCHAR(50) NOT NULL,
166+
`nginx_template_id` INT NOT NULL,
167+
`ip_hash` INT NOT NULL DEFAULT 0,
168+
`ntlm` INT NOT NULL DEFAULT 0,
169+
`keepalive` INT NOT NULL DEFAULT 0,
170+
`keepalive_requests` INT NOT NULL DEFAULT 0,
171+
`keepalive_time` VARCHAR(50) NOT NULL DEFAULT '',
172+
`keepalive_timeout` VARCHAR(50) NOT NULL DEFAULT '',
173+
`advanced_config` TEXT NOT NULL,
174+
`status` VARCHAR(50) NOT NULL DEFAULT '',
175+
`error_message` TEXT NOT NULL,
176+
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`),
177+
FOREIGN KEY (`nginx_template_id`) REFERENCES `nginx_template`(`id`)
178+
);
179+
180+
CREATE TABLE IF NOT EXISTS `upstream_server`
181+
(
182+
`id` INT AUTO_INCREMENT PRIMARY KEY,
183+
`created_at` BIGINT NOT NULL DEFAULT 0,
184+
`updated_at` BIGINT NOT NULL DEFAULT 0,
185+
`is_deleted` INT NOT NULL DEFAULT 0,
186+
`upstream_id` INT NOT NULL,
187+
`server` VARCHAR(50) NOT NULL,
188+
`weight` INT NOT NULL DEFAULT 0,
189+
`max_conns` INT NOT NULL DEFAULT 0,
190+
`max_fails` INT NOT NULL DEFAULT 0,
191+
`fail_timeout` INT NOT NULL DEFAULT 0,
192+
`is_backup` INT NOT NULL DEFAULT 0,
193+
FOREIGN KEY (`upstream_id`) REFERENCES `upstream`(`id`)
194+
);
195+
196+
CREATE TABLE IF NOT EXISTS `access_list`
197+
(
198+
`id` INT AUTO_INCREMENT PRIMARY KEY,
199+
`created_at` BIGINT NOT NULL DEFAULT 0,
200+
`updated_at` BIGINT NOT NULL DEFAULT 0,
201+
`is_deleted` INT NOT NULL DEFAULT 0,
202+
`user_id` INT NOT NULL,
203+
`name` VARCHAR(50) NOT NULL,
204+
`meta` TEXT NOT NULL,
205+
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`)
206+
);
207+
208+
CREATE TABLE IF NOT EXISTS host
209+
(
210+
`id` INT AUTO_INCREMENT PRIMARY KEY,
211+
`created_at` BIGINT NOT NULL DEFAULT 0,
212+
`updated_at` BIGINT NOT NULL DEFAULT 0,
213+
`is_deleted` INT NOT NULL DEFAULT 0,
214+
`user_id` INT NOT NULL,
215+
`type` VARCHAR(50) NOT NULL,
216+
`nginx_template_id` INT NOT NULL,
217+
`listen_interface` VARCHAR(50) NOT NULL DEFAULT '',
218+
`domain_names` TEXT NOT NULL,
219+
`upstream_id` INT NOT NULL DEFAULT 0,
220+
`proxy_scheme` VARCHAR(50) NOT NULL DEFAULT '',
221+
`proxy_host` VARCHAR(50) NOT NULL DEFAULT '',
222+
`proxy_port` INT NOT NULL DEFAULT 0,
223+
`certificate_id` INT NOT NULL DEFAULT 0,
224+
`access_list_id` INT NOT NULL DEFAULT 0,
225+
`ssl_forced` INT NOT NULL DEFAULT 0,
226+
`caching_enabled` INT NOT NULL DEFAULT 0,
227+
`block_exploits` INT NOT NULL DEFAULT 0,
228+
`allow_websocket_upgrade` INT NOT NULL DEFAULT 0,
229+
`http2_support` INT NOT NULL DEFAULT 0,
230+
`hsts_enabled` INT NOT NULL DEFAULT 0,
231+
`hsts_subdomains` INT NOT NULL DEFAULT 0,
232+
`paths` TEXT NOT NULL,
233+
`advanced_config` TEXT NOT NULL,
234+
`status` VARCHAR(50) NOT NULL DEFAULT '',
235+
`error_message` TEXT NOT NULL,
236+
`is_disabled` INT NOT NULL DEFAULT 0,
237+
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`),
238+
FOREIGN KEY (`nginx_template_id`) REFERENCES `nginx_template`(`id`),
239+
FOREIGN KEY (`upstream_id`) REFERENCES `upstream`(`id`),
240+
FOREIGN KEY (`certificate_id`) REFERENCES `certificate`(`id`),
241+
FOREIGN KEY (`access_list_id`) REFERENCES `access_list`(`id`)
242+
);
243+
244+
-- migrate:down
245+
246+
-- Not allowed to go down from initial

0 commit comments

Comments
 (0)