"""Delete foreign keys from ledger tables.""" import mysql.connector def mysqlclient_docker(): """Initialize mysql client for docker image.""" return mysql.connector.connect( host='payoneer-payments-payout-mysql', port='3306', database='royalty_accounting', user='db_user', password='db_pass' ) cnx = mysqlclient_docker() cursor = cnx.cursor() cursor.execute( 'ALTER TABLE accounting_run DROP FOREIGN KEY fk_acct_run_acct_period;') cursor.execute( 'ALTER TABLE accounting_run DROP FOREIGN KEY fk_acc_run_run_ctrl;') cursor.execute( 'ALTER TABLE ledger_deposit DROP FOREIGN KEY fk_contract_ledger_deposit;') cursor.execute( 'ALTER TABLE ledger_deposit DROP FOREIGN KEY fk_ledger_deposit_account;') cursor.execute('ALTER TABLE ledger_account DROP FOREIGN KEY fk_ledger_account_account;') cursor.execute( 'ALTER TABLE ledger_account DROP FOREIGN KEY fk_ledger_account_contract;' ) cursor.execute( """ ALTER TABLE ledger_account_current_balance DROP FOREIGN KEY fk_ledger_account_current_balance_ledger_account_; """ ) cursor.execute( """ ALTER TABLE ledger_account_current_balance DROP FOREIGN KEY fk_ledger_account_current_balance_account; """ ) cursor.execute( """ ALTER TABLE payment_group_payment_account DROP FOREIGN KEY fk_group_account_account; """ ) cursor.execute( """ ALTER TABLE payment_group_payment_account DROP FOREIGN KEY fk_payment_account_current_statement_period; """ ) cursor.execute( """ ALTER TABLE payment_group_payment_batch_account DROP FOREIGN KEY fk_payment_batch_account_payment_group_payment_batch; """ ) cursor.execute( """ ALTER TABLE abacus_state_history DROP FOREIGN KEY fk_abacus_state_history; """ ) cnx.close() print('Foreign keys were deleted from ledger tables')