jaypipes
unread,Mar 22, 2011, 2:30:09 PM3/22/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to migrate-users
Hello all,
I have an issue where for some reason a Table object's metadata is not
properly showing changes to the underlying database schema after a
migration, but only when the engine is SQLite.
Our "images" table has a column ("type") removed when moving from
version 2 to version 3. I put together a simple test case that
verifies the upgrade removes the "type" column and that a downgrade
adds the "type" column back.
My test case looks like this:
migration_api.db_sync(self.options, 3)
cur_version = migration_api.db_version(self.options)
self.assertEquals(3, cur_version)
# We are now on version 3. Type column should not exist.
# Let's downgrade and check that
# the type column exists again...
images_table = Table('images', MetaData(), autoload=True,
autoload_with=self.engine)
self.assertTrue('type' not in images_table.c,
"'type' column found in images table columns!
"
"images table columns: %s"
% images_table.c.keys())
migration_api.downgrade(self.options, 2)
cur_version = migration_api.db_version(self.options)
self.assertEquals(2, cur_version)
images_table = Table('images', MetaData(), autoload=True,
autoload_with=self.engine)
if using_sqlite:
cmd = "sqlite3 glance_test_migration.sqlite \".schema
images\""
exitcode, out, err = execute(cmd)
self.assertEqual(0, exitcode)
self.assertTrue('type VARCHAR(30)' in out)
else:
out = ""
self.assertTrue('type' in images_table.c,
"'type' column not found in images table
columns! "
"images table columns reported by metadata: %s
\n"
"sqlite reported: %s\n"
% (images_table.c.keys(), out))
When running the test with MySQL, the test and migration works
perfectly fine.
Unfortunately, when running with SQLite, I get the following:
FAIL: test_XXX (tests.unit.test_migrations.TestMigrations)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/XXX/tests/unit/test_migrations.py", line 103, in test_XXX
% (images_table.c.keys(), out))
AssertionError: 'type' column not found in images table columns!
images table columns reported by metadata: [u'id', u'name', u'size',
u'status', u'is_public', u'location', u'created_at', u'updated_at',
u'deleted_at', u'deleted', u'disk_format', u'container_format']
sqlite reported: CREATE TABLE images (
id INTEGER NOT NULL,
name VARCHAR(255),
size INTEGER,
type VARCHAR(30),
status VARCHAR(30) NOT NULL,
is_public BOOLEAN NOT NULL,
location TEXT,
created_at DATETIME NOT NULL,
updated_at DATETIME,
deleted_at DATETIME,
deleted BOOLEAN NOT NULL,
PRIMARY KEY (id),
CHECK (is_public IN (0, 1)),
CHECK (deleted IN (0, 1))
);
CREATE INDEX ix_images_deleted ON images (deleted);
CREATE INDEX ix_images_is_public ON images (is_public);
You can see above the the metadata shows the *old* schema incorrectly,
but directly querying the sqlite database shows that the migration
succeeded and the "type" column is indeed added back to the images
table.
Is there some trick with metadata and the SQLite datastore that I'm
missing that prevents the metadata from being refreshed properly?
Any help most appreciated!
-jay
p.s. On a side note, is anyone even monitoring the bug reports for SA-
Migrate any more?