fix MySQL failing tests with autoincrement

This commit is contained in:
iElectric 2010-05-02 20:31:50 +02:00
parent da836aad7e
commit ece9ffed35
2 changed files with 16 additions and 9 deletions

View File

@ -25,13 +25,15 @@ class MySQLSchemaChanger(MySQLSchemaGenerator, ansisql.ANSISchemaChanger):
table = delta.table
colspec = self.get_column_specification(delta.result_column)
if delta.result_column.autoincrement:
first = [c for c in table.primary_key.columns
primary_keys = [c for c in table.primary_key.columns
if (c.autoincrement and
isinstance(c.type, sqltypes.Integer) and
not c.foreign_keys)].pop(0)
not c.foreign_keys)]
if first.name == delta.current_name:
colspec += " AUTO_INCREMENT"
if primary_keys:
first = primary_keys.pop(0)
if first.name == delta.current_name:
colspec += " AUTO_INCREMENT"
old_col_name = self.preparer.quote(delta.current_name, table.quote)
self.start_alter_table(table)

View File

@ -11,6 +11,7 @@ from migrate.versioning.repository import Repository
from migrate.versioning import genmodel, shell, api
from migrate.versioning.exceptions import *
from tests.fixture import Shell, DB, usedb
from tests.fixture import models
class TestShellCommands(Shell):
@ -483,11 +484,15 @@ class TestShellDatabase(Shell, DB):
result = self.env.run('migrate version_control %s %s' % (self.url, repos_path))
result = self.env.run('migrate create_model %s %s' % (self.url, repos_path))
self.assertTrue("""tmp_account_rundiffs = Table('tmp_account_rundiffs', meta,
Column('id', Integer(), primary_key=True, nullable=False),
Column('login', String(length=None, convert_unicode=False, assert_unicode=None)),
Column('passwd', String(length=None, convert_unicode=False, assert_unicode=None))""" in result.stdout)
temp_dict = dict()
exec result.stdout in temp_dict
self.compare_columns_equal(models.tmp_account_rundiffs.c, temp_dict['tmp_account_rundiffs'].c)
#self.assertTrue("""tmp_account_rundiffs = Table('tmp_account_rundiffs', meta,
#Column('id', Integer(), primary_key=True, nullable=False),
#Column('login', String(length=None, convert_unicode=False, assert_unicode=None)),
#Column('passwd', String(length=None, convert_unicode=False, assert_unicode=None))""" in result.stdout)
# We're happy with db changes, make first db upgrade script to go from version 0 -> 1.
result = self.env.run('migrate make_update_script_for_model', expect_error=True)
self.assertTrue('Not enough arguments' in result.stderr)