witten
/
luminotes
Archived
1
0
Fork 0

If Schema_upgrader encounters a database without a schema_version set, assumes that it's a 1.5.4 schema.

This commit is contained in:
Dan Helfman 2008-10-15 21:14:42 -07:00
parent 0a1d481201
commit d79876999a
2 changed files with 21 additions and 2 deletions

View File

@ -48,8 +48,10 @@ class Schema_upgrader:
try:
from_version = self.__database.select_one( tuple, "select * from schema_version;" );
# if there's no schema version table, assume the from_version is 1.5.4, which was the last
# version not to include a schema_version table
except:
from_version = None
from_version = ( 1, 5, 4 )
if self.__database.backend == Persistent.SQLITE_BACKEND:
extension = u"sqlite"
@ -69,7 +71,7 @@ class Schema_upgrader:
continue
# skip those versions that won't help us upgrade
if from_version and version <= from_version:
if version <= from_version:
continue
if version > to_version:
continue

View File

@ -102,6 +102,23 @@ class Test_schema_upgrader( object ):
self.test_upgrade_schema();
def test_upgrade_schema_default_to_start_version_of_1_5_4( self ):
# test that if no schema_version table exists, then the starting version is assumed to be 1.5.4
self.fake_files = {
u"model/delta/1.5.3.sqlite": u"invalid sql;",
u"model/delta/1.5.4.sqlite": u"should not be invoked;",
u"model/delta/1.5.5.sqlite": u"create table new_table ( foo text ); insert into new_table values ( 'hi' );",
u"model/delta/1.5.6.sqlite": u"insert into new_table values ( 'bye' );",
}
self.upgrader.upgrade_schema( u"1.5.6" );
result = self.database.select_many( tuple, u"select * from new_table;" );
assert result == [ ( u"hi", ), ( u"bye", ), ];
result = self.database.select_many( tuple, u"select * from schema_version;" );
assert result == [ ( 1, 5, 6 ) ];
def test_apply_schema_delta( self ):
self.fake_files = {
u"model/delta/5.6.5.sqlite": u"insert into new_table values ( 'should not show up' );",