示例#1
0
文件: db.py 项目: 10sr/hue
 def setUp(self):
     db.debug = False
     try:
         import MySQLdb
     except ImportError:
         pass
     else:
         filterwarnings('ignore', category=MySQLdb.Warning)
     db.clear_deferred_sql()
     db.start_transaction()
示例#2
0
 def setUp(self):
     db.debug = False
     try:
         import MySQLdb
     except ImportError:
         pass
     else:
         filterwarnings('ignore', category=MySQLdb.Warning)
     db.clear_deferred_sql()
     db.start_transaction()
示例#3
0
def innodb_ready_rename_column(orm, models, table, old_column_name,
                               new_column_name, app_model, new_field_name):
    """
    Foreign key renaming which works for InnoDB
    More: http://south.aeracode.org/ticket/466

    Parameters:
    - orm: a reference to 'orm' parameter passed to Migration.forwards()/backwards()
    - models: reference to Migration.models data structure
    - table: e.g. 'askbot_thread'
    - old_column_name: e.g. 'question_post_id'
    - new_column_name: e.g. 'question_id'
    - app_model: e.g. 'askbot.thread' (should be a dict key into 'models')
    - new_field_name: e.g. 'question' (usually it's same as new_column_name, only without trailing '_id')
    """
    use_workaround = houston_do_we_have_a_problem(table)

    # ditch the foreign key
    if use_workaround:
        db.delete_foreign_key(table, old_column_name)

    # rename column
    db.rename_column(table, old_column_name, new_column_name)

    # restore the foreign key
    if not use_workaround:
        return

    model_def = models[app_model][new_field_name]
    assert model_def[0] == 'django.db.models.fields.related.ForeignKey'
    # Copy the dict so that we don't change the original
    # (otherwise the dry run would change it for the "normal" run
    #  and the latter would try to convert str to model once again)
    fkey_params = model_def[2].copy()
    assert 'to' in fkey_params
    assert fkey_params['to'].startswith("orm['")
    assert fkey_params['to'].endswith("']")
    fkey_params['to'] = orm[fkey_params['to'][
        5:-2]]  # convert "orm['app.models']" string to actual model
    field = ask_for_it_by_name(model_def[0])(**fkey_params)
    # INFO: ask_for_it_by_name() if equivalent to self.gf() which is usually used in migrations, e.g.:
    #          db.alter_column('askbot_badgedata', 'slug', self.gf('django.db.models.fields.SlugField')(unique=True, max_length=50))
    db.alter_column(table, new_column_name, field)
    db.clear_deferred_sql()
示例#4
0
def innodb_ready_rename_column(orm, models, table, old_column_name, new_column_name, app_model, new_field_name):
    """
    Foreign key renaming which works for InnoDB
    More: http://south.aeracode.org/ticket/466

    Parameters:
    - orm: a reference to 'orm' parameter passed to Migration.forwards()/backwards()
    - models: reference to Migration.models data structure
    - table: e.g. 'askbot_thread'
    - old_column_name: e.g. 'question_post_id'
    - new_column_name: e.g. 'question_id'
    - app_model: e.g. 'askbot.thread' (should be a dict key into 'models')
    - new_field_name: e.g. 'question' (usually it's same as new_column_name, only without trailing '_id')
    """
    use_workaround = houston_do_we_have_a_problem(table)

    # ditch the foreign key
    if use_workaround:
        db.delete_foreign_key(table, old_column_name)

    # rename column
    db.rename_column(table, old_column_name, new_column_name)

    # restore the foreign key
    if not use_workaround:
        return

    model_def = models[app_model][new_field_name]
    assert model_def[0] == "django.db.models.fields.related.ForeignKey"
    # Copy the dict so that we don't change the original
    # (otherwise the dry run would change it for the "normal" run
    #  and the latter would try to convert str to model once again)
    fkey_params = model_def[2].copy()
    assert "to" in fkey_params
    assert fkey_params["to"].startswith("orm['")
    assert fkey_params["to"].endswith("']")
    fkey_params["to"] = orm[fkey_params["to"][5:-2]]  # convert "orm['app.models']" string to actual model
    field = ask_for_it_by_name(model_def[0])(**fkey_params)
    # INFO: ask_for_it_by_name() if equivalent to self.gf() which is usually used in migrations, e.g.:
    #          db.alter_column('askbot_badgedata', 'slug', self.gf('django.db.models.fields.SlugField')(unique=True, max_length=50))
    db.alter_column(table, new_column_name, field)
    db.clear_deferred_sql()
示例#5
0
文件: db.py 项目: TradeHill2011/south
 def setUp(self):
     db.debug = False
     db.clear_deferred_sql()
     db.start_transaction()
示例#6
0
文件: db_mysql.py 项目: KMhook/istweb
 def setUp(self):
     db.debug = False
     db.clear_deferred_sql()
示例#7
0
文件: db.py 项目: daasara/riba
 def setUp(self):
     db.debug = False
     db.clear_deferred_sql()
     db.start_transaction()
示例#8
0
文件: db_mysql.py 项目: intabeta/inta
 def setUp(self):
     db.debug = False
     db.clear_deferred_sql()