PSA/server/migrations/20250707110000_add_phone_codes_to_countries.cjs
Hermes 284313f908
Some checks are pending
Bidi Control Character Guard / bidi-control-guard (push) Waiting to run
Circular Dependency Check / Check for new circular dependencies (push) Waiting to run
Citus Migration Smoke / Combined migrations on single-node Citus (push) Waiting to run
E2E Fresh Install Tests / fresh-install-e2e (push) Waiting to run
ext-v2 guardrails / Run ext-v2 guard and ESLint (push) Waiting to run
Integration Tests / Check for relevant changes (push) Waiting to run
Integration Tests / ${{ (github.event_name == 'schedule' || github.event.inputs.suite == 'full') && 'Full integration suite' || 'Tier-1 integration subset' }} (push) Blocked by required conditions
Mobile checks / Mobile lint + typecheck (push) Waiting to run
Mobile checks / Mobile unit tests (push) Waiting to run
Mobile checks / Mobile dependency audit (report) (push) Waiting to run
Mobile checks / Mobile reproducibility checks (push) Waiting to run
Secrets guard (env backups) / Ensure no tracked env backup files (push) Waiting to run
Temporal Readiness / fast-readiness (push) Waiting to run
Temporal Readiness / docker-parity (push) Waiting to run
TypeScript Type Check / Nx affected typecheck (push) Waiting to run
Unit Tests / Skipped-test budget (push) Waiting to run
Unit Tests / Nx affected unit tests (push) Waiting to run
Unit Tests / Server unit coverage (informational) (push) Waiting to run
Validate Tenant Management Schema / Check for relevant changes (push) Waiting to run
Validate Tenant Management Schema / Validate Tenant Management Schema (push) Blocked by required conditions
EE Workflows Build Guard / ee-workflows-build-guard (push) Waiting to run
Initial import of AlgaPSA codebase from PSA server
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz

Source: /opt/alga-psa on psa.joliet.tech
2026-06-22 16:12:17 -05:00

