Skip to content

Commit

Permalink
build: archive migrations for fresh start from base schema (#1271)
Browse files Browse the repository at this point in the history
* docs: update links to get.fmtm.dev until fixed

* build: move old migrations to legacy dir (fresh start)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* build: add migration to reset _migrations dir

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
spwoodcock and pre-commit-ci[bot] committed Feb 24, 2024
1 parent 627dfbe commit 3fcb809
Show file tree
Hide file tree
Showing 31 changed files with 129 additions and 96 deletions.
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ On a Linux-based machine with `bash` installed, run the script:
> However, if you run as root, a user svcfmtm will be created for you.
```bash
curl -L https://get.fmtm.dev -o install.sh
curl -L https://https://hotosm.github.io/fmtm-installer/install.sh -o install.sh
bash install.sh

# Then follow the prompts
Expand Down
178 changes: 89 additions & 89 deletions LICENSE.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ To install for a quick test, or on a production instance,
use the convenience script:

```bash
curl -L https://get.fmtm.dev -o install.sh
curl -L https://https://hotosm.github.io/fmtm-installer/install.sh -o install.sh
bash install.sh
```

Expand Down
2 changes: 1 addition & 1 deletion docs/dev/Production.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ your own cloud server.
### Run the install script

```bash
curl -L https://get.fmtm.dev -o install.sh
curl -L https://https://hotosm.github.io/fmtm-installer/install.sh -o install.sh
bash install.sh

# Then follow the prompts
Expand Down
11 changes: 9 additions & 2 deletions src/backend/migrate-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,15 @@ check_if_missing_migrations() {
")
echo "Existing migrations: ${existing_scripts}"

# Iterate through files under /opt/migrations
for script_file in /opt/migrations/*.sql; do
# Check if there are .sql files under /opt/migrations and iterate
migration_files=$(find /opt/migrations -maxdepth 1 -type f -name '*.sql')
if [ -z "$migration_files" ]; then
echo "No migration scripts found in /opt/migrations directory."
return
fi

# Iterate through migration files
for script_file in $migration_files; do
# Extract the script name from the file path
script_name=$(basename "$script_file")

Expand Down
8 changes: 8 additions & 0 deletions src/backend/migrations/000-reset-migrations-table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- ## Migration reset the _migrations table.

-- Start a transaction
BEGIN;
-- Delete all records
DELETE FROM public._migrations;
-- Commit the transaction
COMMIT;
File renamed without changes.
22 changes: 20 additions & 2 deletions src/backend/migrations/init/fmtm_base_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,21 @@ CREATE TYPE public.projectvisibility AS ENUM (
);
ALTER TYPE public.projectvisibility OWNER TO fmtm;

CREATE TYPE public.tasksplittype AS ENUM (
'DIVIDE_ON_SQUARE',
'CHOOSE_AREA_AS_TASK',
'TASK_SPLITTING_ALGORITHM'
);
ALTER TYPE public.tasksplittype OWNER TO fmtm;

CREATE TYPE public.communitytype AS ENUM (
'OSM_COMMUNITY',
'COMPANY',
'NON_PROFIT',
'UNIVERSITY',
'OTHER'
);
ALTER TYPE public.communitytype OWNER TO fmtm;


-- Extra
Expand Down Expand Up @@ -257,7 +272,9 @@ CREATE TABLE public.organisations (
logo character varying,
description character varying,
url character varying,
type public.organisationtype NOT NULL,
type public.organisationtype DEFAULT 'FREE',
community_type public.communitytype DEFAULT 'OSM_COMMUNITY',
created_by integer,
approved BOOLEAN DEFAULT false,
odk_central_url character varying,
odk_central_user character varying,
Expand Down Expand Up @@ -352,7 +369,7 @@ CREATE TABLE public.projects (
form_config_file bytea,
data_extract_type character varying,
data_extract_url character varying,
task_split_type character varying,
task_split_type public.tasksplittype,
hashtags character varying[]
);
ALTER TABLE public.projects OWNER TO fmtm;
Expand Down Expand Up @@ -502,6 +519,7 @@ CREATE TABLE public.users (
name character varying,
city character varying,
country character varying,
profile_img character varying,
email_address character varying,
is_email_verified boolean,
is_expert boolean,
Expand Down

0 comments on commit 3fcb809

Please sign in to comment.