Commit a1039801 authored by Michael Casadevall's avatar Michael Casadevall

Added update system for the database, and the first update script

Signed-off-by: 's avatarMichael Casadevall <sonicmctails@gmail.com>
parent ef849a0e
......@@ -7,6 +7,15 @@
* dak/process_unchecked.py - Added new REJECT for DM-Upload-Allowed not being set
and clarified NMU reject message.
* dak/update_db.py - Added a update-database mechanism. New database updates
can be added by simply adding a simple upgrade script to dakdb
It probably has some bugs, but it can update git HEAD 12-08-2008
to DB revision 1 without any issues.
* dak/dakdb/1.py - Adds DM tables
* dak/import_keyring - Fixed an argument typo on the help screen
2008-12-28 Frank Lichtenheld <djpig@debian.org>
* dak/override.py (main): Handle source-only packages better
......
......@@ -144,6 +144,8 @@ def init():
"Sync PostgreSQL users with passwd file"),
("init-db",
"Update the database to match the conf file"),
("update-db",
"Updates databae schema to latest revision"),
("init-dirs",
"Initial setup of the archive"),
("make-maintainers",
......
#!/usr/bin/env python
# Debian Archive Kit Database Update Script
# Copyright (C) 2008 Michael Casadevall <mcasadevall@debian.org>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
################################################################################
# <tomv_w> really, if we want to screw ourselves, let's find a better way.
# <Ganneff> rm -rf /srv/ftp.debian.org
################################################################################
import psycopg2
################################################################################
def do_update(self):
print "Adding DM fields to database"
try:
c = self.db.cursor()
c.execute("ALTER TABLE source ADD COLUMN dm_upload_allowed BOOLEAN DEFAULT 'no' NOT NULL;")
c.execute("ALTER TABLE uid ADD COLUMN debian_maintainer BOOLEAN DEFAULT 'false' NOT NULL;")
print "Migrating DM data to source table. This might take some time ..."
c.execute("UPDATE source SET dm_upload_allowed = 't' WHERE id = (SELECT source FROM src_uploaders);")
c.execute("UPDATE config SET value = '1' WHERE name = 'db_revision'")
self.db.commit()
print "REMINDER: Remember to run the updated byhand-dm crontab to update Debian Maintainer information"
except psycopg2.ProgrammingError, msg:
self.db.rollback()
print "FATAL: Unable to apply DM table update 1!"
print "Error Message: " + str(msg)
print "Database changes have been rolled back."
......@@ -173,7 +173,7 @@ def usage (exit_code=0):
-h, --help show this help and exit.
-L, --import-ldap-users generate uid entries for keyring from LDAP
-U, --generate-users FMT generate uid entries from keyring as FMT"""
-d, --debian-maintainer mark generated uids as debian-maintainers
-D, --debian-maintainer mark generated uids as debian-maintainers
sys.exit(exit_code)
......
#!/usr/bin/env python
# Debian Archive Kit Database Update Script
# Copyright (C) 2008 Michael Casadevall <mcasadevall@debian.org>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
################################################################################
# <Ganneff> when do you have it written?
# <NCommander> Ganneff, after you make my debian account
# <Ganneff> blackmail wont work
# <NCommander> damn it
################################################################################
import psycopg2, sys
import apt_pkg
import time
from daklib import database
from daklib import utils
################################################################################
Cnf = None
projectB = None
required_database_schema = 1
################################################################################
class UpdateDB:
def usage (self, exit_code=0):
print """Usage: dak update-db
Updates dak's database schema to the lastest version. You should disable crontabs while this is running
-h, --help show this help and exit."""
sys.exit(exit_code)
################################################################################
def update_db_to_zero(self):
# This function will attempt to update a pre-zero database schema to zero
# First, do the sure thing, and create the configuration table
try:
print "Creating configuration table ..."
c = self.db.cursor()
c.execute("""CREATE TABLE config (
id SERIAL PRIMARY KEY NOT NULL,
name TEXT UNIQUE NOT NULL,
value TEXT
);""")
c.execute("INSERT INTO config VALUES ( nextval('config_id_seq'), 'db_revision', '0')");
self.db.commit()
except psycopg2.ProgrammingError:
self.db.rollback()
print "Failed to create configuration table."
print "Can the projectB user CREATE TABLE?"
print ""
print "Aborting update."
sys.exit(-255)
################################################################################
def get_db_rev(self):
global projectB
# We keep database revision info the config table
# Try and access it
try:
c = self.db.cursor()
q = c.execute("SELECT value FROM config WHERE name = 'db_revision';");
return c.fetchone()[0]
except psycopg2.ProgrammingError:
# Whoops .. no config table ...
self.db.rollback()
print "No configuration table found, assuming dak database revision to be pre-zero"
return -1
################################################################################
def update_db(self):
# Ok, try and find the configuration table
print "Determining dak database revision ..."
try:
self.db = psycopg2.connect("dbname='" + Cnf["DB::Name"] + "' host='" + Cnf["DB::Host"] + "' port='" + str(Cnf["DB::Port"]) + "'")
except:
print "FATAL: Failed connect to database"
pass
database_revision = int(self.get_db_rev())
if database_revision == -1:
print "dak database schema predates update-db."
print ""
print "This script will attempt to upgrade it to the lastest, but may fail."
print "Please make sure you have a database backup handy. If you don't, press Ctrl-C now!"
print ""
print "Continuing in five seconds ..."
#time.sleep(5)
print ""
print "Attempting to upgrade pre-zero database to zero"
self.update_db_to_zero()
database_revision = 0
print "dak database schema at " + str(database_revision)
print "dak version requires schema " + str(required_database_schema)
if database_revision == required_database_schema:
print "no updates required"
sys.exit(0)
for i in range (database_revision, required_database_schema):
print "updating databse schema from " + str(database_revision) + " to " + str(i+1)
dakdb = __import__("dakdb", globals(), locals(), ['update'+str(i+1)])
update_module = getattr(dakdb, "update"+str(i+1))
update_module.do_update(self)
database_revision /+ 1
################################################################################
def init (self):
global Cnf, projectB
Cnf = utils.get_conf()
arguments = [('h', "help", "Update-DB::Options::Help")]
for i in [ "help" ]:
if not Cnf.has_key("Update-DB::Options::%s" % (i)):
Cnf["Update-DB::Options::%s" % (i)] = ""
arguments = apt_pkg.ParseCommandLine(Cnf, arguments, sys.argv)
options = Cnf.SubTree("Update-DB::Options")
if options["Help"]:
usage()
elif arguments:
utils.warn("dak update-db takes no arguments.")
usage(exit_code=1)
self.update_db()
################################################################################
if __name__ == '__main__':
app = UpdateDB()
app.init()
def main():
app = UpdateDB()
app.init()
......@@ -38,7 +38,6 @@ CREATE TABLE uid (
id SERIAL PRIMARY KEY,
uid TEXT UNIQUE NOT NULL,
name TEXT
debian_maintainer BOOLEAN NOT NULL,
);
CREATE TABLE keyrings (
......@@ -85,7 +84,6 @@ CREATE TABLE source (
file INT4 UNIQUE NOT NULL, -- REFERENCES files
install_date TIMESTAMP NOT NULL,
sig_fpr INT4 NOT NULL, -- REFERENCES fingerprint
dm-upload-allowed BOOLEAN NOT NULL,
unique (source, version)
);
......
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