From: David Stainton Date: Tue, 14 Jul 2015 23:34:27 +0000 (-0700) Subject: Make backupdb schema evolution more visible X-Git-Url: https://git.rkrishnan.org/pf/content/simplejson/frontends/somewhere?a=commitdiff_plain;h=3f80101f68f851be0788f7f49ee4fb13873d504a;p=tahoe-lafs%2Ftahoe-lafs.git Make backupdb schema evolution more visible --- diff --git a/src/allmydata/backupdb.py b/src/allmydata/backupdb.py index 14e6f9f0..b24c217e 100644 --- a/src/allmydata/backupdb.py +++ b/src/allmydata/backupdb.py @@ -12,28 +12,28 @@ from allmydata.util.dbutil import get_db, DBError DAY = 24*60*60 MONTH = 30*DAY -SCHEMA_v1 = """ -CREATE TABLE version -- added in v1 +MAIN_SCHEMA = """ +CREATE TABLE version ( - version INTEGER -- contains one row, set to 2 + version INTEGER -- contains one row, set to %s ); -CREATE TABLE local_files -- added in v1 +CREATE TABLE local_files ( path VARCHAR(1024) PRIMARY KEY, -- index, this is an absolute UTF-8-encoded local filename size INTEGER, -- os.stat(fn)[stat.ST_SIZE] mtime NUMBER, -- os.stat(fn)[stat.ST_MTIME] ctime NUMBER, -- os.stat(fn)[stat.ST_CTIME] - fileid INTEGER + fileid INTEGER,%s ); -CREATE TABLE caps -- added in v1 +CREATE TABLE caps ( fileid INTEGER PRIMARY KEY AUTOINCREMENT, filecap VARCHAR(256) UNIQUE -- URI:CHK:... ); -CREATE TABLE last_upload -- added in v1 +CREATE TABLE last_upload ( fileid INTEGER PRIMARY KEY, last_uploaded TIMESTAMP, @@ -42,6 +42,8 @@ CREATE TABLE last_upload -- added in v1 """ +SCHEMA_v1 = MAIN_SCHEMA % (1, "") + TABLE_DIRECTORY = """ CREATE TABLE directories -- added in v2 @@ -54,7 +56,7 @@ CREATE TABLE directories -- added in v2 """ -SCHEMA_v2 = SCHEMA_v1 + TABLE_DIRECTORY +SCHEMA_v2 = MAIN_SCHEMA % (2, "") + TABLE_DIRECTORY UPDATE_v1_to_v2 = TABLE_DIRECTORY + """ UPDATE version SET version=2; @@ -64,38 +66,8 @@ UPDATERS = { 2: UPDATE_v1_to_v2, } -MAIN_v3 = """ -CREATE TABLE version -( - version INTEGER -- contains one row, set to 3 -); - -CREATE TABLE local_files -( - path VARCHAR(1024) PRIMARY KEY, -- index, this is an absolute UTF-8-encoded local filename - size INTEGER, -- os.stat(fn)[stat.ST_SIZE] - mtime NUMBER, -- os.stat(fn)[stat.ST_MTIME] - ctime NUMBER, -- os.stat(fn)[stat.ST_CTIME] - fileid INTEGER, - version INTEGER -); - -CREATE TABLE caps -( - fileid INTEGER PRIMARY KEY AUTOINCREMENT, - filecap VARCHAR(256) UNIQUE -- URI:CHK:... -); - -CREATE TABLE last_upload -( - fileid INTEGER PRIMARY KEY, - last_uploaded TIMESTAMP, - last_checked TIMESTAMP -); - -""" -SCHEMA_v3 = MAIN_v3 + TABLE_DIRECTORY +SCHEMA_v3 = MAIN_SCHEMA % (3, "\nversion INTEGER\n") + TABLE_DIRECTORY def get_backupdb(dbfile, stderr=sys.stderr,