public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/cache/
Date: Sun, 10 Jun 2012 08:35:00 +0000 (UTC)	[thread overview]
Message-ID: <1339317276.d6584f5ef8eb65bf0c818a0ab2f9b008663d758e.zmedico@gentoo> (raw)

commit:     d6584f5ef8eb65bf0c818a0ab2f9b008663d758e
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Jun 10 08:24:59 2012 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Jun 10 08:34:36 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=d6584f5e

cache/sqlite.py: dynamically add columns to table

---
 pym/portage/cache/sqlite.py |   42 ++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/pym/portage/cache/sqlite.py b/pym/portage/cache/sqlite.py
index fcc62ff..a6a3e06 100644
--- a/pym/portage/cache/sqlite.py
+++ b/pym/portage/cache/sqlite.py
@@ -1,6 +1,7 @@
-# Copyright 1999-2011 Gentoo Foundation
+# Copyright 1999-2012 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+import re
 import sys
 from portage.cache import fs_template
 from portage.cache import cache_errors
@@ -117,7 +118,13 @@ class database(fs_template.FsBased):
 		for k, v in self._db_table.items():
 			if self._db_table_exists(v["table_name"]):
 				create_statement = self._db_table_get_create(v["table_name"])
-				if create_statement != v["create"]:
+				table_ok, missing_keys = self._db_validate_create_statement(create_statement)
+				if table_ok:
+					if missing_keys:
+						for k in sorted(missing_keys):
+							cursor.execute("ALTER TABLE %s ADD COLUMN %s TEXT" %
+								(self._db_table["packages"]["table_name"], k))
+				else:
 					writemsg(_("sqlite: dropping old table: %s\n") % v["table_name"])
 					cursor.execute("DROP TABLE %s" % v["table_name"])
 					cursor.execute(v["create"])
@@ -138,6 +145,37 @@ class database(fs_template.FsBased):
 			self._db_escape_string(table_name))
 		return cursor.fetchall()[0][0]
 
+	def _db_validate_create_statement(self, statement):
+		missing_keys = None
+		if statement == self._db_table["packages"]["create"]:
+			return True, missing_keys
+
+		m = re.match(r'^\s*CREATE\s*TABLE\s*%s\s*\(\s*%s\s*INTEGER\s*PRIMARY\s*KEY\s*AUTOINCREMENT\s*,(.*)\)\s*$' %
+			(self._db_table["packages"]["table_name"],
+			self._db_table["packages"]["package_id"]),
+			statement)
+		if m is None:
+			return False, missing_keys
+
+		unique_constraints = set([self._db_table["packages"]["package_key"]])
+		missing_keys = set(self._allowed_keys)
+		unique_re = re.compile(r'^\s*UNIQUE\s*\(\s*(\w*)\s*\)\s*$')
+		column_re = re.compile(r'^\s*(\w*)\s*TEXT\s*$')
+		for x in m.group(1).split(","):
+			m = column_re.match(x)
+			if m is not None:
+				missing_keys.discard(m.group(1))
+				continue
+			m = unique_re.match(x)
+			if m is not None:
+				unique_constraints.discard(m.group(1))
+				continue
+
+		if unique_constraints:
+			return False, missing_keys
+
+		return True, missing_keys
+
 	def _db_init_cache_size(self, cache_bytes):
 		cursor = self._db_cursor
 		cursor.execute("PRAGMA page_size")



             reply	other threads:[~2012-06-10  8:35 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-10  8:35 Zac Medico [this message]
  -- strict thread matches above, loose matches on Subject: below --
2016-09-19 16:57 [gentoo-commits] proj/portage:master commit in: pym/portage/cache/ Zac Medico
2016-07-24 23:22 Zac Medico
2016-07-13 11:32 Zac Medico
2015-12-29 16:42 Zac Medico
2015-12-29 16:42 Zac Medico
2015-12-29 16:42 Zac Medico
2014-11-14 17:33 Zac Medico
2013-07-26  8:23 Arfrever Frehtes Taifersar Arahesis
2013-07-26  7:57 Zac Medico
2013-01-18 17:12 Zac Medico
2013-01-18 16:37 Zac Medico
2013-01-18 15:32 Zac Medico
2012-11-21  4:38 Zac Medico
2012-10-02 20:30 Zac Medico
2012-09-25  3:44 Zac Medico
2012-09-25  1:54 Zac Medico
2012-09-25  1:42 Zac Medico
2012-09-18 19:02 Zac Medico
2012-06-10  8:28 Zac Medico
2012-06-10  8:25 Zac Medico
2012-05-24 19:06 Zac Medico
2012-05-23 19:00 Zac Medico
2011-10-29 23:10 Zac Medico
2011-10-18  5:26 Zac Medico
2011-10-14 15:30 Zac Medico
2011-09-07 15:56 Zac Medico
2011-05-12 19:05 Zac Medico
2011-05-12 19:02 Zac Medico
2011-05-12 19:02 Zac Medico
2011-02-08  6:37 Zac Medico
2011-02-07  0:14 Zac Medico

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1339317276.d6584f5ef8eb65bf0c818a0ab2f9b008663d758e.zmedico@gentoo \
    --to=zmedico@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox