Skip to content

Commit 867dae8

Browse files
authored
fix: align db schema everywhere and make it app (#42)
* fix: align db schema everywhere and make it app * fix: add waiting to resume resources
1 parent 6a72489 commit 867dae8

File tree

4 files changed

+42
-9
lines changed

4 files changed

+42
-9
lines changed

.github/workflows/resume-resources.yml

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,31 @@ jobs:
2727
- name: Resume AWS Resources
2828
shell: bash
2929
run: |
30-
aws application-autoscaling register-scalable-target --service-namespace ecs --resource-id service/ecs-cluster-${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-dev/${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-dev-service --scalable-dimension ecs:service:DesiredCount --min-capacity 1 --max-capacity 2 --no-cli-pager --output json
31-
aws ecs update-service --cluster ecs-cluster-${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-dev --service ${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-dev-service --desired-count 1 --no-cli-pager --output json
3230
DB_CLUSTER_STATUS=$(aws rds describe-db-clusters --db-cluster-identifier ${{ needs.stack-prefix.outputs.stack_prefix }}-aurora-dev --query 'DBClusters[0].Status' --output text)
3331
if [ "$DB_CLUSTER_STATUS" = "stopped" ]; then
3432
aws rds start-db-cluster --db-cluster-identifier ${{ needs.stack-prefix.outputs.stack_prefix }}-aurora-dev --no-cli-pager --output json
33+
# wait for the cluster to be available
34+
attempt=1
35+
max_attempts=20
36+
until [[ $(aws rds describe-db-clusters --db-cluster-identifier ${{ needs.stack-prefix.outputs.stack_prefix }}-aurora-dev --query 'DBClusters[0].Status' --output text) == "available" ]] || [[ $attempt -gt $max_attempts ]]
37+
do
38+
echo "Waiting for DB cluster to be available... Attempt $attempt of $max_attempts"
39+
sleep 60
40+
((attempt++))
41+
done
42+
43+
if [[ $attempt -gt $max_attempts ]]; then
44+
echo "Timeout waiting for DB cluster to become available"
45+
exit 1
46+
fi
47+
echo "DB cluster is now available"
48+
3549
else
3650
echo "DB cluster is not in a stopped state. Current state: $DB_CLUSTER_STATUS"
3751
fi
52+
aws application-autoscaling register-scalable-target --service-namespace ecs --resource-id service/ecs-cluster-${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-dev/${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-dev-service --scalable-dimension ecs:service:DesiredCount --min-capacity 1 --max-capacity 2 --no-cli-pager --output json
53+
aws ecs update-service --cluster ecs-cluster-${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-dev --service ${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-dev-service --desired-count 1 --no-cli-pager --output json
54+
3855
resume-resources-test:
3956
name: Resume Resources Test
4057
environment: test
@@ -52,11 +69,27 @@ jobs:
5269
- name: Resume AWS Resources
5370
shell: bash
5471
run: |
55-
aws application-autoscaling register-scalable-target --service-namespace ecs --resource-id service/ecs-cluster-${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-test/${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-test-service --scalable-dimension ecs:service:DesiredCount --min-capacity 1 --max-capacity 2 --no-cli-pager --output json
56-
aws ecs update-service --cluster ecs-cluster-${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-test --service ${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-test-service --desired-count 1 --no-cli-pager --output json
5772
DB_CLUSTER_STATUS=$(aws rds describe-db-clusters --db-cluster-identifier ${{ needs.stack-prefix.outputs.stack_prefix }}-aurora-test --query 'DBClusters[0].Status' --output text)
5873
if [ "$DB_CLUSTER_STATUS" = "stopped" ]; then
5974
aws rds start-db-cluster --db-cluster-identifier ${{ needs.stack-prefix.outputs.stack_prefix }}-aurora-test --no-cli-pager --output json
75+
# wait for the cluster to be available
76+
attempt=1
77+
max_attempts=20
78+
until [[ $(aws rds describe-db-clusters --db-cluster-identifier ${{ needs.stack-prefix.outputs.stack_prefix }}-aurora-test --query 'DBClusters[0].Status' --output text) == "available" ]] || [[ $attempt -gt $max_attempts ]]
79+
do
80+
echo "Waiting for DB cluster to be available... Attempt $attempt of $max_attempts"
81+
sleep 60
82+
((attempt++))
83+
done
84+
85+
if [[ $attempt -gt $max_attempts ]]; then
86+
echo "Timeout waiting for DB cluster to become available"
87+
exit 1
88+
fi
89+
echo "DB cluster is now available"
6090
else
6191
echo "DB cluster is not in a stopped state. Current state: $DB_CLUSTER_STATUS"
62-
fi
92+
fi
93+
aws application-autoscaling register-scalable-target --service-namespace ecs --resource-id service/ecs-cluster-${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-test/${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-test-service --scalable-dimension ecs:service:DesiredCount --min-capacity 1 --max-capacity 2 --no-cli-pager --output json
94+
aws ecs update-service --cluster ecs-cluster-${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-test --service ${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-test-service --desired-count 1 --no-cli-pager --output json
95+

backend/src/prisma.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const DB_USER = process.env.POSTGRES_USER || "postgres";
66
const DB_PWD = encodeURIComponent(process.env.POSTGRES_PASSWORD || "default"); // this needs to be encoded, if the password contains special characters it will break connection string.
77
const DB_PORT = process.env.POSTGRES_PORT || 5432;
88
const DB_NAME = process.env.POSTGRES_DATABASE || "postgres";
9-
const DB_SCHEMA = process.env.POSTGRES_SCHEMA || "users";
9+
const DB_SCHEMA = process.env.POSTGRES_SCHEMA || "app";
1010
const dataSourceURL = `postgresql://${DB_USER}:${DB_PWD}@${DB_HOST}:${DB_PORT}/${DB_NAME}?schema=${DB_SCHEMA}&connection_limit=5`;
1111

1212
@Injectable({ scope: Scope.DEFAULT})

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ services:
3434
FLYWAY_USER: *POSTGRES_USER
3535
FLYWAY_PASSWORD: *POSTGRES_PASSWORD
3636
FLYWAY_BASELINE_ON_MIGRATE: true
37-
FLYWAY_DEFAULT_SCHEMA: users
37+
FLYWAY_DEFAULT_SCHEMA: app
3838
depends_on:
3939
database:
4040
condition: service_healthy
@@ -43,7 +43,7 @@ services:
4343
image: schemaspy/schemaspy:6.2.4
4444
profiles: ["schemaspy"]
4545
container_name: schemaspy
46-
command: -t pgsql11 -db postgres -host database -port 5432 -u postgres -p default -schemas users
46+
command: -t pgsql11 -db postgres -host database -port 5432 -u postgres -p default -schemas app
4747
depends_on:
4848
migrations:
4949
condition: service_completed_successfully

infrastructure/api/ecs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ resource "aws_ecs_task_definition" "node_api_task" {
170170
value = var.db_name
171171
},
172172
{
173-
name = "DB_SCHEMA"
173+
name = "POSTGRES_SCHEMA"
174174
value = "${var.db_schema}"
175175
}
176176
,

0 commit comments

Comments
 (0)