Author: poeml Date: Sun Apr 1 01:49:09 2012 New Revision: 8267 URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=8267&view=rev Log: mb: - add ipv6_only, a new flag, to the server table. Not used yet. - implement a way to migrate the database when needed, after updates. A table "version" keeps info about the state of the database. For now, we do only one migration (2.17.0) so we don't actually check for versions yet.
Modified: trunk/mb/mb/conn.py trunk/sql/initialdata-postgresql.sql trunk/sql/schema-postgresql.sql Modified: trunk/mb/mb/conn.py URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mb/mb/conn.py?rev=8267&r1=8266&r2=8267&view=diff ============================================================================== --- trunk/mb/mb/conn.py (original) +++ trunk/mb/mb/conn.py Sun Apr 1 01:49:09 2012 @@ -20,6 +20,7 @@ countryOnly : %(countryOnly)s asOnly : %(asOnly)s prefixOnly : %(prefixOnly)s +ipv6Only : %(ipv6Only)s otherCountries : %(otherCountries)s fileMaxsize : %(fileMaxsize)s publicNotes : %(publicNotes)s @@ -73,6 +74,7 @@ countryOnly = s.countryOnly, asOnly = s.asOnly, prefixOnly = s.prefixOnly, + ipv6Only = s.ipv6Only, otherCountries = s.otherCountries, fileMaxsize = s.fileMaxsize, score = s.score, @@ -120,6 +122,32 @@ config['dbname']) sqlhub.processConnection = connectionForURI(self.uri) + + + + # upgrade things in the database, if needed + try: + class Version(SQLObject): + """version of the database schema""" + class sqlmeta: + fromDatabase = True + except psycopg2.ProgrammingError: + print 'Your database needs to be upgraded (2.17.0)...' + + query = """CREATE TABLE version ( + "component" text NOT NULL PRIMARY KEY, + "major" INTEGER NOT NULL, + "minor" INTEGER NOT NULL, + "patchlevel" INTEGER NOT NULL ); + INSERT INTO version VALUES ('mirrorbrain', 2, 17, 0); + """ + SQLObject._connection.query(query) + + # the following modification comes with 2.17.0 + print "migrating server table by adding ipv6_only column" + query = "ALTER TABLE server ADD COLUMN ipv6_only boolean NOT NULL default 'f';" + SQLObject._connection.query(query) + class Server(SQLObject): """the server table""" Modified: trunk/sql/initialdata-postgresql.sql URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/sql/initialdata-postgresql.sql?rev=8267&r1=8266&r2=8267&view=diff ============================================================================== --- trunk/sql/initialdata-postgresql.sql (original) +++ trunk/sql/initialdata-postgresql.sql Sun Apr 1 01:49:09 2012 @@ -1,3 +1,5 @@ +INSERT INTO version VALUES ('mirrorbrain', 2, 17, 0); + INSERT INTO region VALUES (1,'af','Africa'),(2,'as','Asia'),(3,'eu','Europe'),(4,'na','North America'),(5,'sa','South America'),(6,'oc','Oceania'); Modified: trunk/sql/schema-postgresql.sql URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/sql/schema-postgresql.sql?rev=8267&r1=8266&r2=8267&view=diff ============================================================================== --- trunk/sql/schema-postgresql.sql (original) +++ trunk/sql/schema-postgresql.sql Sun Apr 1 01:49:09 2012 @@ -10,6 +10,16 @@ -- -------------------------------------------------------- BEGIN; +-- -------------------------------------------------------- + + +CREATE TABLE "version" ( + "component" text NOT NULL PRIMARY KEY, + "major" INTEGER NOT NULL, + "minor" INTEGER NOT NULL, + "patchlevel" INTEGER NOT NULL +); + -- -------------------------------------------------------- _______________________________________________ mirrorbrain-commits mailing list Archive: http://mirrorbrain.org/archive/mirrorbrain-commits/ Note: To remove yourself from this list, send a mail with the content unsubscribe to the address mirrorbrain-commits-requ...@mirrorbrain.org