<s> import datetime <EOL> import os <EOL> from peewee import * <EOL> from peewee import print_ <EOL> from playhouse . migrate import * <EOL> from playhouse . test_utils import count_queries <EOL> from playhouse . tests . base import database_initializer <EOL> from playhouse . tests . base import PeeweeTestCase <EOL> from playhouse . tests . base import skip_if <EOL> try : <EOL> from psycopg2cffi import compat <EOL> compat . register ( ) <EOL> except ImportError : <EOL> pass <EOL> try : <EOL> import psycopg2 <EOL> except ImportError : <EOL> psycopg2 = None <EOL> try : <EOL> import MySQLdb as mysql <EOL> except ImportError : <EOL> try : <EOL> import pymysql as mysql <EOL> except ImportError : <EOL> mysql = None <EOL> if mysql : <EOL> mysql_db = database_initializer . get_database ( '<STR_LIT>' ) <EOL> else : <EOL> mysql_db = None <EOL> if psycopg2 : <EOL> pg_db = database_initializer . get_database ( '<STR_LIT>' ) <EOL> else : <EOL> pg_db = None <EOL> sqlite_db = SqliteDatabase ( '<STR_LIT>' ) <EOL> class Tag ( Model ) : <EOL> tag = CharField ( ) <EOL> class Person ( Model ) : <EOL> first_name = CharField ( ) <EOL> last_name = CharField ( ) <EOL> dob = DateField ( null = True ) <EOL> class User ( Model ) : <EOL> id = CharField ( primary_key = True , max_length = <NUM_LIT:20> ) <EOL> password = CharField ( default = '<STR_LIT>' ) <EOL> class Meta : <EOL> db_table = '<STR_LIT>' <EOL> class Page ( Model ) : <EOL> name = CharField ( max_length = <NUM_LIT:100> , unique = True , null = True ) <EOL> user = ForeignKeyField ( User , null = True , related_name = '<STR_LIT>' ) <EOL> class IndexModel ( Model ) : <EOL> first_name = CharField ( ) <EOL> last_name = CharField ( ) <EOL> data = IntegerField ( unique = True ) <EOL> class Meta : <EOL> database = sqlite_db <EOL> indexes = ( <EOL> ( ( '<STR_LIT>' , '<STR_LIT>' ) , True ) , <EOL> ) <EOL> MODELS = [ <EOL> Person , <EOL> Tag , <EOL> User , <EOL> Page , <EOL> ] <EOL> class BaseMigrationTestCase ( object ) : <EOL> database = None <EOL> migrator_class = None <EOL> _exception_add_not_null = True <EOL> _person_data = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , datetime . date ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:1> ) ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , datetime . date ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT:1> ) ) , <EOL> ] <EOL> def setUp ( self ) : <EOL> super ( BaseMigrationTestCase , self ) . setUp ( ) <EOL> for model_class in MODELS : <EOL> model_class . _meta . database = self . database <EOL> self . database . drop_tables ( MODELS , True ) <EOL> self . database . create_tables ( MODELS ) <EOL> self . migrator = self . migrator_class ( self . database ) <EOL> if '<STR_LIT>' in User . _meta . reverse_rel : <EOL> del User . _meta . reverse_rel [ '<STR_LIT>' ] <EOL> delattr ( User , '<STR_LIT>' ) <EOL> def tearDown ( self ) : <EOL> super ( BaseMigrationTestCase , self ) . tearDown ( ) <EOL> for model_class in MODELS : <EOL> model_class . _meta . database = self . database <EOL> self . database . drop_tables ( MODELS , True ) <EOL> def test_add_column ( self ) : <EOL> df = DateTimeField ( null = True ) <EOL> df_def = DateTimeField ( default = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> cf = CharField ( max_length = <NUM_LIT:200> , default = '<STR_LIT>' ) <EOL> bf = BooleanField ( default = True ) <EOL> ff = FloatField ( default = <NUM_LIT:0> ) <EOL> t1 = Tag . create ( tag = '<STR_LIT>' ) <EOL> t2 = Tag . create ( tag = '<STR_LIT>' ) <EOL> def add_column ( field_name , field_obj ) : <EOL> return self . migrator . add_column ( '<STR_LIT>' , field_name , field_obj ) <EOL> migrate ( <EOL> add_column ( '<STR_LIT>' , df ) , <EOL> add_column ( '<STR_LIT>' , df_def ) , <EOL> add_column ( '<STR_LIT>' , cf ) , <EOL> add_column ( '<STR_LIT>' , bf ) , <EOL> add_column ( '<STR_LIT>' , ff ) ) <EOL> class NewTag ( Model ) : <EOL> tag = CharField ( ) <EOL> pub_date = df <EOL> modified_date = df_def <EOL> comment = cf <EOL> is_public = bf <EOL> popularity = ff <EOL> class Meta : <EOL> database = self . database <EOL> db_table = Tag . _meta . db_table <EOL> query = ( NewTag <EOL> . select ( <EOL> NewTag . id , <EOL> NewTag . tag , <EOL> NewTag . pub_date , <EOL> NewTag . modified_date , <EOL> NewTag . comment , <EOL> NewTag . is_public , <EOL> NewTag . popularity ) <EOL> . order_by ( NewTag . tag . asc ( ) ) ) <EOL> self . assertEqual ( list ( query . tuples ( ) ) , [ <EOL> ( t1 . id , '<STR_LIT>' , None , datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) , '<STR_LIT>' , True , <NUM_LIT:0.0> ) , <EOL> ( t2 . id , '<STR_LIT>' , None , datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) , '<STR_LIT>' , True , <NUM_LIT:0.0> ) , <EOL> ] ) <EOL> def _create_people ( self ) : <EOL> for first , last , dob in self . _person_data : <EOL> Person . create ( first_name = first , last_name = last , dob = dob ) <EOL> def get_column_names ( self , tbl ) : <EOL> cursor = self . database . execute_sql ( '<STR_LIT>' % tbl ) <EOL> return set ( [ col [ <NUM_LIT:0> ] for col in cursor . description ] ) <EOL> def test_drop_column ( self ) : <EOL> self . _create_people ( ) <EOL> migrate ( <EOL> self . migrator . drop_column ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> self . migrator . drop_column ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> column_names = self . get_column_names ( '<STR_LIT>' ) <EOL> self . assertEqual ( column_names , set ( [ '<STR_LIT:id>' , '<STR_LIT>' ] ) ) <EOL> User . create ( id = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> User . create ( id = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> migrate ( self . migrator . drop_column ( '<STR_LIT>' , '<STR_LIT:password>' ) ) <EOL> column_names = self . get_column_names ( '<STR_LIT>' ) <EOL> self . assertEqual ( column_names , set ( [ '<STR_LIT:id>' ] ) ) <EOL> data = [ row for row in User . select ( User . id ) . order_by ( User . id ) . tuples ( ) ] <EOL> self . assertEqual ( data , [ <EOL> ( '<STR_LIT>' , ) , <EOL> ( '<STR_LIT>' , ) , ] ) <EOL> def test_rename_column ( self ) : <EOL> self . _create_people ( ) <EOL> migrate ( <EOL> self . migrator . rename_column ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> self . migrator . rename_column ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> column_names = self . get_column_names ( '<STR_LIT>' ) <EOL> self . assertEqual ( column_names , set ( [ '<STR_LIT:id>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> class NewPerson ( Model ) : <EOL> first = CharField ( ) <EOL> last = CharField ( ) <EOL> dob = DateField ( ) <EOL> class Meta : <EOL> database = self . database <EOL> db_table = Person . _meta . db_table <EOL> query = ( NewPerson <EOL> . select ( <EOL> NewPerson . first , <EOL> NewPerson . last , <EOL> NewPerson . dob ) <EOL> . order_by ( NewPerson . first ) ) <EOL> self . assertEqual ( list ( query . tuples ( ) ) , self . _person_data ) <EOL> def test_rename_gh380 ( self ) : <EOL> u1 = User . create ( id = '<STR_LIT>' ) <EOL> u2 = User . create ( id = '<STR_LIT>' ) <EOL> p1 = Page . create ( name = '<STR_LIT>' , user = u1 ) <EOL> p2 = Page . create ( name = '<STR_LIT>' , user = u1 ) <EOL> p3 = Page . create ( name = '<STR_LIT>' , user = u2 ) <EOL> migrate ( self . migrator . rename_column ( '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT:title>' ) ) <EOL> column_names = self . get_column_names ( '<STR_LIT>' ) <EOL> self . assertEqual ( column_names , set ( [ '<STR_LIT:id>' , '<STR_LIT:title>' , '<STR_LIT>' ] ) ) <EOL> class NewPage ( Model ) : <EOL> title = CharField ( max_length = <NUM_LIT:100> , unique = True , null = True ) <EOL> user = ForeignKeyField ( User , null = True , related_name = '<STR_LIT>' ) <EOL> class Meta : <EOL> database = self . database <EOL> db_table = Page . _meta . db_table <EOL> query = ( NewPage <EOL> . select ( <EOL> NewPage . title , <EOL> NewPage . user ) <EOL> . order_by ( NewPage . title ) ) <EOL> self . assertEqual ( <EOL> [ ( np . title , np . user . id ) for np in query ] , <EOL> [ ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> def test_add_not_null ( self ) : <EOL> self . _create_people ( ) <EOL> def addNotNull ( ) : <EOL> with self . database . transaction ( ) : <EOL> migrate ( self . migrator . add_not_null ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if self . _exception_add_not_null : <EOL> self . assertRaises ( IntegrityError , addNotNull ) <EOL> ( Person <EOL> . update ( dob = datetime . date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> . where ( Person . dob >> None ) <EOL> . execute ( ) ) <EOL> addNotNull ( ) <EOL> with self . database . transaction ( ) : <EOL> with self . assertRaisesCtx ( ( IntegrityError , OperationalError ) ) : <EOL> Person . create ( <EOL> first_name = '<STR_LIT>' , <EOL> last_name = '<STR_LIT>' , <EOL> dob = None ) <EOL> def test_drop_not_null ( self ) : <EOL> self . _create_people ( ) <EOL> migrate ( <EOL> self . migrator . drop_not_null ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> self . migrator . drop_not_null ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> p = Person . create ( first_name = None , last_name = None ) <EOL> query = ( Person <EOL> . select ( ) <EOL> . where ( <EOL> ( Person . first_name >> None ) & <EOL> ( Person . last_name >> None ) ) ) <EOL> self . assertEqual ( query . count ( ) , <NUM_LIT:1> ) <EOL> def test_modify_not_null_foreign_key ( self ) : <EOL> user = User . create ( id = '<STR_LIT>' ) <EOL> Page . create ( name = '<STR_LIT>' ) <EOL> Page . create ( name = '<STR_LIT>' , user = user ) <EOL> def addNotNull ( ) : <EOL> with self . database . transaction ( ) : <EOL> migrate ( self . migrator . add_not_null ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if self . _exception_add_not_null : <EOL> self . assertRaises ( IntegrityError , addNotNull ) <EOL> Page . update ( user = user ) . where ( Page . user . is_null ( ) ) . execute ( ) <EOL> addNotNull ( ) <EOL> with self . database . transaction ( ) : <EOL> with self . assertRaisesCtx ( ( OperationalError , IntegrityError ) ) : <EOL> Page . create ( <EOL> name = '<STR_LIT>' , <EOL> user = None ) <EOL> with self . database . transaction ( ) : <EOL> migrate ( self . migrator . drop_not_null ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertEqual ( Page . select ( ) . where ( Page . user . is_null ( ) ) . count ( ) , <NUM_LIT:0> ) <EOL> Page . create ( name = '<STR_LIT>' , user = None ) <EOL> self . assertEqual ( Page . select ( ) . where ( Page . user . is_null ( ) ) . count ( ) , <NUM_LIT:1> ) <EOL> def test_rename_table ( self ) : <EOL> t1 = Tag . create ( tag = '<STR_LIT>' ) <EOL> t2 = Tag . create ( tag = '<STR_LIT>' ) <EOL> class Tag_asdf ( Tag ) : <EOL> pass <EOL> self . assertEqual ( Tag_asdf . _meta . db_table , '<STR_LIT>' ) <EOL> Tag_asdf . drop_table ( True ) <EOL> migrate ( self . migrator . rename_table ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> query = ( Tag_asdf <EOL> . select ( ) <EOL> . order_by ( Tag_asdf . tag ) ) <EOL> self . assertEqual ( [ t . tag for t in query ] , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> with self . database . transaction ( ) : <EOL> self . assertRaises ( <EOL> DatabaseError , <EOL> Tag . create , <EOL> tag = '<STR_LIT>' ) <EOL> def test_add_index ( self ) : <EOL> columns = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> migrate ( self . migrator . add_index ( '<STR_LIT>' , columns , True ) ) <EOL> Person . create ( first_name = '<STR_LIT>' , last_name = '<STR_LIT>' ) <EOL> with self . database . transaction ( ) : <EOL> self . assertRaises ( <EOL> IntegrityError , <EOL> Person . create , <EOL> first_name = '<STR_LIT>' , <EOL> last_name = '<STR_LIT>' ) <EOL> def test_drop_index ( self ) : <EOL> self . test_add_index ( ) <EOL> migrate ( <EOL> self . migrator . drop_index ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> Person . create ( first_name = '<STR_LIT>' , last_name = '<STR_LIT>' ) <EOL> query = ( Person <EOL> . select ( ) <EOL> . where ( <EOL> ( Person . first_name == '<STR_LIT>' ) & <EOL> ( Person . last_name == '<STR_LIT>' ) ) ) <EOL> self . assertEqual ( query . count ( ) , <NUM_LIT:2> ) <EOL> def test_add_and_remove ( self ) : <EOL> operations = [ ] <EOL> field = CharField ( default = '<STR_LIT:foo>' ) <EOL> for i in range ( <NUM_LIT:10> ) : <EOL> operations . append ( self . migrator . add_column ( '<STR_LIT>' , '<STR_LIT:foo>' , field ) ) <EOL> operations . append ( self . migrator . drop_column ( '<STR_LIT>' , '<STR_LIT:foo>' ) ) <EOL> migrate ( * operations ) <EOL> col_names = self . get_column_names ( '<STR_LIT>' ) <EOL> self . assertEqual ( col_names , set ( [ '<STR_LIT:id>' , '<STR_LIT>' ] ) ) <EOL> def test_multiple_operations ( self ) : <EOL> self . database . execute_sql ( '<STR_LIT>' ) <EOL> self . database . execute_sql ( '<STR_LIT>' ) <EOL> self . _create_people ( ) <EOL> field_n = CharField ( null = True ) <EOL> field_d = CharField ( default = '<STR_LIT:test>' ) <EOL> operations = [ <EOL> self . migrator . add_column ( '<STR_LIT>' , '<STR_LIT>' , field_n ) , <EOL> self . migrator . drop_column ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> self . migrator . add_column ( '<STR_LIT>' , '<STR_LIT>' , field_d ) , <EOL> self . migrator . rename_table ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> self . migrator . rename_table ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> self . migrator . rename_column ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> self . migrator . add_index ( '<STR_LIT>' , ( '<STR_LIT>' , ) , True ) , <EOL> ] <EOL> migrate ( * operations ) <EOL> class PersonNugg ( Model ) : <EOL> field_null = field_n <EOL> field_default = field_d <EOL> last = CharField ( ) <EOL> dob = DateField ( null = True ) <EOL> class Meta : <EOL> database = self . database <EOL> db_table = '<STR_LIT>' <EOL> people = ( PersonNugg <EOL> . select ( <EOL> PersonNugg . field_null , <EOL> PersonNugg . field_default , <EOL> PersonNugg . last , <EOL> PersonNugg . dob ) <EOL> . order_by ( PersonNugg . last ) <EOL> . tuples ( ) ) <EOL> expected = [ <EOL> ( None , '<STR_LIT:test>' , '<STR_LIT>' , datetime . date ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT:1> ) ) , <EOL> ( None , '<STR_LIT:test>' , '<STR_LIT>' , datetime . date ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:1> ) ) , <EOL> ( None , '<STR_LIT:test>' , '<STR_LIT>' , None ) , <EOL> ] <EOL> self . assertEqual ( list ( people ) , expected ) <EOL> with self . database . transaction ( ) : <EOL> self . assertRaises ( <EOL> IntegrityError , <EOL> PersonNugg . create , <EOL> last = '<STR_LIT>' , <EOL> field_default = '<STR_LIT>' ) <EOL> def test_add_foreign_key ( self ) : <EOL> if hasattr ( Person , '<STR_LIT>' ) : <EOL> delattr ( Person , '<STR_LIT>' ) <EOL> del Person . _meta . reverse_rel [ '<STR_LIT>' ] <EOL> self . assertEqual ( self . database . get_foreign_keys ( '<STR_LIT>' ) , [ ] ) <EOL> field = ForeignKeyField ( Person , null = True , to_field = Person . id ) <EOL> migrate ( self . migrator . add_column ( '<STR_LIT>' , '<STR_LIT>' , field ) ) <EOL> class NewTag ( Tag ) : <EOL> person = field <EOL> class Meta : <EOL> db_table = '<STR_LIT>' <EOL> p = Person . create ( first_name = '<STR_LIT>' , last_name = '<STR_LIT>' ) <EOL> t1 = NewTag . create ( tag = '<STR_LIT>' , person = p ) <EOL> t2 = NewTag . create ( tag = '<STR_LIT>' ) <EOL> t1_db = NewTag . get ( NewTag . tag == '<STR_LIT>' ) <EOL> self . assertEqual ( t1_db . person , p ) <EOL> t2_db = NewTag . get ( NewTag . tag == '<STR_LIT>' ) <EOL> self . assertEqual ( t2_db . person , None ) <EOL> foreign_keys = self . database . get_foreign_keys ( '<STR_LIT>' ) <EOL> self . assertEqual ( len ( foreign_keys ) , <NUM_LIT:1> ) <EOL> foreign_key = foreign_keys [ <NUM_LIT:0> ] <EOL> self . assertEqual ( foreign_key . column , '<STR_LIT>' ) <EOL> self . assertEqual ( foreign_key . dest_column , '<STR_LIT:id>' ) <EOL> self . assertEqual ( foreign_key . dest_table , '<STR_LIT>' ) <EOL> def test_drop_foreign_key ( self ) : <EOL> migrate ( self . migrator . drop_column ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> columns = self . database . get_columns ( '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> sorted ( column . name for column in columns ) , <EOL> [ '<STR_LIT:id>' , '<STR_LIT:name>' ] ) <EOL> self . assertEqual ( self . database . get_foreign_keys ( '<STR_LIT>' ) , [ ] ) <EOL> def test_rename_foreign_key ( self ) : <EOL> migrate ( self . migrator . rename_column ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> columns = self . database . get_columns ( '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> sorted ( column . name for column in columns ) , <EOL> [ '<STR_LIT>' , '<STR_LIT:id>' , '<STR_LIT:name>' ] ) <EOL> foreign_keys = self . database . get_foreign_keys ( '<STR_LIT>' ) <EOL> self . assertEqual ( len ( foreign_keys ) , <NUM_LIT:1> ) <EOL> foreign_key = foreign_keys [ <NUM_LIT:0> ] <EOL> self . assertEqual ( foreign_key . column , '<STR_LIT>' ) <EOL> self . assertEqual ( foreign_key . dest_column , '<STR_LIT:id>' ) <EOL> self . assertEqual ( foreign_key . dest_table , '<STR_LIT>' ) <EOL> class SqliteMigrationTestCase ( BaseMigrationTestCase , PeeweeTestCase ) : <EOL> database = sqlite_db <EOL> migrator_class = SqliteMigrator <EOL> def setUp ( self ) : <EOL> super ( SqliteMigrationTestCase , self ) . setUp ( ) <EOL> IndexModel . drop_table ( True ) <EOL> IndexModel . create_table ( ) <EOL> def test_valid_column_required ( self ) : <EOL> self . assertRaises ( <EOL> ValueError , <EOL> migrate , <EOL> self . migrator . drop_column ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertRaises ( <EOL> ValueError , <EOL> migrate , <EOL> self . migrator . rename_column ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def test_table_case_insensitive ( self ) : <EOL> migrate ( self . migrator . drop_column ( '<STR_LIT>' , '<STR_LIT:name>' ) ) <EOL> column_names = self . get_column_names ( '<STR_LIT>' ) <EOL> self . assertEqual ( column_names , set ( [ '<STR_LIT:id>' , '<STR_LIT>' ] ) ) <EOL> testing_field = CharField ( default = '<STR_LIT>' ) <EOL> migrate ( self . migrator . add_column ( '<STR_LIT>' , '<STR_LIT>' , testing_field ) ) <EOL> column_names = self . get_column_names ( '<STR_LIT>' ) <EOL> self . assertEqual ( column_names , set ( [ '<STR_LIT:id>' , '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> migrate ( self . migrator . drop_column ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> indexes = self . migrator . database . get_indexes ( '<STR_LIT>' ) <EOL> self . assertEqual ( len ( indexes ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( indexes [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> def test_add_column_indexed_table ( self ) : <EOL> field = CharField ( default = '<STR_LIT>' ) <EOL> migrate ( self . migrator . add_column ( '<STR_LIT>' , '<STR_LIT:foo>' , field ) ) <EOL> db = self . migrator . database <EOL> columns = db . get_columns ( '<STR_LIT>' ) <EOL> self . assertEqual ( sorted ( column . name for column in columns ) , <EOL> [ '<STR_LIT:data>' , '<STR_LIT>' , '<STR_LIT:foo>' , '<STR_LIT:id>' , '<STR_LIT>' ] ) <EOL> indexes = db . get_indexes ( '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> sorted ( ( index . name , index . columns ) for index in indexes ) , <EOL> [ ( '<STR_LIT>' , [ '<STR_LIT:data>' ] ) , <EOL> ( '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT>' ] ) ] ) <EOL> def test_index_preservation ( self ) : <EOL> with count_queries ( ) as qc : <EOL> migrate ( self . migrator . rename_column ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) ) <EOL> queries = [ log . msg for log in qc . get_queries ( ) ] <EOL> self . assertEqual ( queries , [ <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> ( '<STR_LIT>' , '<STR_LIT:index>' ) ) , <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , [ ] ) , <EOL> ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , [ ] ) , <EOL> ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , [ ] ) , <EOL> ( '<STR_LIT>' , [ ] ) , <EOL> ( '<STR_LIT>' , [ ] ) , <EOL> ( '<STR_LIT>' <EOL> '<STR_LIT>' , [ ] ) , <EOL> ( '<STR_LIT>' <EOL> '<STR_LIT>' , [ ] ) <EOL> ] ) <EOL> @ skip_if ( lambda : psycopg2 is None ) <EOL> class PostgresqlMigrationTestCase ( BaseMigrationTestCase , PeeweeTestCase ) : <EOL> database = pg_db <EOL> migrator_class = PostgresqlMigrator <EOL> @ skip_if ( lambda : mysql is None ) <EOL> class MySQLMigrationTestCase ( BaseMigrationTestCase , PeeweeTestCase ) : <EOL> database = mysql_db <EOL> migrator_class = MySQLMigrator <EOL> _exception_add_not_null = False </s>
