From: Kees Monshouwer Date: Fri, 7 Mar 2014 22:39:04 +0000 (+0100) Subject: database schema change gpgsql backend X-Git-Tag: rec-3.6.0-rc1~75^2~9 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=40ef9665d519ab453e0f871773fb958ef9fc48cb;p=thirdparty%2Fpdns.git database schema change gpgsql backend --- diff --git a/.travis.yml b/.travis.yml index e410838eb9..bef809d3b7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -58,9 +58,9 @@ script: - ./start-test-stop 5300 gmysql-nsec3-both - ./start-test-stop 5300 gmysql-nsec3-optout-both - ./start-test-stop 5300 gmysql-nsec3-narrow -# - ./start-test-stop 5300 gpgsql-nodnssec -# - ./start-test-stop 5300 gpgsql -# - ./start-test-stop 5300 gpgsql-nsec3 + - ./start-test-stop 5300 gpgsql-nodnssec + - ./start-test-stop 5300 gpgsql + - ./start-test-stop 5300 gpgsql-nsec3 # - travis_retry ./start-test-stop 5300 remotebackend-pipe # Workaround for remotebackend failures on travis-ci # - travis_retry ./start-test-stop 5300 remotebackend-pipe-dnssec # - travis_retry ./start-test-stop 5300 remotebackend-unix diff --git a/modules/gpgsqlbackend/Makefile.am b/modules/gpgsqlbackend/Makefile.am index be98d629ba..06bdc354af 100644 --- a/modules/gpgsqlbackend/Makefile.am +++ b/modules/gpgsqlbackend/Makefile.am @@ -2,7 +2,7 @@ AM_CPPFLAGS=-I@PGSQL_incdir@ @THREADFLAGS@ lib_LTLIBRARIES = libgpgsqlbackend.la EXTRA_DIST=OBJECTFILES OBJECTLIBS \ - dnssec.schema.pgsql.sql no-dnssec.schema.pgsql.sql + schema.pgsql.sql nodnssec-3.x_to_3.4_schema.pgsql.sql libgpgsqlbackend_la_SOURCES=gpgsqlbackend.cc gpgsqlbackend.hh \ spgsql.hh spgsql.cc diff --git a/modules/gpgsqlbackend/dnssec.schema.pgsql.sql b/modules/gpgsqlbackend/dnssec.schema.pgsql.sql deleted file mode 100644 index f0dda51447..0000000000 --- a/modules/gpgsqlbackend/dnssec.schema.pgsql.sql +++ /dev/null @@ -1,35 +0,0 @@ -alter table records add ordername VARCHAR(255); -alter table records add auth bool; -create index recordorder on records (domain_id, ordername text_pattern_ops); - -create table domainmetadata ( - id SERIAL PRIMARY KEY, - domain_id INT REFERENCES domains(id) ON DELETE CASCADE, - kind VARCHAR(16), - content TEXT -); - -create index domainidmetaindex on domainmetadata(domain_id); - - -create table cryptokeys ( - id SERIAL PRIMARY KEY, - domain_id INT REFERENCES domains(id) ON DELETE CASCADE, - flags INT NOT NULL, - active BOOL, - content TEXT -); -create index domainidindex on cryptokeys(domain_id); - - -create table tsigkeys ( - id SERIAL PRIMARY KEY, - name VARCHAR(255), - algorithm VARCHAR(50), - secret VARCHAR(255), - constraint c_lowercase_name check (((name)::text = lower((name)::text))) -); - -create unique index namealgoindex on tsigkeys(name, algorithm); - -alter table records alter column type type VARCHAR(10); diff --git a/modules/gpgsqlbackend/gpgsqlbackend.cc b/modules/gpgsqlbackend/gpgsqlbackend.cc index c9667cbffa..eb691796f2 100644 --- a/modules/gpgsqlbackend/gpgsqlbackend.cc +++ b/modules/gpgsqlbackend/gpgsqlbackend.cc @@ -44,10 +44,9 @@ public: declare(suffix,"socket","Pdns backend socket to connect to",""); declare(suffix,"password","Pdns backend password to connect with",""); - declare(suffix,"dnssec","Assume DNSSEC Schema is in place","no"); + declare(suffix,"dnssec","Enable DNSSEC processing","no"); - string record_query = "SELECT content,ttl,prio,type,domain_id,disabled::int,name FROM records WHERE"; - string record_auth_query = "SELECT content,ttl,prio,type,domain_id,disabled::int,name,auth::int FROM records WHERE"; + string record_query = "SELECT content,ttl,prio,type,domain_id,disabled::int,name,auth::int FROM records WHERE"; declare(suffix, "basic-query", "Basic query", record_query+" disabled=false and type='%s' and name=E'%s'"); declare(suffix, "id-query", "Basic with ID query", record_query+" disabled=false and type='%s' and name=E'%s' and domain_id=%d"); @@ -59,29 +58,13 @@ public: declare(suffix, "wildcard-any-query", "Wildcard ANY query", record_query+" disabled=false and name like E'%s'"); declare(suffix, "wildcard-any-id-query", "Wildcard ANY with ID query", record_query+" disabled=false and name like E'%s' and domain_id='%d'"); - declare(suffix, "list-query", "AXFR query", record_query+" (disabled=false OR %d::bool) and domain_id='%d'"); + declare(suffix, "list-query", "AXFR query", record_query+" (disabled=false OR %d::bool) and domain_id='%d' order by name, type"); declare(suffix, "list-subzone-query", "Subzone listing", record_query+" disabled=false and (name=E'%s' OR name like E'%s') and domain_id='%d'"); declare(suffix,"remove-empty-non-terminals-from-zone-query", "remove all empty non-terminals from zone", "delete from records where domain_id='%d' and type is null"); - declare(suffix,"insert-empty-non-terminal-query", "insert empty non-terminal in zone", "insert into records (domain_id,name,type,disabled) values ('%d','%s',null,false)"); + declare(suffix, "insert-empty-non-terminal-query", "insert empty non-terminal in zone", "insert into records (domain_id,name,type,disabled,auth) values ('%d','%s',null,false,true)"); declare(suffix,"delete-empty-non-terminal-query", "delete empty non-terminal from zone", "delete from records where domain_id='%d' and name='%s' and type is null"); - // and now with auth - declare(suffix, "basic-query-auth", "Basic query", record_auth_query+" disabled=false and type='%s' and name=E'%s'"); - declare(suffix, "id-query-auth", "Basic with ID query", record_auth_query+" disabled=false and type='%s' and name=E'%s' and domain_id=%d"); - declare(suffix, "wildcard-query-auth", "Wildcard query", record_auth_query+" disabled=false and type='%s' and name like E'%s'"); - declare(suffix, "wildcard-id-query-auth", "Wildcard with ID query", record_auth_query+" disabled=false and type='%s' and name like E'%s' and domain_id='%d'"); - - declare(suffix, "any-query-auth", "Any query", record_auth_query+" disabled=false and name=E'%s'"); - declare(suffix, "any-id-query-auth", "Any with ID query", record_auth_query+" disabled=false and name=E'%s' and domain_id=%d"); - declare(suffix, "wildcard-any-query-auth", "Wildcard ANY query", record_auth_query+" disabled=false and name like E'%s'"); - declare(suffix, "wildcard-any-id-query-auth", "Wildcard ANY with ID query", record_auth_query+" disabled=false and name like E'%s' and domain_id='%d'"); - - declare(suffix, "list-query-auth", "AXFR query", record_auth_query+" (disabled=false OR %d::bool) and domain_id='%d' order by name, type"); - declare(suffix, "list-subzone-query-auth", "Subzone listing", record_auth_query+" disabled=false and (name=E'%s' OR name like E'%s') and domain_id='%d'"); - - declare(suffix, "insert-empty-non-terminal-query-auth", "insert empty non-terminal in zone", "insert into records (domain_id,name,type,disabled,auth) values ('%d','%s',null,false,true)"); - declare(suffix,"master-zone-query","Data", "select master from domains where name=E'%s' and type='SLAVE'"); declare(suffix,"info-zone-query","","select id,name,master,last_check,notified_serial,type from domains where name=E'%s'"); @@ -89,15 +72,14 @@ public: declare(suffix,"info-all-slaves-query","","select id,name,master,last_check,type from domains where type='SLAVE'"); declare(suffix,"supermaster-query","", "select account from supermasters where ip='%s' and nameserver=E'%s'"); declare(suffix,"supermaster-name-to-ips", "", "select ip from supermasters where nameserver=E'%s'"); + declare(suffix,"insert-zone-query","", "insert into domains (type,name) values('NATIVE',E'%s')"); declare(suffix,"insert-slave-query","", "insert into domains (type,name,master,account) values('SLAVE',E'%s',E'%s',E'%s')"); - declare(suffix, "insert-record-query", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name) values (E'%s',%d,%d,'%s',%d,%d::bool,E'%s')"); - declare(suffix, "insert-record-query-auth", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name,auth) values (E'%s',%d,%d,'%s',%d,%d::bool,E'%s','%d')"); - declare(suffix, "insert-record-order-query-auth", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name,ordername,auth) values (E'%s',%d,%d,'%s',%d,%d::bool,E'%s',E'%s','%d')"); - declare(suffix, "insert-ent-query", "insert empty non-terminal in zone", "insert into records (type,domain_id,disabled,name) values (null,'%d',false,E'%s')"); - declare(suffix, "insert-ent-query-auth", "insert empty non-terminal in zone", "insert into records (type,domain_id,disabled,name,auth) values (null,'%d',false,E'%s','%d')"); - declare(suffix, "insert-ent-order-query-auth", "insert empty non-terminal in zone", "insert into records (type,domain_id,disabled,name,ordername,auth) values (null,'%d',false,E'%s',E'%s','%d')"); + declare(suffix, "insert-record-query", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name,auth) values (E'%s',%d,%d,'%s',%d,%d::bool,E'%s','%d')"); + declare(suffix, "insert-record-order-query", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name,ordername,auth) values (E'%s',%d,%d,'%s',%d,%d::bool,E'%s',E'%s','%d')"); + declare(suffix, "insert-ent-query", "insert empty non-terminal in zone", "insert into records (type,domain_id,disabled,name,auth) values (null,'%d',false,E'%s','%d')"); + declare(suffix, "insert-ent-order-query", "insert empty non-terminal in zone", "insert into records (type,domain_id,disabled,name,ordername,auth) values (null,'%d',false,E'%s',E'%s','%d')"); declare(suffix, "get-order-first-query", "DNSSEC Ordering Query, last", "select ordername, name from records where disabled=false and domain_id=%d and ordername is not null order by 1 using ~<~ limit 1"); declare(suffix, "get-order-before-query", "DNSSEC Ordering Query, before", "select ordername, name from records where disabled=false and ordername ~<=~ E'%s' and domain_id=%d and ordername is not null order by 1 using ~>~ limit 1"); diff --git a/modules/gpgsqlbackend/no-dnssec.schema.pgsql.sql b/modules/gpgsqlbackend/no-dnssec.schema.pgsql.sql deleted file mode 100644 index e41e363492..0000000000 --- a/modules/gpgsqlbackend/no-dnssec.schema.pgsql.sql +++ /dev/null @@ -1,55 +0,0 @@ -create table domains ( - id SERIAL PRIMARY KEY, - name VARCHAR(255) NOT NULL, - master VARCHAR(128) DEFAULT NULL, - last_check INT DEFAULT NULL, - type VARCHAR(6) NOT NULL, - notified_serial INT DEFAULT NULL, - account VARCHAR(40) DEFAULT NULL, - CONSTRAINT c_lowercase_name CHECK (((name)::text = lower((name)::text))) -); -CREATE UNIQUE INDEX name_index ON domains(name); - -CREATE TABLE records ( - id SERIAL PRIMARY KEY, - domain_id INT DEFAULT NULL, - name VARCHAR(255) DEFAULT NULL, - type VARCHAR(10) DEFAULT NULL, - content VARCHAR(65535) DEFAULT NULL, - ttl INT DEFAULT NULL, - prio INT DEFAULT NULL, - change_date INT DEFAULT NULL, - disabled BOOL DEFAULT 'f', - CONSTRAINT domain_exists - FOREIGN KEY(domain_id) REFERENCES domains(id) - ON DELETE CASCADE, - CONSTRAINT c_lowercase_name CHECK (((name)::text = lower((name)::text))) -); - -CREATE INDEX rec_name_index ON records(name); -CREATE INDEX nametype_index ON records(name,type); -CREATE INDEX domain_id ON records(domain_id); - -create table supermasters ( - ip INET NOT NULL, - nameserver VARCHAR(255) NOT NULL, - account VARCHAR(40) DEFAULT NULL, - PRIMARY KEY (ip, nameserver) -); - -CREATE TABLE comments ( - id SERIAL PRIMARY KEY, - domain_id INT NOT NULL, - name VARCHAR(255) NOT NULL, - type VARCHAR(10) NOT NULL, - modified_at INT NOT NULL, - account VARCHAR(40) DEFAULT NULL, - comment VARCHAR(65535) NOT NULL, - CONSTRAINT domain_exists - FOREIGN KEY(domain_id) REFERENCES domains(id) - ON DELETE CASCADE, - CONSTRAINT c_lowercase_name CHECK (((name)::text = lower((name)::text))) -); -CREATE INDEX comments_domain_id_idx ON comments (domain_id); -CREATE INDEX comments_name_type_idx ON comments (name, type); -CREATE INDEX comments_order_idx ON comments (domain_id, modified_at); diff --git a/modules/gpgsqlbackend/nodnssec-3.x_to_3.4_schema.pgsql.sql b/modules/gpgsqlbackend/nodnssec-3.x_to_3.4_schema.pgsql.sql new file mode 100644 index 0000000000..1467150c07 --- /dev/null +++ b/modules/gpgsqlbackend/nodnssec-3.x_to_3.4_schema.pgsql.sql @@ -0,0 +1,61 @@ +ALTER table records ADD disabled BOOL DEFAULT 'f'; +ALTER table records ADD ordername VARCHAR(255); +ALTER table records ADD auth bool BOOL DEFAULT 't'; +ALTER table records ALTER COLUMN type TYPE VARCHAR(10); + +CREATE INDEX recordorder ON records (domain_id, ordername text_pattern_ops); + + + +CREATE TABLE domainmetadata ( + id SERIAL PRIMARY KEY, + domain_id INT REFERENCES domains(id) ON DELETE CASCADE, + kind VARCHAR(16), + content TEXT +); + +CREATE INDEX domainidmetaindex ON domainmetadata(domain_id); + + + +CREATE TABLE cryptokeys ( + id SERIAL PRIMARY KEY, + domain_id INT REFERENCES domains(id) ON DELETE CASCADE, + flags INT NOT NULL, + active BOOL, + content TEXT +); + +CREATE INDEX domainidindex ON cryptokeys(domain_id); + + + +CREATE TABLE tsigkeys ( + id SERIAL PRIMARY KEY, + name VARCHAR(255), + algorithm VARCHAR(50), + secret VARCHAR(255), + constraint c_lowercase_name CHECK (((name)::TEXT = LOWER((name)::TEXT))) +); + +CREATE UNIQUE INDEX namealgoindex ON tsigkeys(name, algorithm); + + + +CREATE TABLE comments ( + id SERIAL PRIMARY KEY, + domain_id INT NOT NULL, + name VARCHAR(255) NOT NULL, + type VARCHAR(10) NOT NULL, + modified_at INT NOT NULL, + account VARCHAR(40) DEFAULT NULL, + comment VARCHAR(65535) NOT NULL, + CONSTRAINT domain_exists + FOREIGN KEY(domain_id) REFERENCES domains(id) + ON DELETE CASCADE, + CONSTRAINT c_lowercase_name CHECK (((name)::TEXT = LOWER((name)::TEXT))) +); + +CREATE INDEX comments_domain_id_idx ON comments (domain_id); +CREATE INDEX comments_name_type_idx ON comments (name, type); +CREATE INDEX comments_order_idx ON comments (domain_id, modified_at); diff --git a/modules/gpgsqlbackend/schema.pgsql.sql b/modules/gpgsqlbackend/schema.pgsql.sql new file mode 100644 index 0000000000..eecc63e63e --- /dev/null +++ b/modules/gpgsqlbackend/schema.pgsql.sql @@ -0,0 +1,100 @@ +CREATE TABLE domains ( + id SERIAL PRIMARY KEY, + name VARCHAR(255) NOT NULL, + master VARCHAR(128) DEFAULT NULL, + last_check INT DEFAULT NULL, + type VARCHAR(10) NOT NULL, + notified_serial INT DEFAULT NULL, + account VARCHAR(40) DEFAULT NULL, + CONSTRAINT c_lowercase_name CHECK (((name)::TEXT = LOWER((name)::TEXT))) +); + +CREATE UNIQUE INDEX name_index ON domains(name); + + +CREATE TABLE records ( + id SERIAL PRIMARY KEY, + domain_id INT DEFAULT NULL, + name VARCHAR(255) DEFAULT NULL, + type VARCHAR(10) DEFAULT NULL, + content VARCHAR(65535) DEFAULT NULL, + ttl INT DEFAULT NULL, + prio INT DEFAULT NULL, + change_date INT DEFAULT NULL, + disabled BOOL DEFAULT 'f', + ordername VARCHAR(255), + auth BOOL DEFAULT 't', + CONSTRAINT domain_exists + FOREIGN KEY(domain_id) REFERENCES domains(id) + ON DELETE CASCADE, + CONSTRAINT c_lowercase_name CHECK (((name)::TEXT = LOWER((name)::TEXT))) +); + +CREATE INDEX rec_name_index ON records(name); +CREATE INDEX nametype_index ON records(name,type); +CREATE INDEX domain_id ON records(domain_id); +CREATE INDEX recordorder ON records (domain_id, ordername text_pattern_ops); + + + +CREATE TABLE supermasters ( + ip INET NOT NULL, + nameserver VARCHAR(255) NOT NULL, + account VARCHAR(40) DEFAULT NULL, + PRIMARY KEY(ip, nameserver) +); + + + +CREATE TABLE comments ( + id SERIAL PRIMARY KEY, + domain_id INT NOT NULL, + name VARCHAR(255) NOT NULL, + type VARCHAR(10) NOT NULL, + modified_at INT NOT NULL, + account VARCHAR(40) DEFAULT NULL, + comment VARCHAR(65535) NOT NULL, + CONSTRAINT domain_exists + FOREIGN KEY(domain_id) REFERENCES domains(id) + ON DELETE CASCADE, + CONSTRAINT c_lowercase_name CHECK (((name)::TEXT = LOWER((name)::TEXT))) +); + +CREATE INDEX comments_domain_id_idx ON comments (domain_id); +CREATE INDEX comments_name_type_idx ON comments (name, type); +CREATE INDEX comments_order_idx ON comments (domain_id, modified_at); + + + +CREATE TABLE domainmetadata ( + id SERIAL PRIMARY KEY, + domain_id INT REFERENCES domains(id) ON DELETE CASCADE, + kind VARCHAR(16), + content TEXT +); + +CREATE INDEX domainidmetaindex ON domainmetadata(domain_id); + + + +CREATE TABLE cryptokeys ( + id SERIAL PRIMARY KEY, + domain_id INT REFERENCES domains(id) ON DELETE CASCADE, + flags INT NOT NULL, + active BOOL, + content TEXT +); + +CREATE INDEX domainidindex ON cryptokeys(domain_id); + + + +CREATE TABLE tsigkeys ( + id SERIAL PRIMARY KEY, + name VARCHAR(255), + algorithm VARCHAR(50), + secret VARCHAR(255), + CONSTRAINT c_lowercase_name CHECK (((name)::TEXT = LOWER((name)::TEXT))) +); + +CREATE UNIQUE INDEX namealgoindex ON tsigkeys(name, algorithm); diff --git a/regression-tests/backends/gpgsql-master b/regression-tests/backends/gpgsql-master index 934249642a..23231af541 100644 --- a/regression-tests/backends/gpgsql-master +++ b/regression-tests/backends/gpgsql-master @@ -5,7 +5,7 @@ case $context in dropdb --user="$GPGSQLUSER" "$GPGSQLDB" || echo ignoring mysqladmin drop failure createdb --user="$GPGSQLUSER" "$GPGSQLDB" || echo ignoring mysqladmin drop failure - psql --user="$GPGSQLUSER" "$GPGSQLDB" < ../modules/gpgsqlbackend/no-dnssec.schema.pgsql.sql + psql --user="$GPGSQLUSER" "$GPGSQLDB" < ../modules/gpgsqlbackend/schema.pgsql.sql tosql gpgsql | psql --user="$GPGSQLUSER" "$GPGSQLDB" 2>&1 | uniq -c @@ -20,6 +20,9 @@ __EOF__ ../pdns/pdnssec --config-dir=. --config-name=gpgsql rectify-zone $zone 2>&1 done + ../pdns/pdnssec --config-dir=. --config-name=gpgsql import-tsig-key test $ALGORITHM $KEY + ../pdns/pdnssec --config-dir=. --config-name=gpgsql activate-tsig-key tsig.com test master + $RUNWRAPPER $PDNS --daemon=no --local-port=$port --socket-dir=./ \ --no-shuffle --launch=gpgsql \ --send-root-referral \ @@ -37,8 +40,7 @@ __EOF__ dropdb --user="$GPGSQLUSER" "$GPGSQLDB" || echo ignoring dropdb failure createdb --user="$GPGSQLUSER" "$GPGSQLDB" || echo ignoring createdb failure # FIXME - psql --user="$GPGSQLUSER" "$GPGSQLDB" < ../modules/gpgsqlbackend/no-dnssec.schema.pgsql.sql - psql --user="$GPGSQLUSER" "$GPGSQLDB" < ../modules/gpgsqlbackend/dnssec.schema.pgsql.sql + psql --user="$GPGSQLUSER" "$GPGSQLDB" < ../modules/gpgsqlbackend/schema.pgsql.sql tosql gpgsql | psql --user="$GPGSQLUSER" "$GPGSQLDB" 2>&1 | uniq -c