diff --git a/app/.env.dist b/app/.env.dist index 5dc2cc82..f2850d71 100644 --- a/app/.env.dist +++ b/app/.env.dist @@ -3,5 +3,6 @@ VITE_API_URL=http://localhost:8055/ #VITE_API_URL=https://api.utopia-lab.org VITE_MAP_URL=http://local.development #VITE_MAP_URL=CURRENT_WINDOW_LOCATION +#VITE_DIRECTUS_ADMIN_ROLE= VITE_VALIDATE_INVITE_FLOW_ID=01d61db0-25aa-4bfa-bc24-c6a8f208a455 VITE_REDEEM_INVITE_FLOW_ID=cc80ec73-ecf5-4789-bee5-1127fb1a6ed4 diff --git a/app/README.md b/app/README.md new file mode 100644 index 00000000..c54058af --- /dev/null +++ b/app/README.md @@ -0,0 +1,11 @@ +# App + +## Troubleshooting + +Map doesn't load and the Error `You must define the Admin roll in the .env file!` shows in the console. + +In order to get the map running you need to define the correct uuid of the admin roll in the `.env` file. + +Go to http://localhost:8055 and login with the admin credentials. Navigate to http://localhost:8055/admin/settings/roles and click `Administrator` and copy the UUID from the URL. + +Put this UUID in the `.env` as `VITE_DIRECTUS_ADMIN_ROLE=UUID` \ No newline at end of file diff --git a/app/src/App.tsx b/app/src/App.tsx index caece166..4707eb27 100644 --- a/app/src/App.tsx +++ b/app/src/App.tsx @@ -156,10 +156,7 @@ function App() { embedded={embedded} openCollectiveApiKey={config.openCollectiveApiKey} > - + {tagsApi && } diff --git a/app/src/config/index.ts b/app/src/config/index.ts index 4f1630d5..98c8b891 100644 --- a/app/src/config/index.ts +++ b/app/src/config/index.ts @@ -1,6 +1,7 @@ export const config = { apiUrl: String(import.meta.env.VITE_API_URL ?? 'http://localhost:8055/'), mapUrl: String(import.meta.env.VITE_MAP_URL ?? 'http://local.development'), + adminRole: String(import.meta.env.VITE_DIRECTUS_ADMIN_ROLE ?? ''), validateInviteFlowId: String( import.meta.env.VITE_VALIDATE_INVITE_FLOW_ID ?? '01d61db0-25aa-4bfa-bc24-c6a8f208a455', ), @@ -10,4 +11,8 @@ export const config = { openCollectiveApiKey: String(import.meta.env.VITE_OPEN_COLLECTIVE_API_KEY ?? ''), } +if (config.adminRole === '') { + throw Error('You must define the Admin roll in the .env file!') +} + export type Config = typeof config diff --git a/backend/README.md b/backend/README.md index 3d8ab163..8ba6775b 100644 --- a/backend/README.md +++ b/backend/README.md @@ -12,12 +12,8 @@ npx directus-sync push \ --directus-email admin@it4c.dev \ --directus-password admin123 -npx directus-sync seed push \ - --directus-url http://localhost:8055 \ - --directus-email admin@it4c.dev \ - --directus-password admin123 +./seed.sh -./directus-config/manual/seed.sh ``` ## Pull Data from Docker to Harddrive @@ -44,27 +40,8 @@ npx directus-sync push \ ## Seed Data for local development -Seed the development data via: -``` -npx directus-sync seed push \ - --directus-url http://localhost:8055 \ - --directus-email admin@it4c.dev \ - --directus-password admin123 -``` +In order to seed the development data, run the script `backend/seed.sh`. -## Seed Data - find differences - -In order so see what changes would appear when seeding, you can execute: -``` -npx directus-sync seed diff \ - --directus-url http://localhost:8055 \ - --directus-email admin@it4c.dev \ - --directus-password admin123 -``` - -## Manual Seed - -In order to seed files and additional data not covered by `directus-sync` run the script `backend/directus-config/manual/seed.sh`. ## Backup Database diff --git a/backend/directus-config/manual/sql/branding-logo.sql b/backend/directus-config/manual/sql/branding-logo.sql deleted file mode 100644 index 101b948c..00000000 --- a/backend/directus-config/manual/sql/branding-logo.sql +++ /dev/null @@ -1,7 +0,0 @@ -DELETE FROM public.directus_files WHERE id = '412c25dc-a3b7-4114-b64b-cac2d6b46db3'; - -COPY public.directus_files (id, storage, filename_disk, filename_download, title, type, folder, uploaded_by, created_on, modified_by, modified_on, charset, filesize, width, height, duration, embed, description, location, tags, metadata, focal_point_x, focal_point_y, tus_id, tus_data, uploaded_on) FROM stdin; -412c25dc-a3b7-4114-b64b-cac2d6b46db3 local 412c25dc-a3b7-4114-b64b-cac2d6b46db3.svg utopia-logo.svg utopia-logo image/svg+xml \N \N 2025-08-12 11:26:36.539+00 \N 2025-08-12 11:27:07.646+00 \N 22906 \N \N \N \N \N \N \N \N \N \N \N \N 2025-08-12 11:26:36.555+00 -\. - -UPDATE public.directus_settings SET project_logo = '412c25dc-a3b7-4114-b64b-cac2d6b46db3'; diff --git a/backend/directus-config/manual/seed.sh b/backend/directus-config/seed-manual/seed.sh similarity index 64% rename from backend/directus-config/manual/seed.sh rename to backend/directus-config/seed-manual/seed.sh index a31092e2..087f2abb 100755 --- a/backend/directus-config/manual/seed.sh +++ b/backend/directus-config/seed-manual/seed.sh @@ -3,17 +3,9 @@ # base setup SCRIPT_PATH=$(realpath $0) SCRIPT_DIR=$(dirname $SCRIPT_PATH) -ROOT_DIR=$SCRIPT_DIR/../../.. -DATA_DIR=$ROOT_DIR/data -DATA_UPLOADS_DIR=$DATA_DIR/uploads - -SEED_FILES_DIR=$SCRIPT_DIR/files SEED_SQL_DIR=$SCRIPT_DIR/sql -# copy files -cp $SEED_FILES_DIR/* $DATA_UPLOADS_DIR/ - # apply database updates for filename in $SEED_SQL_DIR/*.sql; do docker exec -i utopia-map-database-1 /bin/bash -c "PGPASSWORD=directus psql -v ON_ERROR_STOP=1 --username directus directus" < $filename diff --git a/backend/directus-config/seed-manual/sql/branding-logo.sql b/backend/directus-config/seed-manual/sql/branding-logo.sql new file mode 100644 index 00000000..e9efc137 --- /dev/null +++ b/backend/directus-config/seed-manual/sql/branding-logo.sql @@ -0,0 +1 @@ +UPDATE public.directus_settings SET project_logo = (SELECT id FROM directus_files WHERE filename_download = 'utopia-logo.svg'); diff --git a/backend/directus-config/seeds/.gitignore b/backend/directus-config/seeds/.gitignore new file mode 100644 index 00000000..eb9ad4c4 --- /dev/null +++ b/backend/directus-config/seeds/.gitignore @@ -0,0 +1,3 @@ +* +!development/ +!.gitignore \ No newline at end of file diff --git a/backend/directus-config/seeds/development/directus/directus_files.json b/backend/directus-config/seeds/development/directus/directus_files.json new file mode 100644 index 00000000..7b23b240 --- /dev/null +++ b/backend/directus-config/seeds/development/directus/directus_files.json @@ -0,0 +1,14 @@ +{ + "collection": "directus_files", + "data": [ + { + "_sync_id": "utopia-logo", + "_file_path": "./files/utopia-logo.svg", + "storage": "local", + "filename_download": "utopia-logo.svg", + "title": "Utopia Logo", + "tags": [], + "description": "Utopia Logo" + } + ] +} \ No newline at end of file diff --git a/backend/directus-config/manual/files/412c25dc-a3b7-4114-b64b-cac2d6b46db3.svg b/backend/directus-config/seeds/development/directus/files/utopia-logo.svg similarity index 100% rename from backend/directus-config/manual/files/412c25dc-a3b7-4114-b64b-cac2d6b46db3.svg rename to backend/directus-config/seeds/development/directus/files/utopia-logo.svg diff --git a/backend/directus-config/seed/layers.json b/backend/directus-config/seeds/development/directus/layers.json similarity index 100% rename from backend/directus-config/seed/layers.json rename to backend/directus-config/seeds/development/directus/layers.json diff --git a/backend/directus-config/seed/layers_maps.json b/backend/directus-config/seeds/development/directus/layers_maps.json similarity index 100% rename from backend/directus-config/seed/layers_maps.json rename to backend/directus-config/seeds/development/directus/layers_maps.json diff --git a/backend/directus-config/seed/maps.json b/backend/directus-config/seeds/development/directus/maps.json similarity index 100% rename from backend/directus-config/seed/maps.json rename to backend/directus-config/seeds/development/directus/maps.json diff --git a/backend/directus-config/seed/types.json b/backend/directus-config/seeds/development/directus/types.json similarity index 100% rename from backend/directus-config/seed/types.json rename to backend/directus-config/seeds/development/directus/types.json diff --git a/backend/directus-config/seeds/development/manual/branding-logo.sql b/backend/directus-config/seeds/development/manual/branding-logo.sql new file mode 100644 index 00000000..e9efc137 --- /dev/null +++ b/backend/directus-config/seeds/development/manual/branding-logo.sql @@ -0,0 +1 @@ +UPDATE public.directus_settings SET project_logo = (SELECT id FROM directus_files WHERE filename_download = 'utopia-logo.svg'); diff --git a/backend/extensions/package.json b/backend/extensions/package.json index 3d392c73..90366a48 100644 --- a/backend/extensions/package.json +++ b/backend/extensions/package.json @@ -1,6 +1,6 @@ { "name": "directus-extensions", "dependencies": { - "directus-extension-sync": "^3.0.3" + "directus-extension-sync": "^3.0.4" } } \ No newline at end of file diff --git a/backend/seed.sh b/backend/seed.sh new file mode 100755 index 00000000..ac58d444 --- /dev/null +++ b/backend/seed.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +# base setup +SCRIPT_PATH=$(realpath $0) +SCRIPT_DIR=$(dirname $SCRIPT_PATH) + +DIRECTUS_URL="${DIRECTUS_URL:-http://localhost:8055}" +DIRECTUS_EMAIL="${DIRECTUS_EMAIL:-admin@it4c.dev}" +DIRECTUS_PASSWORD="${DIRECTUS_PASSWORD:-admin123}" + +PGPASSWORD="${PGPASSWORD:-'directus'}" +PGUSER="${PGUSER:-'directus'}" +PGDATABASE="${PGDATABASE:-'directus'}" + +PROJECT_NAME="${PROJECT:-development}" +PROJECT_FOLDER=$SCRIPT_DIR/directus-config/seeds/$PROJECT_NAME + + +npx directus-sync seed push \ + --directus-url $DIRECTUS_URL \ + --directus-email $DIRECTUS_EMAIL \ + --directus-password $DIRECTUS_PASSWORD \ + --seed-path $PROJECT_FOLDER/directus + + +SEED_SQL_DIR=$PROJECT_FOLDER/manual + +# apply database updates +for filename in $SEED_SQL_DIR/*.sql; do + docker exec -i utopia-map-database-1 /bin/bash -c "PGPASSWORD=$PGPASSWORD psql -v ON_ERROR_STOP=1 --username $PGUSER $PGDATABASE" < $filename +done \ No newline at end of file