コード例 #1
0
def clean_database():
    """
    Remove obsolete tables and columns
    """
    disable_constraints()
    op.drop_table('cae_situation_change')
    op.drop_table('contract_history')
    op.drop_table('date_convention_cape_datas')
    op.drop_table('date_diagnostic_datas')
    op.drop_table('date_dpae_datas')
    op.drop_constraint('fk_user_datas_parcours_employee_quality_id', 'user_datas', type_='foreignkey')
    op.drop_constraint('fk_user_datas_sortie_motif_id', 'user_datas', type_='foreignkey')
    op.drop_constraint('fk_user_datas_sortie_type_id', 'user_datas', type_='foreignkey')
    op.drop_column('user_datas', 'parcours_contract_type',)
    op.drop_column('user_datas', 'parcours_start_date',)
    op.drop_column('user_datas', 'parcours_end_date',)
    op.drop_column('user_datas', 'parcours_last_avenant',)
    op.drop_column('user_datas', 'parcours_taux_horaire',)
    op.drop_column('user_datas', 'parcours_taux_horaire_letters',)
    op.drop_column('user_datas', 'parcours_num_hours',)
    op.drop_column('user_datas', 'parcours_salary',)
    op.drop_column('user_datas', 'parcours_salary_letters',)
    op.drop_column('user_datas', 'parcours_employee_quality_id',)
    op.drop_column('user_datas', 'sortie_date',)
    op.drop_column('user_datas', 'sortie_motif_id',)
    op.drop_column('user_datas', 'sortie_type_id',)
    enable_constraints()
def clean_database():
    """
    Remove obsolete tables and columns
    """
    disable_constraints()
    op.drop_table('cae_situation_change')
    op.drop_table('contract_history')
    op.drop_table('date_convention_cape_datas')
    op.drop_table('date_diagnostic_datas')
    op.drop_table('date_dpae_datas')
    op.drop_constraint('fk_user_datas_parcours_employee_quality_id', 'user_datas', type_='foreignkey')
    if column_exists('user_datas', 'sortie_motif_id'):
        try:
            op.drop_constraint('fk_user_datas_sortie_motif_id', 'user_datas', type_='foreignkey')
        except:
            pass
        op.drop_column('user_datas', 'sortie_motif_id',)

    if column_exists('user_datas', 'sortie_type_id'):
        try:
            op.drop_constraint('fk_user_datas_sortie_type_id', 'user_datas', type_='foreignkey')
        except:
            pass
        op.drop_column('user_datas', 'sortie_type_id',)

    for column in (
        ('user_datas', 'parcours_contract_type',),
        ('user_datas', 'parcours_start_date',),
        ('user_datas', 'parcours_end_date',),
        ('user_datas', 'parcours_last_avenant',),
        ('user_datas', 'parcours_taux_horaire',),
        ('user_datas', 'parcours_taux_horaire_letters',),
        ('user_datas', 'parcours_num_hours',),
        ('user_datas', 'parcours_salary',),
        ('user_datas', 'parcours_salary_letters',),
        ('user_datas', 'parcours_employee_quality_id',),
        ('user_datas', 'sortie_date',),
        ('user_datas', 'sortie_motif_id',),
    ):
        if column_exists('user_datas', column):
            op.drop_column('user_datas', column)
    enable_constraints()
