From f28b0d0ae31e5c1f00b9646ee10bbdd7fb63446d Mon Sep 17 00:00:00 2001 From: Gibheer Date: Fri, 21 May 2021 20:53:50 +0200 Subject: [PATCH] fix not null constraint The default not null constraint only checks for the SQL null, not a json null. Therefore add an extended not null constraint by checking both possible null values. --- schema/01_initial.sql | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/schema/01_initial.sql b/schema/01_initial.sql index 9e87f62..7505332 100644 --- a/schema/01_initial.sql +++ b/schema/01_initial.sql @@ -1,7 +1,7 @@ create table if not exists layer3domains( id serial not null primary key, name varchar(128) not null unique, - attributes jsonb not null default '{}', + attributes jsonb default '{}'::jsonb constraint attributes_not_null check(attributes is not null and attributes != 'null'::jsonb), created_at timestamptz not null default now(), created_by varchar(128) not null, modified_at timestamptz not null default now(), @@ -12,7 +12,7 @@ create table if not exists pools( id serial not null, layer3domain_id integer not null references layer3domains(id), name varchar(128) unique, - attributes jsonb not null default '{}'::jsonb, + attributes jsonb default '{}'::jsonb constraint attributes_not_null check(attributes is not null and attributes != 'null'::jsonb), created_at timestamptz not null default now(), created_by varchar(128) not null, modified_at timestamptz not null default now(), @@ -24,7 +24,7 @@ create table containers( layer3domain_id integer not null references layer3domains(id), subnet cidr not null, pool_id integer, - attributes jsonb not null default '{}'::jsonb, + attributes jsonb default '{}'::jsonb constraint attributes_not_null check(attributes is not null and attributes != 'null'::jsonb), created_at timestamptz not null default now(), created_by varchar(128) not null, modified_at timestamptz not null default now(), @@ -50,7 +50,7 @@ create table if not exists ips( layer3domain_id integer not null, version smallint not null, address inet not null, - attributes jsonb not null default '{}'::jsonb, + attributes jsonb default '{}'::jsonb constraint attributes_not_null check(attributes is not null and attributes != 'null'::jsonb), created_at timestamptz not null default now(), created_by varchar(128) not null, modified_at timestamptz not null default now(), @@ -61,7 +61,7 @@ create table if not exists ips( create table if not exists zones( id serial not null primary key, name varchar not null unique, - attributes jsonb not null default '{}'::jsonb, + attributes jsonb default '{}'::jsonb constraint attributes_not_null check(attributes is not null and attributes != 'null'::jsonb), created_at timestamptz not null default now(), created_by varchar(128) not null, modified_at timestamptz not null default now(), @@ -80,7 +80,7 @@ create table if not exists zoneviews( retry integer not null default 900, expire integer not null default 604800, minimum bigint not null default 86400, - attributes jsonb not null default '{}'::jsonb, + attributes jsonb default '{}'::jsonb constraint attributes_not_null check(attributes is not null and attributes != 'null'::jsonb), created_at timestamptz not null default now(), created_by varchar(128) not null, modified_at timestamptz not null default now(), @@ -94,7 +94,7 @@ create table if not exists records( type varchar(11) not null, ttl integer, value text not null, - attributes jsonb not null default '{}'::jsonb, + attributes jsonb default '{}'::jsonb constraint attributes_not_null check(attributes is not null and attributes != 'null'::jsonb), created_at timestamptz not null default now(), created_by varchar(128) not null, modified_at timestamptz not null default now(), @@ -105,7 +105,7 @@ create table if not exists records( create table if not exists outputgroups( id serial not null primary key, name varchar(128) not null unique, - attributes jsonb not null default '{}'::jsonb, + attributes jsonb default '{}'::jsonb constraint attributes_not_null check(attributes is not null and attributes != 'null'::jsonb), created_at timestamptz not null default now(), created_by varchar(128) not null, modified_at timestamptz not null default now(), @@ -124,7 +124,7 @@ create table if not exists outputs( plugin varchar(20) not null, db_uri varchar(250) not null, status varchar(250) not null, - attributes jsonb not null default '{}'::jsonb, + attributes jsonb default '{}'::jsonb constraint attributes_not_null check(attributes is not null and attributes != 'null'::jsonb), created_at timestamptz not null default now(), created_by varchar(128) not null, modified_at timestamptz not null default now(),