-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update migration idempotence, add org email field, extra project fiel…
…ds (#2072) * build: update migration idempotence, add org email field, project fields * feat(backend): add new project + org fields to response models * build: tweak migrations to work when applied on fresh instance
- Loading branch information
1 parent
35939f1
commit 056c3b5
Showing
9 changed files
with
138 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,7 @@ async def init_admin_org(db: Connection) -> None: | |
name="HOTOSM", | ||
description="Humanitarian OpenStreetMap Team.", | ||
url="https://hotosm.org", | ||
associated_email="[email protected]", | ||
odk_central_url=settings.ODK_CENTRAL_URL, | ||
odk_central_user=settings.ODK_CENTRAL_USER, | ||
odk_central_password=settings.ODK_CENTRAL_PASSWD.get_secret_value() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
-- ## Migration add some extra fields. | ||
-- * Add geo_restrict_distance_meters and geo_restrict_force_error to projects. | ||
-- * Add new_geom_type to projects. | ||
-- * Add associated_email to organisations. | ||
|
||
-- Related issues: | ||
-- https://github.com/hotosm/fmtm/issues/1985#issuecomment-2577342507 | ||
-- https://github.com/hotosm/fmtm/issues/1979 | ||
-- https://github.com/hotosm/fmtm/issues/2066 | ||
|
||
-- Start a transaction | ||
|
||
BEGIN; | ||
|
||
DO $$ BEGIN | ||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'geomtype') THEN | ||
CREATE TYPE public.geomtype AS ENUM ('POINT', 'POLYLINE', 'POLYGON'); | ||
END IF; | ||
END $$; | ||
ALTER TYPE public.geomstatus OWNER TO fmtm; | ||
|
||
ALTER TABLE public.organisations | ||
ADD COLUMN IF NOT EXISTS associated_email | ||
character varying; | ||
|
||
ALTER TABLE public.projects | ||
ADD COLUMN IF NOT EXISTS new_geom_type | ||
public.geomtype | ||
DEFAULT 'POINT', | ||
ADD COLUMN IF NOT EXISTS geo_restrict_distance_meters | ||
int2 | ||
DEFAULT 50 | ||
CHECK (geo_restrict_distance_meters >= 0), | ||
ADD COLUMN IF NOT EXISTS geo_restrict_force_error | ||
BOOLEAN | ||
DEFAULT false; | ||
|
||
-- Also update the fields from previous migration | ||
DROP INDEX IF EXISTS idx_geometrylog; | ||
DROP INDEX IF EXISTS idx_geom_gin; | ||
|
||
DO $$ | ||
BEGIN | ||
IF EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'geometrylog' AND column_name = 'geom') THEN | ||
ALTER TABLE public.geometrylog RENAME COLUMN geom TO geojson; | ||
ALTER TABLE public.geometrylog ALTER COLUMN geojson TYPE JSONB USING geojson::jsonb; | ||
END IF; | ||
END $$; | ||
|
||
CREATE INDEX IF NOT EXISTS idx_geometrylog_geojson | ||
ON geometrylog USING gin (geojson); | ||
|
||
-- Commit the transaction | ||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/backend/migrations/revert/004-project-extra-fields.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
-- Start a transaction | ||
|
||
BEGIN; | ||
|
||
ALTER TABLE public.organisations | ||
DROP COLUMN IF EXISTS associated_email; | ||
|
||
ALTER TABLE public.projects | ||
DROP CONSTRAINT IF EXISTS projects_geo_restrict_distance_meters_check, | ||
DROP COLUMN IF EXISTS new_geom_type, | ||
DROP COLUMN IF EXISTS geo_restrict_distance_meters, | ||
DROP COLUMN IF EXISTS geo_restrict_force_error; | ||
|
||
DROP TYPE IF EXISTS public.geomtype; | ||
|
||
-- Commit the transaction | ||
COMMIT; |