module DDNS.DBInfo ( dbinfo , indexDeclarations ) where import Database.HaskellDB.DBSpec import qualified Database.HaskellDB.DBSpec.PPHelpers as PP dbinfo :: DBInfo dbinfo = DBInfo { dbname = "BlackboardDNS" , opts = DBOptions { useBString = False , makeIdent = PP.mkIdentPreserving } , tbls = [ zones , records ] } zones :: TInfo zones = TInfo { tname = "zones" , cols = [ CInfo "zone" (StringT, False) , CInfo "ns" (StringT, False) , CInfo "owner" (StringT, False) , CInfo "serial" (IntT , False) , CInfo "refresh" (IntT , False) , CInfo "retry" (IntT , False) , CInfo "expire" (IntT , False) , CInfo "minTTL" (IntT , False) ] } records :: TInfo records = TInfo { tname = "records" , cols = [ CInfo "name" (StringT, False) , CInfo "zone" (StringT, False) , CInfo "recType" (StringT, False) , CInfo "recData" (StringT, False) ] } -- This kind of dirty hack should go away someday. indexDeclarations :: [String] indexDeclarations = [ "CREATE UNIQUE INDEX pkey_on_zones ON zones ( zone )" , "CREATE INDEX pkey_on_records ON records ( name, zone )" , "CREATE TRIGGER insert_into_records\n" ++ " BEFORE INSERT ON records\n" ++ " FOR EACH ROW\n" ++ " WHEN\n" ++ " NOT EXISTS (\n" ++ " SELECT 1\n" ++ " FROM zones\n" ++ " WHERE zone = NEW.zone\n" ++ " )\n" ++ " BEGIN\n" ++ " SELECT RAISE(ABORT, \"FK constraint failure\");\n" ++ " END" , "CREATE TRIGGER change_record_zone\n" ++ " BEFORE UPDATE OF zone ON records\n" ++ " FOR EACH ROW\n" ++ " WHEN\n" ++ " NOT EXISTS (\n" ++ " SELECT 1\n" ++ " FROM zones\n" ++ " WHERE zone = NEW.zone\n" ++ " )\n" ++ " BEGIN\n" ++ " SELECT RAISE(ABORT, \"FK constraint failure\");\n" ++ " END" , "CREATE TRIGGER update_zone_name\n" ++ " AFTER UPDATE OF zone ON zones\n" ++ " FOR EACH ROW\n" ++ " BEGIN\n" ++ " UPDATE records\n" ++ " SET zone = NEW.zone\n" ++ " WHERE zone = OLD.zone;\n" ++ " END" , "CREATE TRIGGER delete_zone\n" ++ " AFTER DELETE ON zones\n" ++ " FOR EACH ROW\n" ++ " BEGIN\n" ++ " DELETE\n" ++ " FROM records\n" ++ " WHERE zone = OLD.zone;\n" ++ " END" ]