Commit f284e186 authored by Mukund Sivaraman's avatar Mukund Sivaraman
Browse files

[1899] Add a unique constraint to nsec3 table

This is to check that only one NSEC3 RR exists per owner name in a
zone.  The code to fix #1899 would depend on this assertion.
parent e5bf564f
......@@ -193,10 +193,19 @@ UPGRADES = [
"ALTER TABLE schema_version " +
"ADD COLUMN minor INTEGER NOT NULL DEFAULT 0"
]
},
{'from': (2, 0), 'to': (2, 1),
'statements': [
# Enforce that only one NSEC3 RR exists for an owner name in
# the zone.
"CREATE UNIQUE INDEX nsec3_by_zoneid_and_owner ON nsec3 " +
"(zone_id, owner)"
]
}
# To extend this, leave the above statements in place and add another
# dictionary to the list. The "from" version should be (2, 0), the "to"
# dictionary to the list. The "from" version should be (2, 1), the "to"
# version whatever the version the update is to, and the SQL statements are
# the statements required to perform the upgrade. This way, the upgrade
# program will be able to upgrade both a V1.0 and a V2.0 database.
......
......@@ -165,7 +165,7 @@ upgrade_ok_test() {
if [ $? -eq 0 ]
then
# Compare schema with the reference
get_schema $testdata/v2_0.sqlite3
get_schema $testdata/v2_1.sqlite3
expected_schema=$db_schema
get_schema $tempfile
actual_schema=$db_schema
......@@ -177,7 +177,7 @@ upgrade_ok_test() {
fi
# Check the version is set correctly
check_version $tempfile "V2.0"
check_version $tempfile "V2.1"
# Check that a backup was made
check_backup $1 $2
......@@ -449,7 +449,7 @@ copy_file $testdata/old_v1.sqlite3 $tempfile
Yes
.
passzero $?
check_version $tempfile "V2.0"
check_version $tempfile "V2.1"
rm -f $tempfile $backupfile
echo "13.4 Interactive prompt - no"
......
......@@ -10,3 +10,4 @@ EXTRA_DIST += old_v1.sqlite3
EXTRA_DIST += README
EXTRA_DIST += too_many_version.sqlite3
EXTRA_DIST += v2_0.sqlite3
EXTRA_DIST += v2_1.sqlite3
......@@ -42,7 +42,7 @@ namespace {
// program may not be taking advantage of features (possibly performance
// improvements) added to the database.
const int SQLITE_SCHEMA_MAJOR_VERSION = 2;
const int SQLITE_SCHEMA_MINOR_VERSION = 0;
const int SQLITE_SCHEMA_MINOR_VERSION = 1;
}
namespace isc {
......@@ -325,7 +325,7 @@ public:
const char* const SCHEMA_LIST[] = {
"CREATE TABLE schema_version (version INTEGER NOT NULL, "
"minor INTEGER NOT NULL DEFAULT 0)",
"INSERT INTO schema_version VALUES (2, 0)",
"INSERT INTO schema_version VALUES (2, 1)",
"CREATE TABLE zones (id INTEGER PRIMARY KEY, "
"name TEXT NOT NULL COLLATE NOCASE, "
"rdclass TEXT NOT NULL COLLATE NOCASE DEFAULT 'IN', "
......@@ -351,6 +351,8 @@ const char* const SCHEMA_LIST[] = {
"ttl INTEGER NOT NULL, rdtype TEXT NOT NULL COLLATE NOCASE, "
"rdata TEXT NOT NULL)",
"CREATE INDEX nsec3_byhash ON nsec3 (hash)",
// Enforce that only one NSEC3 RR exists for an owner name in the zone.
"CREATE UNIQUE INDEX nsec3_by_zoneid_and_owner ON nsec3 (zone_id, owner)",
"CREATE TABLE diffs (id INTEGER PRIMARY KEY, "
"zone_id INTEGER NOT NULL, "
"version INTEGER NOT NULL, "
......
......@@ -25,7 +25,7 @@ RR_RDATA_INDEX = 7
# Current major and minor versions of schema
SCHEMA_MAJOR_VERSION = 2
SCHEMA_MINOR_VERSION = 0
SCHEMA_MINOR_VERSION = 1
class Sqlite3DSError(Exception):
""" Define exceptions."""
......@@ -81,6 +81,9 @@ def create(cur):
rdtype TEXT NOT NULL COLLATE NOCASE,
rdata TEXT NOT NULL)""")
cur.execute("CREATE INDEX nsec3_byhash ON nsec3 (hash)")
# Enforce that only one NSEC3 RR exists for an owner name in the zone.
cur.execute("""CREATE UNIQUE INDEX nsec3_by_zoneid_and_owner ON nsec3
(zone_id, owner)""");
cur.execute("""CREATE TABLE diffs (id INTEGER PRIMARY KEY,
zone_id INTEGER NOT NULL,
version INTEGER NOT NULL,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment