From 4e601daa6c19a8e64ff6627e8903bfb197fdd6ef Mon Sep 17 00:00:00 2001 From: Sosokker Date: Wed, 12 Mar 2025 17:12:48 +0700 Subject: [PATCH] chore: update migration - add goose down to migration --- backend/migrations/00001_create_user_table.sql | 6 +++++- .../00002_create_farm_and_cropland_tables.sql | 9 +++++++++ ...00003_drop_column_plant_types_from_farms.sql | 6 +++++- backend/migrations/00004_update_farm_table.sql | 17 +++++++++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 backend/migrations/00004_update_farm_table.sql diff --git a/backend/migrations/00001_create_user_table.sql b/backend/migrations/00001_create_user_table.sql index 09d2932..ffcd9ea 100644 --- a/backend/migrations/00001_create_user_table.sql +++ b/backend/migrations/00001_create_user_table.sql @@ -10,4 +10,8 @@ CREATE TABLE users ( is_active BOOLEAN NOT NULL DEFAULT TRUE ); -CREATE UNIQUE INDEX idx_users_uuid ON users(uuid); \ No newline at end of file +CREATE UNIQUE INDEX idx_users_uuid ON users(uuid); + +-- +goose Down +DROP INDEX IF EXISTS idx_users_uuid; +DROP TABLE IF EXISTS users; \ No newline at end of file diff --git a/backend/migrations/00002_create_farm_and_cropland_tables.sql b/backend/migrations/00002_create_farm_and_cropland_tables.sql index bd5a114..a0e0447 100644 --- a/backend/migrations/00002_create_farm_and_cropland_tables.sql +++ b/backend/migrations/00002_create_farm_and_cropland_tables.sql @@ -66,3 +66,12 @@ CREATE TABLE croplands ( CONSTRAINT fk_cropland_farm FOREIGN KEY (farm_id) REFERENCES farms(uuid) ON DELETE CASCADE, CONSTRAINT fk_cropland_plant FOREIGN KEY (plant_id) REFERENCES plants(uuid) ON DELETE CASCADE ); + + +-- +goose Down +DROP TABLE IF EXISTS croplands; +DROP TABLE IF EXISTS farms; +DROP TABLE IF EXISTS plants; +DROP TABLE IF EXISTS harvest_units; +DROP TABLE IF EXISTS soil_conditions; +DROP TABLE IF EXISTS light_profiles; \ No newline at end of file diff --git a/backend/migrations/00003_drop_column_plant_types_from_farms.sql b/backend/migrations/00003_drop_column_plant_types_from_farms.sql index b643d83..5162bda 100644 --- a/backend/migrations/00003_drop_column_plant_types_from_farms.sql +++ b/backend/migrations/00003_drop_column_plant_types_from_farms.sql @@ -1,2 +1,6 @@ -- +goose Up -ALTER TABLE farms DROP COLUMN plant_types; \ No newline at end of file +ALTER TABLE farms DROP COLUMN plant_types; + +-- +goose Down +ALTER TABLE farms + ADD COLUMN plant_types UUID[]; \ No newline at end of file diff --git a/backend/migrations/00004_update_farm_table.sql b/backend/migrations/00004_update_farm_table.sql new file mode 100644 index 0000000..f49065f --- /dev/null +++ b/backend/migrations/00004_update_farm_table.sql @@ -0,0 +1,17 @@ +-- +goose Up +ALTER TABLE farms + ADD COLUMN farm_type TEXT, + ADD COLUMN total_size TEXT; + +ALTER TABLE farms + ALTER COLUMN lat TYPE DOUBLE PRECISION USING lat[1], + ALTER COLUMN lon TYPE DOUBLE PRECISION USING lon[1]; + +-- +goose Down +ALTER TABLE farms + ALTER COLUMN lat TYPE DOUBLE PRECISION[] USING ARRAY[lat], + ALTER COLUMN lon TYPE DOUBLE PRECISION[] USING ARRAY[lon]; + +ALTER TABLE farms + DROP COLUMN farm_type, + DROP COLUMN total_size; \ No newline at end of file