From fb78619fa91a03bdaf5ac3ebef8019ea431b037d Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Wed, 13 Aug 2025 23:25:40 +0100 Subject: [PATCH 1/4] define cors also for development (#302) --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 0caabd00..58170d80 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -50,7 +50,7 @@ services: SECRET: 'SECRET' CORS_ENABLED: 'true' - CORS_ORIGIN: 'http://localhost:8080' + CORS_ORIGIN: 'array:http://localhost:8080,http://localhost:5174' DB_CLIENT: 'pg' DB_HOST: 'database' From a778fcf97180c065adfe1fecbffc82aab653dde6 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Thu, 14 Aug 2025 00:10:30 +0100 Subject: [PATCH 2/4] backend readme: import dump instructions (#296) --- backend/README.md | 70 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/backend/README.md b/backend/README.md index 0c917ee9..4b17e2d8 100644 --- a/backend/README.md +++ b/backend/README.md @@ -1,5 +1,12 @@ +# Utopia Backend + +To run the backend you can simply execute +`docker-compose up` + +## Pull Data from Docker to Harddrive In order to pull data from your locally running backend (see [docker-compose](../app/docker-compose.yml)) to your local harddrive, you can run the following command + ``` npx directus-sync pull \ --directus-url http://localhost:8055 \ @@ -7,6 +14,7 @@ npx directus-sync pull \ --directus-password admin123 ``` +## Push Data from Harddrive to Docker To push local changes or to seed directus use the following command ``` npx directus-sync push \ @@ -22,6 +30,66 @@ Either keep a copy of the `/data/database` folder or run the following command t docker exec -t utopia-map-database-1 pg_dumpall -c -U directus > dump.sql ``` +## How to apply a database dump to the docker + +Assuming you run docker-compose with the default postgress credentials and have the dump in cwd as ./dump.sql, execute: + +Find current schema name: +``` +echo "SELECT CURRENT_SCHEMA, CURRENT_SCHEMA();" | docker exec -i utopia-map-database-1 /bin/bash -c "PGPASSWORD=directus psql --username directus" +``` +> current_schema | current_schema +> ----------------+---------------- +> public | public +> (1 row) + +Drop schemata (loses all data): +``` +echo "DROP SCHEMA public CASCADE;" | docker exec -i utopia-map-database-1 /bin/bash -c "PGPASSWORD=directus psql --username directus" + +echo "DROP SCHEMA tiger CASCADE;" | docker exec -i utopia-map-database-1 /bin/bash -c "PGPASSWORD=directus psql --username directus" + +echo "DROP SCHEMA tiger_data CASCADE;" | docker exec -i utopia-map-database-1 /bin/bash -c "PGPASSWORD=directus psql --username directus" + +echo "DROP SCHEMA topology CASCADE;" | docker exec -i utopia-map-database-1 /bin/bash -c "PGPASSWORD=directus psql --username directus" +``` +> drop cascades to table ... +> ... +> DROP SCHEMA + +Create the public schema again: +``` +echo "CREATE SCHEMA public;" | docker exec -i utopia-map-database-1 /bin/bash -c "PGPASSWORD=directus psql --username directus" +``` + +Verify schemata: +``` +echo "select schema_name from information_schema.schemata;" | docker exec -i utopia-map-database-1 /bin/bash -c "PGPASSWORD=directus psql --username directus" +``` + +Verify database is empty: +``` +echo "\dt" | docker exec -i utopia-map-database-1 /bin/bash -c "PGPASSWORD=directus psql --username directus directus" +``` +> Did not find any relations. + +Create admin role & grant it: +``` +echo "CREATE ROLE admin;" | docker exec -i utopia-map-database-1 /bin/bash -c "PGPASSWORD=directus psql --username directus directus" +``` + +Apply dump: +``` +docker exec -i utopia-map-database-1 /bin/bash -c "PGPASSWORD=directus psql -v ON_ERROR_STOP=1 --username directus directus" < ./dump.sql +``` +> Bring time depending on the dump size. + +Reassign ownership of tables: +``` +echo "REASSIGN OWNED BY admin TO directus" | docker exec -i utopia-map-database-1 /bin/bash -c "PGPASSWORD=directus psql --username directus directus +``` +> REASSIGN OWNED + ## Access Data on local drive In order to access the postgress data mounted to the local drive at `/data/database` you need to make it accessible (assuming you are not root): @@ -29,4 +97,4 @@ In order to access the postgress data mounted to the local drive at `/data/datab sudo chmod 777 -R ./data/ ``` -This process is to be repeated whenever you restart the database docker container \ No newline at end of file +This process is to be repeated whenever you restart the database docker container From cfd7ca1a26d64366b9987f17286b89c5e783a661 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Thu, 14 Aug 2025 00:12:39 +0100 Subject: [PATCH 3/4] refactor(app): default backend: localhost (#303) * use api config everywhere, default to localhost, ignore .env file, provide .env.dist * fix lint --- app/{.env => .env.dist} | 3 ++- app/.gitignore | 1 + app/src/App.tsx | 6 +++--- app/src/ModalContent.tsx | 4 +++- app/src/api/directus.ts | 5 ++++- app/src/config/index.ts | 2 +- app/src/pages/Landingpage.tsx | 3 ++- app/src/pages/MapContainer.tsx | 3 ++- 8 files changed, 18 insertions(+), 9 deletions(-) rename app/{.env => .env.dist} (68%) diff --git a/app/.env b/app/.env.dist similarity index 68% rename from app/.env rename to app/.env.dist index 4d364d32..9d9b38ca 100644 --- a/app/.env +++ b/app/.env.dist @@ -1,4 +1,5 @@ VITE_OPEN_COLLECTIVE_API_KEY=your_key -VITE_API_URL=https://api.utopia-lab.org +VITE_API_URL=http://localhost:8055/ +#VITE_API_URL=https://api.utopia-lab.org VITE_VALIDATE_INVITE_FLOW_ID=01d61db0-25aa-4bfa-bc24-c6a8f208a455 VITE_REDEEM_INVITE_FLOW_ID=cc80ec73-ecf5-4789-bee5-1127fb1a6ed4 diff --git a/app/.gitignore b/app/.gitignore index 3bdd52eb..3a773879 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -1,3 +1,4 @@ node_modules/ dist/ .DS_Store +.env \ No newline at end of file diff --git a/app/src/App.tsx b/app/src/App.tsx index 39b07772..56b95f24 100644 --- a/app/src/App.tsx +++ b/app/src/App.tsx @@ -113,7 +113,7 @@ function App() { path: '/' + l.name, // url icon: ( code.replace(/stroke=".*?"/g, 'stroke="currentColor"') @@ -134,7 +134,7 @@ function App() { link.rel = 'icon' document.getElementsByTagName('head')[0].appendChild(link) } - link.href = map?.logo && 'https://api.utopia-lab.org/assets/' + map.logo // Specify the path to your favicon + link.href = map?.logo && config.apiUrl + 'assets/' + map.logo // Specify the path to your favicon } setLoading(false) @@ -148,7 +148,7 @@ function App() {
void map?: any @@ -31,7 +33,7 @@ export function Welcome1({ clickAction1, map }: ChapterProps) {

Welcome to {map?.name || 'Utopia Map'}

It is a tool for collaborative mapping to connect local initiatives, people and events. diff --git a/app/src/api/directus.ts b/app/src/api/directus.ts index 7b32f8b4..140ca4ba 100644 --- a/app/src/api/directus.ts +++ b/app/src/api/directus.ts @@ -4,6 +4,9 @@ /* eslint-disable @typescript-eslint/no-unsafe-return */ import { createDirectus, rest, authentication } from '@directus/sdk' +// eslint-disable-next-line import/no-relative-parent-imports +import { config } from '../config' + import type { AuthenticationData, AuthenticationStorage } from '@directus/sdk' import type { Point } from 'geojson' import type { Item } from 'utopia-ui' @@ -94,7 +97,7 @@ export async function getRefreshToken() { return auth!.refresh_token } -export const directusClient = createDirectus('https://api.utopia-lab.org/') +export const directusClient = createDirectus(config.apiUrl) .with(rest()) .with( authentication('json', { diff --git a/app/src/config/index.ts b/app/src/config/index.ts index 28ab494c..e82ac975 100644 --- a/app/src/config/index.ts +++ b/app/src/config/index.ts @@ -1,5 +1,5 @@ export const config = { - apiUrl: String(import.meta.env.VITE_API_URL ?? 'https://api.utopia-lab.org'), + apiUrl: String(import.meta.env.VITE_API_URL ?? 'http://localhost:8055/'), validateInviteFlowId: String( import.meta.env.VITE_VALIDATE_INVITE_FLOW_ID ?? '01d61db0-25aa-4bfa-bc24-c6a8f208a455', ), diff --git a/app/src/pages/Landingpage.tsx b/app/src/pages/Landingpage.tsx index ce11c382..9387411c 100644 --- a/app/src/pages/Landingpage.tsx +++ b/app/src/pages/Landingpage.tsx @@ -12,6 +12,7 @@ import { useNavigate } from 'react-router-dom' import { MapOverlayPage } from 'utopia-ui' import { itemsApi } from '../api/itemsApi' +import { config } from '../config' export const Landingpage = () => { const [isLandingpageVisible, setIsLandingpageVisible] = useState(true) @@ -137,7 +138,7 @@ export const Landingpage = () => {

  • diff --git a/app/src/pages/MapContainer.tsx b/app/src/pages/MapContainer.tsx index fe3140a1..9818286e 100644 --- a/app/src/pages/MapContainer.tsx +++ b/app/src/pages/MapContainer.tsx @@ -23,6 +23,7 @@ import { } from 'utopia-ui' import { itemsApi } from '../api/itemsApi' +import { config } from '../config' import type { Place } from '../api/directus' import type { LayerProps } from 'utopia-ui' @@ -94,7 +95,7 @@ function MapContainer({ layers, map }: { layers: LayerProps[]; map: any }) { id={layer.id} key={layer.id} name={layer.name} - menuIcon={'https://api.utopia-lab.org/assets/' + layer.menuIcon} + menuIcon={config.apiUrl + 'assets/' + layer.menuIcon} menuText={layer.menuText} menuColor={layer.menuColor} markerIcon={layer.markerIcon} From 9b2ac9f74f58552bc0e87af2df2ce06632ae446b Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Thu, 14 Aug 2025 00:14:29 +0100 Subject: [PATCH 4/4] directus minimal seed & seed instructions (#305) --- backend/README.md | 18 ++++++++++++++++++ backend/directus-config/seed/maps.json | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 backend/directus-config/seed/maps.json diff --git a/backend/README.md b/backend/README.md index 4b17e2d8..c0bbcfc9 100644 --- a/backend/README.md +++ b/backend/README.md @@ -23,6 +23,24 @@ npx directus-sync push \ --directus-password admin123 ``` +## 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 +``` + +## 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 +``` + ## Backup Database Either keep a copy of the `/data/database` folder or run the following command to get an sql dump diff --git a/backend/directus-config/seed/maps.json b/backend/directus-config/seed/maps.json new file mode 100644 index 00000000..59a8443b --- /dev/null +++ b/backend/directus-config/seed/maps.json @@ -0,0 +1,18 @@ +{ + "collection": "maps", + "meta": { + "insert_order": 1, + "create": true, + "update": true, + "delete": true, + "preserve_ids": false, + "ignore_on_update": [] + }, + "data": [ + { + "_sync_id": "local-development", + "name": "Local Development", + "url": "http://local.development" + } + ] +} \ No newline at end of file