"""lowercase and fastapi Revision ID: eed0b382c287 Revises: 0bf3d70ee7de Create Date: 2020-05-10 19:52:58.163810 """ import sqlalchemy as sa from alembic import op from sqlalchemy import column, select, table from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. revision = "eed0b382c287" down_revision = "0bf3d70ee7de" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.drop_table("msg_subscribers") op.drop_table("msg_posts") op.drop_table("msg_threadtags") op.drop_table("msg_threads") op.drop_table("msg_tags") op.rename_table("auth_roles", "auth_permissions") with op.batch_alter_table("auth_permissions") as batch_op: batch_op.alter_column("RoleID", new_column_name="id") batch_op.alter_column("Name", new_column_name="name") op.rename_table("auth_groups", "auth_roles") with op.batch_alter_table("auth_roles") as batch_op: batch_op.alter_column("GroupID", new_column_name="id") batch_op.alter_column("Name", new_column_name="name") op.rename_table("auth_rolegroups", "role_permissions") with op.batch_alter_table("role_permissions") as batch_op: batch_op.alter_column("RoleGroupID", new_column_name="id") batch_op.alter_column("RoleID", new_column_name="permission_id") batch_op.alter_column("GroupID", new_column_name="role_id") op.rename_table("auth_usergroups", "user_roles") with op.batch_alter_table("user_roles") as batch_op: batch_op.alter_column("UserGroupID", new_column_name="id") batch_op.alter_column("UserID", new_column_name="user_id") batch_op.alter_column("GroupID", new_column_name="role_id") with op.batch_alter_table("attendances") as batch_op: batch_op.alter_column("Amount", new_column_name="amount") batch_op.alter_column("UserID", new_column_name="user_id") batch_op.alter_column("AttendanceType", new_column_name="attendance_type") batch_op.alter_column("CreationDate", new_column_name="creation_date") batch_op.alter_column("Date", new_column_name="date", type_=sa.Date(), nullable=False) batch_op.alter_column("EmployeeID", new_column_name="employee_id") batch_op.alter_column("AttendanceID", new_column_name="id") batch_op.alter_column("IsValid", new_column_name="is_valid") with op.batch_alter_table("auth_users") as batch_op: batch_op.alter_column("UserID", new_column_name="id") batch_op.alter_column("Name", new_column_name="username") batch_op.alter_column("Password", new_column_name="password") batch_op.alter_column("LockedOut", new_column_name="disabled") with op.batch_alter_table("batches") as batch_op: batch_op.alter_column("BatchID", new_column_name="id") batch_op.alter_column("Discount", new_column_name="discount") batch_op.alter_column("Name", new_column_name="name", type_=sa.Date(), nullable=False) batch_op.alter_column("ProductID", new_column_name="product_id") batch_op.alter_column("QuantityRemaining", new_column_name="quantity_remaining") batch_op.alter_column("Rate", new_column_name="rate") batch_op.alter_column("Tax", new_column_name="tax") with op.batch_alter_table("cost_centres") as batch_op: batch_op.alter_column("CostCentreID", new_column_name="id") batch_op.alter_column("Name", new_column_name="name") batch_op.alter_column("IsFixture", new_column_name="is_fixture") with op.batch_alter_table("product_groups") as batch_op: batch_op.alter_column("ProductGroupID", new_column_name="id") batch_op.alter_column("Name", new_column_name="name") batch_op.alter_column("IsFixture", new_column_name="is_fixture") with op.batch_alter_table("inventories") as batch_op: batch_op.alter_column("InventoryID", new_column_name="id") batch_op.alter_column("BatchID", new_column_name="batch_id") batch_op.alter_column("Discount", new_column_name="discount") batch_op.alter_column("ProductID", new_column_name="product_id") batch_op.alter_column("Quantity", new_column_name="quantity") batch_op.alter_column("Rate", new_column_name="rate") batch_op.alter_column("Tax", new_column_name="tax") batch_op.alter_column("VoucherID", new_column_name="voucher_id") with op.batch_alter_table("journals") as batch_op: batch_op.alter_column("Amount", new_column_name="amount") batch_op.alter_column("CostCentreID", new_column_name="cost_centre_id") batch_op.alter_column("Debit", new_column_name="debit") batch_op.alter_column("JournalID", new_column_name="id") batch_op.alter_column("VoucherID", new_column_name="voucher_id") with op.batch_alter_table("fingerprints") as batch_op: batch_op.alter_column("FingerprintID", new_column_name="id") batch_op.alter_column("Date", new_column_name="date") batch_op.alter_column("EmployeeID", new_column_name="employee_id") with op.batch_alter_table("products") as batch_op: batch_op.alter_column("ProductID", new_column_name="id") batch_op.alter_column("Code", new_column_name="code") batch_op.alter_column("Fraction", new_column_name="fraction") batch_op.alter_column("FractionUnits", new_column_name="fraction_units") batch_op.alter_column("IsActive", new_column_name="is_active") batch_op.alter_column("IsFixture", new_column_name="is_fixture") batch_op.alter_column("Name", new_column_name="name") batch_op.alter_column("ProductGroupID", new_column_name="product_group_id") batch_op.alter_column("ProductYield", new_column_name="product_yield") batch_op.alter_column("Units", new_column_name="units") with op.batch_alter_table("recipes") as batch_op: batch_op.alter_column("recipe_id", new_column_name="id") op.rename_table("salary_deductions", "employee_benefit") with op.batch_alter_table("employee_benefit") as batch_op: batch_op.alter_column("SalaryDeductionID", new_column_name="id") batch_op.alter_column("DaysWorked", new_column_name="days_worked") batch_op.alter_column("EsiEmployee", new_column_name="esi_employee") batch_op.alter_column("EsiEmployer", new_column_name="esi_employer") batch_op.alter_column("GrossSalary", new_column_name="gross_salary") batch_op.alter_column("JournalID", new_column_name="journal_id") batch_op.alter_column("PfEmployee", new_column_name="pf_employee") batch_op.alter_column("PfEmployer", new_column_name="pf_employer") batch_op.alter_column("VoucherID", new_column_name="voucher_id") with op.batch_alter_table("vouchers") as batch_op: batch_op.alter_column("VoucherID", new_column_name="id") batch_op.alter_column("date", type_=sa.Date(), nullable=False) batch_op.alter_column("reconcile_date", type_=sa.Date(), nullable=False) op.rename_table("service_charges", "incentives") with op.batch_alter_table("employees") as batch_op: batch_op.alter_column("Designation", new_column_name="designation", nullable=False) batch_op.alter_column("Salary", new_column_name="salary", nullable=False) batch_op.alter_column("ServicePoints", new_column_name="points", nullable=False) batch_op.alter_column( "JoiningDate", new_column_name="joining_date", type_=sa.Date(), nullable=False, ) batch_op.alter_column( "LeavingDate", new_column_name="leaving_date", type_=sa.Date(), nullable=True, ) with op.batch_alter_table("settings") as batch_op: batch_op.alter_column("SettingID", new_column_name="id") batch_op.alter_column("Name", new_column_name="name") batch_op.alter_column("Data", new_column_name="data") op.create_unique_constraint(op.f("uq_accounts_name"), "accounts", ["name"]) op.drop_constraint("accounts_name_key", "accounts", type_="unique") op.create_unique_constraint(op.f("uq_auth_clients_code"), "auth_clients", ["code"]) op.create_unique_constraint(op.f("uq_auth_clients_name"), "auth_clients", ["name"]) op.drop_constraint("auth_clients_Code_key", "auth_clients", type_="unique") op.drop_constraint("auth_clients_Name_key", "auth_clients", type_="unique") op.create_unique_constraint( op.f("uq_auth_login_history_user_id"), "auth_login_history", ["user_id", "client_id", "date"], ) op.drop_constraint( "auth_login_history_user_id_client_id_date_key", "auth_login_history", type_="unique", ) op.create_unique_constraint(op.f("uq_auth_permissions_name"), "auth_permissions", ["name"]) op.drop_constraint("auth_roles_Name_key", "auth_permissions", type_="unique") op.create_unique_constraint(op.f("uq_auth_roles_name"), "auth_roles", ["name"]) op.drop_constraint("auth_groups_Name_key", "auth_roles", type_="unique") op.create_unique_constraint(op.f("uq_auth_users_username"), "auth_users", ["username"]) op.drop_constraint("auth_users_Name_key", "auth_users", type_="unique") op.create_unique_constraint(op.f("uq_cost_centres_name"), "cost_centres", ["name"]) op.drop_constraint("entities_costcenters_Name_key", "cost_centres", type_="unique") op.drop_constraint("uq_employee_id_date", "fingerprints", type_="unique") op.create_index(op.f("ix_inventories_voucher_id"), "inventories", ["voucher_id"], unique=False) op.create_unique_constraint(op.f("uq_inventories_voucher_id"), "inventories", ["voucher_id", "batch_id"]) op.drop_index("ix_inventories_VoucherID", table_name="inventories") op.create_index(op.f("ix_journals_voucher_id"), "journals", ["voucher_id"], unique=False) op.drop_index("ix_journals_VoucherID", table_name="journals") op.create_unique_constraint(op.f("uq_product_groups_name"), "product_groups", ["name"]) op.drop_constraint("entities_productgroups_Name_key", "product_groups", type_="unique") op.create_unique_constraint(op.f("uq_products_code"), "products", ["code"]) op.create_unique_constraint(op.f("uq_products_name"), "products", ["name", "units"]) op.drop_constraint("products_Code_key", "products", type_="unique") op.drop_constraint("products_Name_Units_key", "products", type_="unique") op.create_unique_constraint(op.f("uq_recipe_items_recipe_id"), "recipe_items", ["recipe_id", "product_id"]) op.drop_constraint("recipe_items_recipe_id_product_id_key", "recipe_items", type_="unique") op.create_unique_constraint(op.f("uq_settings_name"), "settings", ["name"]) op.drop_constraint("settings_Name_key", "settings", type_="unique") op.create_index(op.f("ix_vouchers_date"), "vouchers", ["date"], unique=False) op.create_foreign_key( "fk_incentives_journal_id_journals", "incentives", "journals", ["journal_id"], ["id"], ) op.create_foreign_key( "fk_incentives_voucher_id_vouchers", "incentives", "vouchers", ["voucher_id"], ["id"], ) op.drop_constraint("service_charges_journal_id_fkey", "incentives", type_="foreignkey") op.drop_constraint("service_charges_voucher_id_fkey", "incentives", type_="foreignkey") op.create_foreign_key( "fk_employee_benefit_journal_id_journals", "employee_benefit", "journals", ["journal_id"], ["id"], ) op.create_foreign_key( "fk_employee_benefit_voucher_id_vouchers", "employee_benefit", "vouchers", ["voucher_id"], ["id"], ) op.drop_constraint( "entities_salarydeductions_JournalID_fkey", "employee_benefit", type_="foreignkey", ) op.drop_constraint("salary_deductions_VoucherID_fkey", "employee_benefit", type_="foreignkey") permission = table("auth_permissions", column("id", postgresql.UUID()), column("name", sa.String)) op.execute( permission.update() .where(permission.c.name == op.inline_literal("Service Charge")) .values({"name": op.inline_literal("Incentive")}) ) op.execute( permission.update() .where(permission.c.name == op.inline_literal("Salary Deduction")) .values({"name": op.inline_literal("Employee Benefit")}) ) account = table("accounts", column("name", sa.String)) op.execute( account.update() .where(account.c.name == op.inline_literal("Service Charges")) .values({"name": op.inline_literal("Incentives")}) ) # Remove unneeded Payment and Receipt permissions permission = table("auth_permissions", column("id", postgresql.UUID()), column("name", sa.String)) role_permission = table( "role_permissions", column("permission_id", postgresql.UUID()), column("role_id", postgresql.UUID()), ) op.execute( role_permission.delete().where( role_permission.c.permission_id.in_( select([permission.c.id], permission.c.name.in_(["Payment", "Receipt"])) ) ) ) op.execute(permission.delete().where(permission.c.name.in_(["Payment", "Receipt"]))) ### end Alembic commands ### def downgrade(): raise Exception("Irreversible migration")