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

DDLS-402 - Migrate existing data from dd_user table to deputy table #1775

Merged
merged 9 commits into from
Jan 7, 2025
2 changes: 2 additions & 0 deletions api/app/api.env
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ SECRETS_MANAGER_LOCALSTACK=true

JWT_HOST=http://frontend-webserver
WORKSPACE=local

RUN_ONE_OFF_MIGRATIONS=true
50 changes: 50 additions & 0 deletions api/app/src/Migrations/Version286.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version286 extends AbstractMigration
{
public function getDescription(): string
{
return 'Adds mirgration script';
}

public function up(Schema $schema): void
{
if (!!getenv('RUN_ONE_OFF_MIGRATIONS')) {
$sql = <<<SQL
INSERT INTO deputy
(user_id, deputy_uid, firstname, lastname, email1, address1, address2,
address3, address4, address5, address_postcode, address_country, phone_main, phone_alternative)
SELECT id, CAST(deputy_uid AS VARCHAR), firstname, lastname, email, address1, address2, address3,
address4, address5, address_postcode, address_country, phone_main, phone_alternative
FROM dd_user
WHERE id IN (
SELECT u.id
FROM client c
LEFT JOIN deputy_case dc ON c.id = dc.client_id
LEFT JOIN dd_user u ON dc.user_id = u.id
WHERE dc.user_id IN (
SELECT id
FROM dd_user
WHERE is_primary = TRUE
AND CAST(deputy_uid AS VARCHAR) NOT IN (
SELECT deputy_uid
FROM deputy
)
)
)
SQL;

$this->addSql($sql);
}
}
}
4 changes: 4 additions & 0 deletions terraform/environment/region/ecs_cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ locals {
name = "LAY_REPORT_CSV_FILENAME",
value = local.lay_report_csv_file
},
{
name = "RUN_ONE_OFF_MIGRATIONS",
value = var.account.run_one_off_migrations
},
]

api_integration_test_variables = [
Expand Down
18 changes: 12 additions & 6 deletions terraform/environment/terraform.tfvars.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"secondary_region_enabled": false,
"fault_injection_experiments_enabled": false,
"sleep_mode_enabled": false,
"waf_ip_blocking_enabled": true
"waf_ip_blocking_enabled": true,
"run_one_off_migrations": ""
},
"preproduction": {
"name": "preproduction",
Expand Down Expand Up @@ -86,7 +87,8 @@
"secondary_region_enabled": false,
"fault_injection_experiments_enabled": false,
"sleep_mode_enabled": true,
"waf_ip_blocking_enabled": true
"waf_ip_blocking_enabled": true,
"run_one_off_migrations": "true"
},
"training": {
"name": "preproduction",
Expand Down Expand Up @@ -130,7 +132,8 @@
"secondary_region_enabled": false,
"fault_injection_experiments_enabled": false,
"sleep_mode_enabled": true,
"waf_ip_blocking_enabled": false
"waf_ip_blocking_enabled": false,
"run_one_off_migrations": ""
},
"integration": {
"name": "preproduction",
Expand Down Expand Up @@ -174,7 +177,8 @@
"secondary_region_enabled": false,
"fault_injection_experiments_enabled": true,
"sleep_mode_enabled": true,
"waf_ip_blocking_enabled": false
"waf_ip_blocking_enabled": false,
"run_one_off_migrations": ""
},
"development": {
"name": "development",
Expand Down Expand Up @@ -219,7 +223,8 @@
"secondary_region_enabled": false,
"fault_injection_experiments_enabled": false,
"sleep_mode_enabled": false,
"waf_ip_blocking_enabled": false
"waf_ip_blocking_enabled": false,
"run_one_off_migrations": ""
},
"default": {
"name": "development",
Expand Down Expand Up @@ -264,7 +269,8 @@
"secondary_region_enabled": false,
"fault_injection_experiments_enabled": false,
"sleep_mode_enabled": false,
"waf_ip_blocking_enabled": false
"waf_ip_blocking_enabled": false,
"run_one_off_migrations": ""
}
}
}
1 change: 1 addition & 0 deletions terraform/environment/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ variable "accounts" {
fault_injection_experiments_enabled = bool
sleep_mode_enabled = bool
waf_ip_blocking_enabled = bool
run_one_off_migrations = string
})
)
}
Expand Down
Loading