Changeset 507 for trunk


Ignore:
Timestamp:
05/08/13 18:53:23 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Re-re-re-review and tweak the new-database initialization dns.sql script
and the dns-1.0-1.2.sql upgrade script to ensure the resulting structure
is as close as possible to identical to minimize any possible breakage.

Creating a database with the 1.0 SQL init, then applying the 1.0-1.2
upgrade script, will result in pg_dump output with only one difference;
the setval for the sequence on user_id in the users table. Sematically,
there is no difference in the database behaviour (the first new user
created will have ID 2), but the changes make it easier to copy-paste
pg_dump schema fragments if further updates to the default schema are
required.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/dns-1.0-1.2.sql

    r456 r507  
    4040\.
    4141 
    42 SELECT pg_catalog.setval('default_rev_records_record_id_seq', 5, false);
     42SELECT pg_catalog.setval('default_rev_records_record_id_seq', 4, true);
    4343
    4444ALTER TABLE domains ADD COLUMN changed boolean DEFAULT true NOT NULL;
     
    171171\.
    172172
     173-- and readd the primary key
     174ALTER TABLE ONLY rectypes
     175     ADD CONSTRAINT rectypes_pkey PRIMARY KEY (val, name);
     176
    173177-- Update dbversion
    174178UPDATE misc SET value='1.2' WHERE key='dbversion';
  • trunk/dns.sql

    r456 r507  
    7878    default_location character varying (4) DEFAULT '' NOT NULL
    7979);
     80-- ~2x performance boost iff most zones are fed to output from the cache
     81CREATE INDEX dom_status_index ON domains (status);
     82
    8083
    8184CREATE TABLE revzones (
     
    9093    default_location character varying (4) DEFAULT '' NOT NULL
    9194);
     95CREATE INDEX rev_status_index ON revzones USING btree (status);
    9296
    9397CREATE TABLE groups (
     
    109113    log_id serial NOT NULL,
    110114    domain_id integer,
    111     rdns_id integer,
    112115    user_id integer,
    113116    group_id integer,
     
    115118    name character varying(60),
    116119    entry text,
    117     stamp timestamp with time zone DEFAULT now()
     120    stamp timestamp with time zone DEFAULT now(),
     121    rdns_id integer
    118122);
    119123
     
    134138    record_edit boolean DEFAULT false NOT NULL,
    135139    record_delete boolean DEFAULT false NOT NULL,
     140    user_id integer UNIQUE,
     141    group_id integer UNIQUE,
    136142    record_locchg boolean DEFAULT false NOT NULL,
    137143    location_create boolean DEFAULT false NOT NULL,
    138144    location_edit boolean DEFAULT false NOT NULL,
    139145    location_delete boolean DEFAULT false NOT NULL,
    140     location_view boolean DEFAULT false NOT NULL,
    141     user_id integer UNIQUE,
    142     group_id integer UNIQUE
     146    location_view boolean DEFAULT false NOT NULL
    143147);
    144148
    145149-- Need *two* basic permissions;  one for the initial group, one for the default admin user
    146 COPY permissions (permission_id, "admin", self_edit, group_create, group_edit, group_delete, user_create, user_edit, user_delete, domain_create, domain_edit, domain_delete, record_create, record_edit, record_delete, record_locchg, location_create, location_edit, location_delete, location_view, user_id, group_id) FROM stdin;
    147 1       f       f       f       f       f       f       f       f       t       t       t       t       t       t       f       f       f       f       f       \N      1
    148 2       t       f       f       f       f       f       f       f       f       f       f       f       f       f       f       f       f       f       f       1       \N
     150COPY permissions (permission_id, "admin", self_edit, group_create, group_edit, group_delete, user_create, user_edit, user_delete, domain_create, domain_edit, domain_delete, record_create, record_edit, record_delete, user_id, group_id, record_locchg, location_create, location_edit, location_delete, location_view) FROM stdin;
     1511       f       f       f       f       f       f       f       f       t       t       t       t       t       t       \N      1       f       f       f       f       f
     1522       t       f       f       f       f       f       f       f       f       f       f       f       f       f       1       \N      f       f       f       f       f
    149153\.
    150154
     
    152156CREATE TABLE records (
    153157    domain_id integer NOT NULL DEFAULT 0,
    154     rdns_id integer NOT NULL DEFAULT 0,
    155158    record_id serial NOT NULL,
    156159    host text DEFAULT '' NOT NULL,
     
    162165    ttl integer DEFAULT 7200 NOT NULL,
    163166    description text,
     167    rdns_id integer NOT NULL DEFAULT 0,
    164168    location character varying (4) DEFAULT '' NOT NULL
    165169);
     170CREATE INDEX rec_domain_index ON records USING btree (domain_id);
     171CREATE INDEX rec_revzone_index ON records USING btree (rdns_id);
     172CREATE INDEX rec_types_index ON records USING btree ("type");
    166173
    167174CREATE TABLE rectypes (
     
    309316    ADD CONSTRAINT "$1" FOREIGN KEY (group_id) REFERENCES groups(group_id);
    310317
     318ALTER TABLE ONLY default_records
     319    ADD CONSTRAINT "$1" FOREIGN KEY (group_id) REFERENCES groups(group_id);
     320
     321ALTER TABLE ONLY users
     322    ADD CONSTRAINT "$1" FOREIGN KEY (group_id) REFERENCES groups(group_id);
     323
    311324ALTER TABLE ONLY revzones
    312325    ADD CONSTRAINT "$1" FOREIGN KEY (group_id) REFERENCES groups(group_id);
    313326
    314 ALTER TABLE ONLY default_records
    315     ADD CONSTRAINT "$1" FOREIGN KEY (group_id) REFERENCES groups(group_id);
    316 
    317 ALTER TABLE ONLY users
    318     ADD CONSTRAINT "$1" FOREIGN KEY (group_id) REFERENCES groups(group_id);
    319 
    320327ALTER TABLE ONLY groups
    321328    ADD CONSTRAINT group_parent FOREIGN KEY (parent_group_id) REFERENCES groups(group_id);
    322329
    323330-- set starting sequence numbers, since we've inserted data before they're active
    324 SELECT pg_catalog.setval('misc_misc_id_seq', 2, false);
    325 SELECT pg_catalog.setval('default_records_record_id_seq', 8, false);
    326 SELECT pg_catalog.setval('default_rev_records_record_id_seq', 5, false);
    327 SELECT pg_catalog.setval('domains_domain_id_seq', 1, false);
    328 SELECT pg_catalog.setval('groups_group_id_seq', 2, false);
    329 SELECT pg_catalog.setval('permissions_permission_id_seq', 3, false);
    330 SELECT pg_catalog.setval('records_record_id_seq', 1, false);
    331 SELECT pg_catalog.setval('users_user_id_seq', 2, false);
     331-- only set the ones that have data loaded with \copy, and obey the convention
     332-- that comes out of pg_dump
     333SELECT pg_catalog.setval('misc_misc_id_seq', 1, true);
     334SELECT pg_catalog.setval('default_records_record_id_seq', 8, true);
     335SELECT pg_catalog.setval('default_rev_records_record_id_seq', 4, true);
     336SELECT pg_catalog.setval('groups_group_id_seq', 1, true);
     337SELECT pg_catalog.setval('permissions_permission_id_seq', 2, true);
     338SELECT pg_catalog.setval('users_user_id_seq', 1, true);
Note: See TracChangeset for help on using the changeset viewer.