def upgrade():
    disable_constraints()
    for table in OLD_TABLES:
        if table_exists(table):
            op.drop_table(table)

    op.alter_column('accounts',
                    'active',
                    existing_type=mysql.VARCHAR(length=1),
                    nullable=False,
                    existing_server_default=sa.text(u"'Y'"))
    op.alter_column('accounts',
                    'email',
                    existing_type=mysql.VARCHAR(length=100),
                    nullable=False)
    op.alter_column('accounts',
                    'firstname',
                    existing_type=mysql.VARCHAR(length=50),
                    nullable=False)
    op.alter_column('accounts',
                    'lastname',
                    existing_type=mysql.VARCHAR(length=50),
                    nullable=False)
    op.alter_column('company',
                    'active',
                    existing_type=mysql.VARCHAR(length=1),
                    nullable=False,
                    existing_server_default=sa.text(u"'Y'"))
    op.alter_column('company',
                    'creationDate',
                    existing_type=mysql.INTEGER(display_width=11),
                    nullable=False)
    op.alter_column('company',
                    'name',
                    existing_type=mysql.VARCHAR(length=150),
                    nullable=False)
    op.alter_column('company',
                    'object',
                    existing_type=mysql.VARCHAR(length=255),
                    nullable=True)
    op.alter_column('company',
                    'phone',
                    existing_type=mysql.VARCHAR(length=20),
                    nullable=True)
    op.alter_column('company',
                    'updateDate',
                    existing_type=mysql.INTEGER(display_width=11),
                    nullable=False)
    op.alter_column('company_employee',
                    'account_id',
                    existing_type=mysql.INTEGER(display_width=11),
                    nullable=False)
    op.alter_column('company_employee',
                    'company_id',
                    existing_type=mysql.INTEGER(display_width=11),
                    nullable=False)
    op.alter_column('customer',
                    'address',
                    existing_type=mysql.TEXT(),
                    nullable=False)
    op.alter_column('customer',
                    'city',
                    existing_type=mysql.VARCHAR(length=255),
                    nullable=False)
    op.alter_column('customer',
                    'company_id',
                    existing_type=mysql.INTEGER(display_width=11),
                    nullable=True)
    op.alter_column('configurable_option',
                    'label',
                    existing_type=mysql.VARCHAR(length=100),
                    nullable=False)
    op.alter_column('customer',
                    'contactLastName',
                    existing_type=mysql.VARCHAR(length=255),
                    nullable=False)
    op.alter_column('customer',
                    'creationDate',
                    existing_type=mysql.INTEGER(display_width=11),
                    nullable=False)
    op.alter_column('customer',
                    'name',
                    existing_type=mysql.VARCHAR(length=255),
                    nullable=False)
    op.alter_column('customer',
                    'updateDate',
                    existing_type=mysql.INTEGER(display_width=11),
                    nullable=False)
    op.alter_column('customer',
                    'zipCode',
                    existing_type=mysql.VARCHAR(length=20),
                    nullable=False)
    op.alter_column('estimation',
                    'deposit',
                    existing_type=mysql.INTEGER(display_width=11),
                    nullable=True,
                    existing_server_default=sa.text(u"'0'"))
    # Clean table
    for (table, column) in OLD_COLUMNS:
        if column_exists(table, column):
            op.drop_column(table, column)

    enable_constraints()
コード例 #4
0
def upgrade():
    disable_constraints()
    update_database_structure()
    migrate_datas()
    clean_database()
    enable_constraints()
def upgrade():
    disable_constraints()
    for table in OLD_TABLES:
        if table_exists(table):
            op.drop_table(table)

    op.alter_column('accounts', 'active',
               existing_type=mysql.VARCHAR(length=1),
               nullable=False,
               existing_server_default=sa.text(u"'Y'"))
    op.alter_column('accounts', 'email',
               existing_type=mysql.VARCHAR(length=100),
               nullable=False)
    op.alter_column('accounts', 'firstname',
               existing_type=mysql.VARCHAR(length=50),
               nullable=False)
    op.alter_column('accounts', 'lastname',
               existing_type=mysql.VARCHAR(length=50),
               nullable=False)
    op.alter_column('company', 'active',
               existing_type=mysql.VARCHAR(length=1),
               nullable=False,
               existing_server_default=sa.text(u"'Y'"))
    op.alter_column('company', 'creationDate',
               existing_type=mysql.INTEGER(display_width=11),
               nullable=False)
    op.alter_column('company', 'name',
               existing_type=mysql.VARCHAR(length=150),
               nullable=False)
    op.alter_column('company', 'object',
               existing_type=mysql.VARCHAR(length=255),
               nullable=True)
    op.alter_column('company', 'phone',
               existing_type=mysql.VARCHAR(length=20),
               nullable=True)
    op.alter_column('company', 'updateDate',
               existing_type=mysql.INTEGER(display_width=11),
               nullable=False)
    op.alter_column('company_employee', 'account_id',
               existing_type=mysql.INTEGER(display_width=11),
               nullable=False)
    op.alter_column('company_employee', 'company_id',
               existing_type=mysql.INTEGER(display_width=11),
               nullable=False)
    op.alter_column('customer', 'address',
               existing_type=mysql.TEXT(),
               nullable=False)
    op.alter_column('customer', 'city',
               existing_type=mysql.VARCHAR(length=255),
               nullable=False)
    op.alter_column('customer', 'company_id',
               existing_type=mysql.INTEGER(display_width=11),
               nullable=True)
    op.alter_column('configurable_option', 'label',
               existing_type=mysql.VARCHAR(length=100),
               nullable=False)
    op.alter_column('customer', 'contactLastName',
               existing_type=mysql.VARCHAR(length=255),
               nullable=False)
    op.alter_column('customer', 'creationDate',
               existing_type=mysql.INTEGER(display_width=11),
               nullable=False)
    op.alter_column('customer', 'name',
               existing_type=mysql.VARCHAR(length=255),
               nullable=False)
    op.alter_column('customer', 'updateDate',
               existing_type=mysql.INTEGER(display_width=11),
               nullable=False)
    op.alter_column('customer', 'zipCode',
               existing_type=mysql.VARCHAR(length=20),
               nullable=False)
    op.alter_column('estimation', 'deposit',
               existing_type=mysql.INTEGER(display_width=11),
               nullable=True,
               existing_server_default=sa.text(u"'0'"))
    # Clean table
    for (table, column) in OLD_COLUMNS:
        if column_exists(table, column):
            op.drop_column(table, column)

    enable_constraints()