97 lines
4.6 KiB
JavaScript

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async function(knex) {
// Add phone_code column to countries table
await knex.schema.alterTable('countries', function(table) {
table.string('phone_code', 10);
});
// Populate phone codes for countries
const phoneCodeUpdates = [
// North America
['US', '+1'], ['CA', '+1'],
// Europe
['GB', '+44'], ['DE', '+49'], ['FR', '+33'], ['IT', '+39'], ['ES', '+34'],
['PT', '+351'], ['NL', '+31'], ['BE', '+32'], ['CH', '+41'], ['AT', '+43'],
['SE', '+46'], ['NO', '+47'], ['DK', '+45'], ['FI', '+358'], ['IE', '+353'],
['PL', '+48'], ['CZ', '+420'], ['HU', '+36'], ['RO', '+40'], ['BG', '+359'],
['HR', '+385'], ['SI', '+386'], ['SK', '+421'], ['EE', '+372'], ['LV', '+371'],
['LT', '+370'], ['LU', '+352'], ['MT', '+356'], ['CY', '+357'], ['GR', '+30'],
['IS', '+354'], ['RU', '+7'], ['UA', '+380'], ['BY', '+375'], ['MD', '+373'],
['RS', '+381'], ['BA', '+387'], ['ME', '+382'], ['MK', '+389'], ['AL', '+355'],
['XK', '+383'], // Kosovo
// Asia Pacific
['AU', '+61'], ['NZ', '+64'], ['JP', '+81'], ['KR', '+82'], ['CN', '+86'],
['HK', '+852'], ['TW', '+886'], ['SG', '+65'], ['MY', '+60'], ['TH', '+66'],
['VN', '+84'], ['PH', '+63'], ['ID', '+62'], ['IN', '+91'], ['PK', '+92'],
['BD', '+880'], ['LK', '+94'], ['NP', '+977'], ['BT', '+975'], ['MV', '+960'],
['AF', '+93'], ['IR', '+98'], ['IQ', '+964'], ['SA', '+966'], ['AE', '+971'],
['QA', '+974'], ['KW', '+965'], ['BH', '+973'], ['OM', '+968'], ['YE', '+967'],
['JO', '+962'], ['LB', '+961'], ['SY', '+963'], ['IL', '+972'], ['PS', '+970'],
['TR', '+90'], ['GE', '+995'], ['AM', '+374'], ['AZ', '+994'], ['KZ', '+7'],
['UZ', '+998'], ['TM', '+993'], ['TJ', '+992'], ['KG', '+996'], ['MN', '+976'],
['KP', '+850'], ['MM', '+95'], ['KH', '+855'], ['LA', '+856'], ['BN', '+673'],
['MO', '+853'],
// Africa
['ZA', '+27'], ['EG', '+20'], ['LY', '+218'], ['TN', '+216'], ['DZ', '+213'],
['MA', '+212'], ['SD', '+249'], ['SS', '+211'], ['ET', '+251'], ['ER', '+291'],
['DJ', '+253'], ['SO', '+252'], ['KE', '+254'], ['UG', '+256'], ['TZ', '+255'],
['RW', '+250'], ['BI', '+257'], ['MG', '+261'], ['MU', '+230'], ['SC', '+248'],
['KM', '+269'], ['YT', '+262'], ['RE', '+262'], ['ZW', '+263'], ['ZM', '+260'],
['MW', '+265'], ['MZ', '+258'], ['BW', '+267'], ['NA', '+264'], ['SZ', '+268'],
['LS', '+266'], ['AO', '+244'], ['CD', '+243'], ['CG', '+242'], ['CF', '+236'],
['TD', '+235'], ['CM', '+237'], ['GQ', '+240'], ['GA', '+241'], ['ST', '+239'],
['CV', '+238'], ['GW', '+245'], ['GN', '+224'], ['SN', '+221'], ['GM', '+220'],
['ML', '+223'], ['BF', '+226'], ['NE', '+227'], ['NG', '+234'], ['BJ', '+229'],
['TG', '+228'], ['GH', '+233'], ['CI', '+225'], ['LR', '+231'], ['SL', '+232'],
['SH', '+290'],
// South America
['BR', '+55'], ['AR', '+54'], ['CL', '+56'], ['PE', '+51'], ['CO', '+57'],
['VE', '+58'], ['EC', '+593'], ['BO', '+591'], ['PY', '+595'], ['UY', '+598'],
['GY', '+592'], ['SR', '+597'], ['GF', '+594'], ['FK', '+500'],
// Central America & Caribbean
['MX', '+52'], ['GT', '+502'], ['BZ', '+501'], ['SV', '+503'], ['HN', '+504'],
['NI', '+505'], ['CR', '+506'], ['PA', '+507'], ['CU', '+53'], ['JM', '+1876'],
['HT', '+509'], ['DO', '+1809'], ['PR', '+1787'], ['VI', '+1340'], ['AG', '+1268'],
['BB', '+1246'], ['DM', '+1767'], ['GD', '+1473'], ['KN', '+1869'], ['LC', '+1758'],
['VC', '+1784'], ['TT', '+1868'], ['AW', '+297'], ['AN', '+599'], ['BQ', '+599'],
['CW', '+599'], ['SX', '+1721'], ['TC', '+1649'], ['KY', '+1345'], ['BM', '+1441'],
['BS', '+1242'],
// Oceania
['FJ', '+679'], ['PG', '+675'], ['NC', '+687'], ['VU', '+678'], ['SB', '+677'],
['TO', '+676'], ['WS', '+685'], ['KI', '+686'], ['TV', '+688'], ['NR', '+674'],
['PW', '+680'], ['FM', '+691'], ['MH', '+692'], ['CK', '+682'], ['NU', '+683'],
['TK', '+690'], ['PF', '+689'], ['WF', '+681'], ['AS', '+1684'], ['GU', '+1671'],
['MP', '+1670'],
// Antarctica & Special cases
['AQ', '+672'], ['VA', '+39'], ['SM', '+378'], ['AD', '+376'], ['MC', '+377'],
['LI', '+423']
];
// Update countries with phone codes
for (const [countryCode, phoneCode] of phoneCodeUpdates) {
await knex('countries')
.where('code', countryCode)
.update({ phone_code: phoneCode });
}
};
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async function(knex) {
// Remove phone_code column
await knex.schema.alterTable('countries', function(table) {
table.dropColumn('phone_code');
});
};