Skip to content

Commit

Permalink
Update CHECK constraints to match API validation
Browse files Browse the repository at this point in the history
domain/host limit based on number of allowed characters in a DNS name
without the trailing dot. See e.g.
https://devblogs.microsoft.com/oldnewthing/?p=7873 for a good
explanation.
  • Loading branch information
eest committed Dec 12, 2024
1 parent 22ebb59 commit 7436073
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/server/testdata/migrations/00001_init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
CREATE TABLE organizations (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
ts timestamptz NOT NULL DEFAULT now(),
name text UNIQUE NOT NULL CONSTRAINT non_empty CHECK(length(name)>0)
name text UNIQUE NOT NULL CONSTRAINT non_empty CHECK(length(name)>=1 AND length(name)<=63)
);

CREATE TABLE roles (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
ts timestamptz NOT NULL DEFAULT now(),
name text UNIQUE NOT NULL CONSTRAINT non_empty CHECK(length(name)>0),
name text UNIQUE NOT NULL CONSTRAINT non_empty CHECK(length(name)>=1 AND length(name)<=63),
superuser boolean DEFAULT false NOT NULL
);

Expand All @@ -17,7 +17,7 @@ CREATE TABLE users (
ts timestamptz NOT NULL DEFAULT now(),
org_id uuid REFERENCES organizations(id),
role_id uuid NOT NULL REFERENCES roles(id),
name text UNIQUE NOT NULL CONSTRAINT non_empty CHECK(length(name)>0)
name text UNIQUE NOT NULL CONSTRAINT non_empty CHECK(length(name)>=1 AND length(name)<=63)
);

CREATE TABLE user_argon2keys (
Expand All @@ -37,7 +37,7 @@ CREATE TABLE services (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
ts timestamptz NOT NULL DEFAULT now(),
org_id uuid NOT NULL REFERENCES organizations(id),
name text NOT NULL CONSTRAINT non_empty CHECK(length(name)>0),
name text NOT NULL CONSTRAINT non_empty CHECK(length(name)>=1 AND length(name)<=63),
version_counter BIGINT DEFAULT 0 NOT NULL,
UNIQUE(org_id, name)
);
Expand All @@ -56,15 +56,15 @@ CREATE TABLE service_domains (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
ts timestamptz NOT NULL DEFAULT now(),
service_version_id uuid NOT NULL REFERENCES service_versions(id),
domain text NOT NULL CONSTRAINT non_empty CHECK(length(domain)>0),
domain text NOT NULL CONSTRAINT non_empty CHECK(length(domain)>=1 AND length(domain)<=253),
UNIQUE(service_version_id, domain)
);

CREATE TABLE service_origins (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
ts timestamptz NOT NULL DEFAULT now(),
service_version_id uuid NOT NULL REFERENCES service_versions(id),
host text NOT NULL CONSTRAINT non_empty CHECK(length(host)>0),
host text NOT NULL CONSTRAINT non_empty CHECK(length(host)>=1 AND length(host)<=253),
port integer NOT NULL CONSTRAINT port_range CHECK(port >= 1 AND port <= 65535),
tls boolean DEFAULT true NOT NULL,
UNIQUE(service_version_id, host, port)
Expand Down

0 comments on commit 7436073

Please sign in to comment.