Skip to content

Commit

Permalink
[SDP-1382] Remove countries from the flow and delete any reference to…
Browse files Browse the repository at this point in the history
… it from the database (#455)

### What

Remove countries from the flow and delete any reference to it from the database

### Why

It's not needed in the flow anymore.
Addresses https://stellarorg.atlassian.net/browse/SDP-1382.
  • Loading branch information
marcelosalloum authored Nov 2, 2024
1 parent 9d0d720 commit e824a74
Show file tree
Hide file tree
Showing 48 changed files with 652 additions and 1,057 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ BEGIN
ALTER COLUMN verification_field DROP DEFAULT,
ALTER COLUMN verification_field TYPE %I.verification_type
USING verification_field::text::%I.verification_type,
ADD COLUMN IF NOT EXISTS registration_contact_type %I.registration_contact_types NOT NULL DEFAULT ''PHONE_NUMBER'';
ADD COLUMN IF NOT EXISTS registration_contact_type %I.registration_contact_types NOT NULL DEFAULT ''PHONE_NUMBER'',
DROP COLUMN IF EXISTS country_code CASCADE;
INSERT INTO %I.disbursements SELECT * FROM public.disbursements;
ALTER TABLE public.payments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ ALTER TABLE disbursements ALTER COLUMN country_code SET NOT NULL;
CREATE TRIGGER refresh_country_updated_at BEFORE UPDATE ON countries FOR EACH ROW EXECUTE PROCEDURE update_at_refresh();

-- +migrate Down
DROP TRIGGER refresh_country_updated_at ON countries;

ALTER TABLE disbursements DROP COLUMN country_code;
ALTER TABLE disbursements DROP COLUMN country_code CASCADE;

DROP TABLE countries CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
-- This migration drops the countries table and any references to it.

-- +migrate Up
ALTER TABLE disbursements
DROP COLUMN country_code;

DROP TABLE countries CASCADE;


-- +migrate Down
CREATE TABLE countries (
code VARCHAR(3) PRIMARY KEY,
name VARCHAR(100) NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
deleted_at TIMESTAMP WITH TIME ZONE,
UNIQUE (name),
CONSTRAINT country_code_length_check CHECK (char_length(code) = 3)
);

INSERT INTO countries
(code, name)
VALUES
('AFG', 'Afghanistan'),
('ALB', 'Albania'),
('DZA', 'Algeria'),
('ASM', 'American Samoa'),
('AND', 'Andorra'),
('AGO', 'Angola'),
('ATG', 'Antigua and Barbuda'),
('ARG', 'Argentina'),
('ARM', 'Armenia'),
('ABW', 'Aruba'),
('AUS', 'Australia'),
('AUT', 'Austria'),
('AZE', 'Azerbaijan'),
('BHS', 'Bahamas'),
('BHR', 'Bahrain'),
('BGD', 'Bangladesh'),
('BRB', 'Barbados'),
('BLR', 'Belarus'),
('BEL', 'Belgium'),
('BLZ', 'Belize'),
('BEN', 'Benin'),
('BMU', 'Bermuda'),
('BTN', 'Bhutan'),
('BOL', 'Bolivia'),
('BIH', 'Bosnia and Herzegovina'),
('BWA', 'Botswana'),
('BRA', 'Brazil'),
('BRN', 'Brunei'),
('BGR', 'Bulgaria'),
('BFA', 'Burkina Faso'),
('BDI', 'Burundi'),
('CPV', 'Cabo Verde'),
('KHM', 'Cambodia'),
('CMR', 'Cameroon'),
('CAN', 'Canada'),
('CAF', 'Central African Republic'),
('TCD', 'Chad'),
('CHL', 'Chile'),
('CHN', 'China'),
('COL', 'Colombia'),
('COM', 'Comoros (the)'),
('COG', 'Congo (the)'),
('COK', 'Cook Islands (the)'),
('CRI', 'Costa Rica'),
('HRV', 'Croatia'),
('CYP', 'Cyprus'),
('CZE', 'Czechia'),
('CIV', 'Côte d''Ivoire (Ivory Coast)'),
('COD', 'Democratic Republic of the Congo'),
('DNK', 'Denmark'),
('DJI', 'Djibouti'),
('DMA', 'Dominica'),
('DOM', 'Dominican Republic'),
('ECU', 'Ecuador'),
('EGY', 'Egypt'),
('SLV', 'El Salvador'),
('GNQ', 'Equatorial Guinea'),
('ERI', 'Eritrea'),
('EST', 'Estonia'),
('SWZ', 'Eswatini'),
('ETH', 'Ethiopia'),
('FJI', 'Fiji'),
('FIN', 'Finland'),
('FRA', 'France'),
('GUF', 'French Guiana'),
('PYF', 'French Polynesia'),
('ATF', 'French Southern Territories (the)'),
('GAB', 'Gabon'),
('GMB', 'Gambia (the)'),
('GEO', 'Georgia'),
('DEU', 'Germany'),
('GHA', 'Ghana'),
('GRC', 'Greece'),
('GRL', 'Greenland'),
('GRD', 'Grenada'),
('GUM', 'Guam'),
('GTM', 'Guatemala'),
('GIN', 'Guinea'),
('GNB', 'Guinea-Bissau'),
('GUY', 'Guyana'),
('HTI', 'Haiti'),
('HND', 'Honduras'),
('HUN', 'Hungary'),
('ISL', 'Iceland'),
('IND', 'India'),
('IDN', 'Indonesia'),
('IRQ', 'Iraq'),
('IRL', 'Ireland'),
('ISR', 'Israel'),
('ITA', 'Italy'),
('JAM', 'Jamaica'),
('JPN', 'Japan'),
('JOR', 'Jordan'),
('KAZ', 'Kazakhstan'),
('KEN', 'Kenya'),
('KIR', 'Kiribati'),
('KOR', 'South Korea'),
('KWT', 'Kuwait'),
('KGZ', 'Kyrgyzstan'),
('LAO', 'Laos'),
('LVA', 'Latvia'),
('LBN', 'Lebanon'),
('LSO', 'Lesotho'),
('LBR', 'Liberia'),
('LBY', 'Libya'),
('LIE', 'Liechtenstein'),
('LTU', 'Lithuania'),
('LUX', 'Luxembourg'),
('MDG', 'Madagascar'),
('MWI', 'Malawi'),
('MYS', 'Malaysia'),
('MDV', 'Maldives'),
('MLI', 'Mali'),
('MLT', 'Malta'),
('MHL', 'Marshall Islands (the)'),
('MTQ', 'Martinique'),
('MRT', 'Mauritania'),
('MUS', 'Mauritius'),
('MEX', 'Mexico'),
('FSM', 'Micronesia'),
('MDA', 'Moldova'),
('MCO', 'Monaco'),
('MNG', 'Mongolia'),
('MNE', 'Montenegro'),
('MAR', 'Morocco'),
('MOZ', 'Mozambique'),
('MMR', 'Myanmar'),
('NAM', 'Namibia'),
('NRU', 'Nauru'),
('NPL', 'Nepal'),
('NLD', 'Netherlands (the)'),
('NZL', 'New Zealand'),
('NIC', 'Nicaragua'),
('NER', 'Niger'),
('NGA', 'Nigeria'),
('MKD', 'North Macedonia (Republic of)'),
('NOR', 'Norway'),
('OMN', 'Oman'),
('PAK', 'Pakistan'),
('PLW', 'Palau'),
('PAN', 'Panama'),
('PNG', 'Papua New Guinea'),
('PRY', 'Paraguay'),
('PER', 'Peru'),
('PHL', 'Philippines (the)'),
('POL', 'Poland'),
('PRT', 'Portugal'),
('PRI', 'Puerto Rico'),
('QAT', 'Qatar'),
('ROU', 'Romania'),
('RUS', 'Russia'),
('RWA', 'Rwanda'),
('REU', 'Réunion'),
('BLM', 'Saint Barts'),
('KNA', 'Saint Kitts and Nevis'),
('LCA', 'Saint Lucia'),
('MAF', 'Saint Martin'),
('VCT', 'Saint Vincent and the Grenadines'),
('WSM', 'Samoa'),
('SMR', 'San Marino'),
('STP', 'Sao Tome and Principe'),
('SAU', 'Saudi Arabia'),
('SEN', 'Senegal'),
('SRB', 'Serbia'),
('SYC', 'Seychelles'),
('SLE', 'Sierra Leone'),
('SGP', 'Singapore'),
('SVK', 'Slovakia'),
('SVN', 'Slovenia'),
('SLB', 'Solomon Islands'),
('SOM', 'Somalia'),
('ZAF', 'South Africa'),
('SSD', 'South Sudan'),
('ESP', 'Spain'),
('LKA', 'Sri Lanka'),
('SDN', 'Sudan (the)'),
('SUR', 'Suriname'),
('SWE', 'Sweden'),
('CHE', 'Switzerland'),
('TWN', 'Taiwan'),
('TJK', 'Tajikistan'),
('TZA', 'Tanzania'),
('THA', 'Thailand'),
('TLS', 'Timor-Leste'),
('TGO', 'Togo'),
('TON', 'Tonga'),
('TTO', 'Trinidad and Tobago'),
('TUN', 'Tunisia'),
('TUR', 'Turkey'),
('TKM', 'Turkmenistan'),
('TCA', 'Turks and Caicos Islands'),
('TUV', 'Tuvalu'),
('UGA', 'Uganda'),
('UKR', 'Ukraine'),
('ARE', 'United Arab Emirates'),
('GBR', 'United Kingdom'),
('UMI', 'United States Minor Outlying Islands'),
('USA', 'United States of America'),
('URY', 'Uruguay'),
('UZB', 'Uzbekistan'),
('VUT', 'Vanuatu'),
('VEN', 'Venezuela'),
('VNM', 'Vietnam'),
('VGB', 'Virgin Islands (British)'),
('VIR', 'Virgin Islands (U.S.)'),
('YEM', 'Yemen'),
('ZMB', 'Zambia'),
('ZWE', 'Zimbabwe')
ON CONFLICT DO NOTHING;

ALTER TABLE disbursements
ADD COLUMN country_code VARCHAR(3),
ADD CONSTRAINT fk_disbursement_country_code FOREIGN KEY (country_code) REFERENCES countries (code);
6 changes: 0 additions & 6 deletions internal/data/assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,37 +451,31 @@ func Test_GetAssetsPerReceiverWallet(t *testing.T) {
require.NoError(t, err)

// 1. Create assets, wallets and disbursements:
country := CreateCountryFixture(t, ctx, dbConnectionPool, "ATL", "Atlantis")

asset1 := CreateAssetFixture(t, ctx, dbConnectionPool, "FOO1", "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVV")
asset2 := CreateAssetFixture(t, ctx, dbConnectionPool, "FOO2", "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVV")

walletA := CreateWalletFixture(t, ctx, dbConnectionPool, "walletA", "https://www.a.com", "www.a.com", "a://")
walletB := CreateWalletFixture(t, ctx, dbConnectionPool, "walletB", "https://www.b.com", "www.b.com", "b://")

disbursementA1 := CreateDisbursementFixture(t, ctx, dbConnectionPool, models.Disbursements, &Disbursement{
Country: country,
Wallet: walletA,
Status: ReadyDisbursementStatus,
Asset: asset1,
ReceiverRegistrationMessageTemplate: "Disbursement SMS Registration Message Template A1",
})
disbursementA2 := CreateDisbursementFixture(t, ctx, dbConnectionPool, models.Disbursements, &Disbursement{
Country: country,
Wallet: walletA,
Status: ReadyDisbursementStatus,
Asset: asset2,
ReceiverRegistrationMessageTemplate: "Disbursement SMS Registration Message Template A2",
})
disbursementB1 := CreateDisbursementFixture(t, ctx, dbConnectionPool, models.Disbursements, &Disbursement{
Country: country,
Wallet: walletB,
Status: ReadyDisbursementStatus,
Asset: asset1,
ReceiverRegistrationMessageTemplate: "Disbursement SMS Registration Message Template B1",
})
disbursementB2 := CreateDisbursementFixture(t, ctx, dbConnectionPool, models.Disbursements, &Disbursement{
Country: country,
Wallet: walletB,
Status: ReadyDisbursementStatus,
Asset: asset2,
Expand Down
16 changes: 6 additions & 10 deletions internal/data/circle_transfer_requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,11 @@ func Test_CircleTransferRequestModel_GetOrInsert(t *testing.T) {
models, err := NewModels(dbConnectionPool)
require.NoError(t, err)
asset := CreateAssetFixture(t, ctx, dbConnectionPool, "USDC", "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVV")
country := CreateCountryFixture(t, ctx, dbConnectionPool, "FRA", "France")
wallet := CreateWalletFixture(t, ctx, dbConnectionPool, "wallet1", "https://www.wallet.com", "www.wallet.com", "wallet1://")
disbursement := CreateDisbursementFixture(t, ctx, dbConnectionPool, models.Disbursements, &Disbursement{
Country: country,
Wallet: wallet,
Status: ReadyDisbursementStatus,
Asset: asset,
Wallet: wallet,
Status: ReadyDisbursementStatus,
Asset: asset,
})
receiverReady := CreateReceiverFixture(t, ctx, dbConnectionPool, &Receiver{})
rwReady := CreateReceiverWalletFixture(t, ctx, dbConnectionPool, receiverReady.ID, wallet.ID, ReadyReceiversWalletStatus)
Expand Down Expand Up @@ -547,13 +545,11 @@ func Test_CircleTransferRequestModel_GetCurrentTransfersForPaymentIDs(t *testing
models, outerErr := NewModels(dbConnectionPool)
require.NoError(t, outerErr)
asset := CreateAssetFixture(t, ctx, dbConnectionPool, "USDC", "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVV")
country := CreateCountryFixture(t, ctx, dbConnectionPool, "FRA", "France")
wallet := CreateWalletFixture(t, ctx, dbConnectionPool, "wallet1", "https://www.wallet.com", "www.wallet.com", "wallet1://")
disbursement := CreateDisbursementFixture(t, ctx, dbConnectionPool, models.Disbursements, &Disbursement{
Country: country,
Wallet: wallet,
Status: ReadyDisbursementStatus,
Asset: asset,
Wallet: wallet,
Status: ReadyDisbursementStatus,
Asset: asset,
})
receiverReady := CreateReceiverFixture(t, ctx, dbConnectionPool, &Receiver{})
rwReady := CreateReceiverWalletFixture(t, ctx, dbConnectionPool, receiverReady.ID, wallet.ID, ReadyReceiversWalletStatus)
Expand Down
69 changes: 0 additions & 69 deletions internal/data/countries.go

This file was deleted.

Loading

0 comments on commit e824a74

Please sign in to comment.