"""Delete foreign keys from ledger tables.""" import mysql.connector def db_royalty_accounting_connector(): """Connector to the royalty_accounting db (docker).""" cnx = mysql.connector.connect( host='sync-contract-mysql', port='3306', database='royalty_accounting', user='db_user', password='db_pass', ) return cnx cnx = db_royalty_accounting_connector() 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 accounting_period DROP FOREIGN KEY fk_statement_period_acct_period; """ ) cnx.close() print('Foreign keys were deleted from ledger tables')