Skip to content

Commit

Permalink
chore: update sql queries for v2 and run migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
kashif-m committed Jan 10, 2025
1 parent 7979986 commit f33ed66
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 14 deletions.
8 changes: 4 additions & 4 deletions crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ diesel::table! {
capture_sequence -> Int2,
#[max_length = 128]
connector_response_reference_id -> Nullable<Varchar>,
#[max_length = 512]
#[max_length = 1024]
connector_capture_data -> Nullable<Varchar>,
}
}
Expand Down Expand Up @@ -886,7 +886,7 @@ diesel::table! {
card_network -> Nullable<Varchar>,
shipping_cost -> Nullable<Int8>,
order_tax_amount -> Nullable<Int8>,
#[max_length = 512]
#[max_length = 1024]
connector_transaction_data -> Nullable<Varchar>,
connector_mandate_detail -> Nullable<Jsonb>,
}
Expand Down Expand Up @@ -1230,9 +1230,9 @@ diesel::table! {
charges -> Nullable<Jsonb>,
#[max_length = 32]
organization_id -> Varchar,
#[max_length = 512]
#[max_length = 1024]
connector_refund_data -> Nullable<Varchar>,
#[max_length = 512]
#[max_length = 1024]
connector_transaction_data -> Nullable<Varchar>,
split_refunds -> Nullable<Jsonb>,
#[max_length = 255]
Expand Down
8 changes: 4 additions & 4 deletions crates/diesel_models/src/schema_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ diesel::table! {
capture_sequence -> Int2,
#[max_length = 128]
connector_response_reference_id -> Nullable<Varchar>,
#[max_length = 512]
#[max_length = 1024]
connector_capture_data -> Nullable<Varchar>,
}
}
Expand Down Expand Up @@ -852,7 +852,7 @@ diesel::table! {
tax_on_surcharge -> Nullable<Int8>,
payment_method_billing_address -> Nullable<Bytea>,
redirection_data -> Nullable<Jsonb>,
#[max_length = 512]
#[max_length = 1024]
connector_payment_data -> Nullable<Varchar>,
#[max_length = 64]
id -> Varchar,
Expand Down Expand Up @@ -1176,9 +1176,9 @@ diesel::table! {
charges -> Nullable<Jsonb>,
#[max_length = 32]
organization_id -> Varchar,
#[max_length = 512]
#[max_length = 1024]
connector_refund_data -> Nullable<Varchar>,
#[max_length = 512]
#[max_length = 1024]
connector_transaction_data -> Nullable<Varchar>,
split_refunds -> Nullable<Jsonb>,
#[max_length = 255]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,51 @@
ALTER TABLE payment_attempt ALTER COLUMN connector_transaction_data TYPE VARCHAR(1024);
ALTER TABLE refund ALTER COLUMN connector_refund_data TYPE VARCHAR(1024);
ALTER TABLE refund ALTER COLUMN connector_transaction_data TYPE VARCHAR(1024);
ALTER TABLE captures ALTER COLUMN connector_capture_data TYPE VARCHAR(1024);
DO $$
BEGIN
IF EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_name = 'payment_attempt'
AND column_name = 'connector_transaction_data'
) THEN
ALTER TABLE payment_attempt
ALTER COLUMN connector_transaction_data TYPE VARCHAR(1024);
END IF;
END $$;

DO $$
BEGIN
IF EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_name = 'refund'
AND column_name = 'connector_refund_data'
) THEN
ALTER TABLE refund
ALTER COLUMN connector_refund_data TYPE VARCHAR(1024);
END IF;
END $$;

DO $$
BEGIN
IF EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_name = 'refund'
AND column_name = 'connector_transaction_data'
) THEN
ALTER TABLE refund
ALTER COLUMN connector_transaction_data TYPE VARCHAR(1024);
END IF;
END $$;

DO $$
BEGIN
IF EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_name = 'captures'
AND column_name = 'connector_capture_data'
) THEN
ALTER TABLE captures
ALTER COLUMN connector_capture_data TYPE VARCHAR(1024);
END IF;
END $$;
2 changes: 1 addition & 1 deletion v2_migrations/2024-08-28-081721_add_v2_columns/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ADD COLUMN payment_method_type_v2 VARCHAR,
ADD COLUMN tax_on_surcharge BIGINT,
ADD COLUMN payment_method_billing_address BYTEA,
ADD COLUMN redirection_data JSONB,
ADD COLUMN connector_payment_data VARCHAR(512);
ADD COLUMN connector_payment_data VARCHAR(1024);

-- Change the type of the column from JSON to JSONB
ALTER TABLE merchant_connector_account
Expand Down
2 changes: 1 addition & 1 deletion v2_migrations/2024-10-08-081847_drop_v1_columns/down.sql
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ADD COLUMN IF NOT EXISTS attempt_id VARCHAR(64) NOT NULL,
ADD COLUMN offer_amount bigint,
ADD COLUMN payment_method VARCHAR,
ADD COLUMN connector_transaction_id VARCHAR(64),
ADD COLUMN connector_transaction_data VARCHAR(512),
ADD COLUMN connector_transaction_data VARCHAR(1024),
ADD COLUMN capture_method "CaptureMethod",
ADD COLUMN capture_on TIMESTAMP,
ADD COLUMN mandate_id VARCHAR(64),
Expand Down

0 comments on commit f33ed66

Please sign in to comment.