From 262c5c9f121318d3014436571a37c1055cad0d98 Mon Sep 17 00:00:00 2001 From: Froidefond Julien Date: Thu, 5 Mar 2026 23:31:21 +0100 Subject: [PATCH] feat(db): add migration for volume column type change - Create migration 0002_alter_volume_type.sql to change volume from TEXT to INTEGER - Update docker-compose to run all migrations automatically using env variables - Enables proper numeric sorting of volumes (1, 2, 3 instead of 01, 02, 03) --- infra/docker-compose.yml | 4 +++- infra/migrations/0002_alter_volume_type.sql | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 infra/migrations/0002_alter_volume_type.sql diff --git a/infra/docker-compose.yml b/infra/docker-compose.yml index 9af4c27..dea0d3b 100644 --- a/infra/docker-compose.yml +++ b/infra/docker-compose.yml @@ -34,13 +34,15 @@ services: depends_on: postgres: condition: service_healthy + env_file: + - ../.env volumes: - ./migrations:/migrations:ro command: [ "sh", "-c", - "PGPASSWORD=stripstream psql -h postgres -U stripstream -d stripstream -f /migrations/0001_init.sql", + "for f in /migrations/*.sql; do echo \"Applying migration: $f\"; psql -h postgres -U \"$${POSTGRES_USER:-stripstream}\" -d \"$${POSTGRES_DB:-stripstream}\" -f \"$f\" || exit 1; done", ] api: diff --git a/infra/migrations/0002_alter_volume_type.sql b/infra/migrations/0002_alter_volume_type.sql new file mode 100644 index 0000000..31a6fed --- /dev/null +++ b/infra/migrations/0002_alter_volume_type.sql @@ -0,0 +1,4 @@ +-- Migration: Change volume column type from TEXT to INTEGER +-- This allows proper numeric sorting and removes leading zeros + +ALTER TABLE books ALTER COLUMN volume TYPE INTEGER USING volume::integer;