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