Skip to content

Commit 88f3953

Browse files
committed
Use null for optional foreign keys
1 parent 0d3e152 commit 88f3953

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

backend/embed/migrations/mysql/20201013035318_initial_schema.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ CREATE TABLE IF NOT EXISTS `dns_provider`
104104
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON DELETE CASCADE
105105
);
106106

107-
CREATE TABLE IF NOT EXISTS certificate
107+
CREATE TABLE IF NOT EXISTS `certificate`
108108
(
109109
`id` INT AUTO_INCREMENT PRIMARY KEY,
110110
`created_at` BIGINT NOT NULL DEFAULT 0,
111111
`updated_at` BIGINT NOT NULL DEFAULT 0,
112112
`is_deleted` INT NOT NULL DEFAULT 0, -- int on purpose, gormism
113113
`user_id` INT NOT NULL,
114114
`type` VARCHAR(50) NOT NULL, -- custom,dns,http
115-
`certificate_authority_id` INT, -- 0 for a custom cert
115+
`certificate_authority_id` INT, -- null for a custom cert
116116
`dns_provider_id` INT, -- 0, for a http or custom cert
117117
`name` VARCHAR(50) NOT NULL,
118118
`domain_names` TEXT NOT NULL,
@@ -216,12 +216,12 @@ CREATE TABLE IF NOT EXISTS host
216216
`nginx_template_id` INT NOT NULL,
217217
`listen_interface` VARCHAR(50) NOT NULL DEFAULT '',
218218
`domain_names` TEXT NOT NULL,
219-
`upstream_id` INT NOT NULL DEFAULT 0,
219+
`upstream_id` INT,
220220
`proxy_scheme` VARCHAR(50) NOT NULL DEFAULT '',
221221
`proxy_host` VARCHAR(50) NOT NULL DEFAULT '',
222222
`proxy_port` INT NOT NULL DEFAULT 0,
223-
`certificate_id` INT NOT NULL DEFAULT 0,
224-
`access_list_id` INT NOT NULL DEFAULT 0,
223+
`certificate_id` INT,
224+
`access_list_id` INT,
225225
`ssl_forced` BOOLEAN NOT NULL DEFAULT FALSE,
226226
`caching_enabled` BOOLEAN NOT NULL DEFAULT FALSE,
227227
`block_exploits` BOOLEAN NOT NULL DEFAULT FALSE,

backend/embed/migrations/postgres/20201013035318_initial_schema.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,12 @@ CREATE TABLE "host" (
187187
"nginx_template_id" INTEGER NOT NULL REFERENCES "nginx_template"("id") ON DELETE CASCADE,
188188
"listen_interface" TEXT NOT NULL DEFAULT '',
189189
"domain_names" TEXT NOT NULL,
190-
"upstream_id" INTEGER NOT NULL DEFAULT 0 REFERENCES "upstream"("id") ON DELETE CASCADE,
190+
"upstream_id" INTEGER REFERENCES "upstream"("id") ON DELETE CASCADE,
191191
"proxy_scheme" TEXT NOT NULL DEFAULT '',
192192
"proxy_host" TEXT NOT NULL DEFAULT '',
193193
"proxy_port" INTEGER NOT NULL DEFAULT 0,
194-
"certificate_id" INTEGER NOT NULL DEFAULT 0 REFERENCES "certificate"("id") ON DELETE CASCADE,
195-
"access_list_id" INTEGER NOT NULL DEFAULT 0 REFERENCES "access_list"("id") ON DELETE CASCADE,
194+
"certificate_id" INTEGER REFERENCES "certificate"("id") ON DELETE CASCADE,
195+
"access_list_id" INTEGER REFERENCES "access_list"("id") ON DELETE CASCADE,
196196
"ssl_forced" BOOLEAN NOT NULL DEFAULT FALSE,
197197
"caching_enabled" BOOLEAN NOT NULL DEFAULT FALSE,
198198
"block_exploits" BOOLEAN NOT NULL DEFAULT FALSE,

backend/embed/migrations/sqlite/20201013035318_initial_schema.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,12 @@ CREATE TABLE IF NOT EXISTS `host`
216216
nginx_template_id INTEGER NOT NULL,
217217
listen_interface TEXT NOT NULL DEFAULT "",
218218
domain_names TEXT NOT NULL,
219-
upstream_id INTEGER NOT NULL DEFAULT 0,
219+
upstream_id INTEGER,
220220
proxy_scheme TEXT NOT NULL DEFAULT "",
221221
proxy_host TEXT NOT NULL DEFAULT "",
222222
proxy_port INTEGER NOT NULL DEFAULT 0,
223-
certificate_id INTEGER NOT NULL DEFAULT 0,
224-
access_list_id INTEGER NOT NULL DEFAULT 0,
223+
certificate_id INTEGER,
224+
access_list_id INTEGER,
225225
ssl_forced INTEGER NOT NULL DEFAULT 0,
226226
caching_enabled INTEGER NOT NULL DEFAULT 0,
227227
block_exploits INTEGER NOT NULL DEFAULT 0,

0 commit comments

Comments
 (0)