Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persist data during event-api/down migration #877

Merged
merged 2 commits into from
Dec 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions core/payment/migrations/2020-12-11-123456_event_api/down.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
DROP TABLE pay_allocation;

CREATE TABLE pay_allocation(
-- HACK: All this code below is just to drop column timestamp from table pay_allocation

PRAGMA foreign_keys=off;

CREATE TABLE pay_allocation_tmp(
id VARCHAR(50) NOT NULL PRIMARY KEY,
owner_id VARCHAR(50) NOT NULL,
payment_platform VARCHAR(50) NOT NULL,
Expand All @@ -13,9 +16,15 @@ CREATE TABLE pay_allocation(
released BOOLEAN NOT NULL DEFAULT FALSE
);

-- HACK: All this code below is just to drop column app_session_id from table pay_agreement
INSERT INTO pay_allocation_tmp(id, owner_id, payment_platform, address, total_amount, spent_amount, remaining_amount, timeout, make_deposit, released)
SELECT id, owner_id, payment_platform, address, total_amount, spent_amount, remaining_amount, timeout, make_deposit, released FROM pay_allocation;

PRAGMA foreign_keys=off;

DROP TABLE pay_allocation;

ALTER TABLE pay_allocation_tmp RENAME TO pay_allocation;

-- HACK: All this code below is just to drop column app_session_id from table pay_agreement

CREATE TABLE pay_agreement_tmp(
id VARCHAR(50) NOT NULL,
Expand All @@ -32,8 +41,8 @@ CREATE TABLE pay_agreement_tmp(
UNIQUE (id, role)
);

INSERT INTO pay_agreement_tmp(id, owner_id, role, peer_id, payee_addr, payer_addr, payment_platform, total_amount_due, total_amount_accepted, total_amount_accepted)
SELECT id, owner_id, role, peer_id, payee_addr, payer_addr, payment_platform, total_amount_due, total_amount_accepted, total_amount_accepted FROM pay_agreement;
INSERT INTO pay_agreement_tmp(id, owner_id, role, peer_id, payee_addr, payer_addr, payment_platform, total_amount_due, total_amount_accepted, total_amount_paid)
SELECT id, owner_id, role, peer_id, payee_addr, payer_addr, payment_platform, total_amount_due, total_amount_accepted, total_amount_paid FROM pay_agreement;

DROP TABLE pay_agreement;

Expand Down