Changeset 212 for trunk


Ignore:
Timestamp:
12/21/11 17:49:46 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Begin setting up the barest sketch of what will eventually become
a complete automagical DB init/upgrade feature. See #34.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r209 r212  
    262262    or return (undef, $DBI::errstr) if(!$dbh);
    263263
    264 # Return here if we can't select.  Note that this indicates a
    265 # problem executing the select.
    266   my $sth = $dbh->prepare("select group_id from groups limit 1");
     264##fixme:  initialize the DB if we can't find the table (since, by definition, there's
     265# nothing there if we can't select from it...)
     266  my $tblsth = $dbh->prepare("SELECT count(*) FROM pg_catalog.pg_class WHERE relkind='r' AND relname=?");
     267  my ($tblcount) = $dbh->selectrow_array($tblsth, undef, ('misc'));
     268  return (undef,$DBI::errstr) if $dbh->err;
     269
     270#if ($tblcount == 0) {
     271#  # create tables one at a time, checking for each.
     272#  return (undef, "check table misc missing");
     273#}
     274
     275
     276# Return here if we can't select.
     277# This should retrieve the dbversion key.
     278  my $sth = $dbh->prepare("SELECT key,value FROM misc WHERE misc_id=1");
    267279  $sth->execute();
    268280  return (undef,$DBI::errstr) if ($sth->err);
     281
     282##fixme:  do stuff to the DB on version mismatch
     283# x.y series should upgrade on $DNSDB::VERSION > misc(key=>version)
     284# DB should be downward-compatible;  column defaults should give sane (if possibly
     285# useless-and-needs-help) values in columns an older software stack doesn't know about.
    269286
    270287# See if the select returned anything (or null data).  This should
  • trunk/dns.sql

    r206 r212  
    55-- CREATE DATABASE dnsdb OWNED BY dnsdb;
    66-- SET SESSION AUTHORIZATION 'dnsdb';
     7
     8-- need a handy place to put eg a DB version identifier - useful for auto-upgrading a DB
     9CREATE TABLE misc (
     10        misc_id serial NOT NULL,
     11        key text DEFAULT '' NOT NULL,
     12        value test DEFAULT '' NOT NULL
     13);
     14
     15COPY misc (misc_id, key, value) FROM stdin;
     161       dbversion       1.0
     17\.
    718
    819CREATE TABLE default_records (
     
    253264
    254265-- set starting sequence numbers, since we've inserted data before they're active
     266SELECT pg_catalog.setval('misc_misc_id_seq', 1, true);
    255267SELECT pg_catalog.setval('default_records_record_id_seq', 8, true);
    256268SELECT pg_catalog.setval('domains_domain_id_seq', 1, false);
Note: See TracChangeset for help on using the changeset viewer.