diff --git a/README.md b/README.md index 42b0920a..39a67220 100644 --- a/README.md +++ b/README.md @@ -430,16 +430,7 @@ With the following commands it is possible to get a proper state of the database ## Initial Setup up the RDS database and the user -Right now the initial setup on the RDS database for the stagings *dev*, *int* and *prod* can be obtained -with the helper script `scripts/setup_rds_db.sh`. The credentials come from `ssm`. To -setup the RDS database on int, run following command (the PROFILE variable denotes in what account the -parameters are stored): - -```bash - summon -p `ssm` -D APP_ENV=int -D PROFILE=swisstopo-bgdi-dev scripts/setup_rds_db.sh -``` - -**Note:** The script won't delete the existing database. +The RDS database and user are managed by terraform. See [the service-stac module for int](https://github.com/geoadmin/infra-terraform-bgdi/blob/master/tf/aws/swisstopo-bgdi/systems-int/data/service-stac/db.tf) for example. ## Deploying the project and continuous integration diff --git a/scripts/setup_rds_db.sh b/scripts/setup_rds_db.sh deleted file mode 100755 index 194dc75d..00000000 --- a/scripts/setup_rds_db.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash -set -e -set -u - -MY_DIR=$(dirname "$(readlink -f "$0")") -# The following variables are used from ENV which -# is populated by summon with the following command -# summon -p `which summon-gopass` -D APP_ENV=int scripts/setup_rds_db.sh -# where the environment is set by the APP_ENV variable - -# create db -SQL_CREATE_DB="$(envsubst < scripts/sql/create_db.sql)" - -# create user -SQL_CREATE_USER="$(envsubst < scripts/sql/create_user.sql)" - -create_user(){ - echo "create user" - PGPASSWORD=${DB_SUPER_PW} psql -qAt -X -U ${DB_SUPER_USER} -h ${DB_HOST} -p ${DB_PORT} -d template1 -c "${SQL_CREATE_USER}" -} - -create_db(){ - echo "create db" - if [ "$(PGPASSWORD=${DB_SUPER_PW} psql -U ${DB_SUPER_USER} -h ${DB_HOST} -p ${DB_PORT} -d template1 -tAc "SELECT 1 FROM pg_database WHERE datname='${DB_NAME}'" )" = '1' ]; then - echo "db ${DB_NAME} already exists" - else - PGPASSWORD=${DB_SUPER_PW} psql -qAt -X -U ${DB_SUPER_USER} -h ${DB_HOST} -p ${DB_PORT} -d template1 -c "${SQL_CREATE_DB}" - fi -} - -grant_privileges(){ - echo "grant privileges" - PGPASSWORD=${DB_SUPER_PW} psql -qAt -X -U ${DB_SUPER_USER} -h ${DB_HOST} -p ${DB_PORT} -d ${DB_NAME} -c "GRANT ALL PRIVILEGES ON DATABASE ${DB_NAME} to ${DB_USER}"; -} - -setup_postgis(){ - echo "setup postgis" - PGPASSWORD=${DB_SUPER_PW} psql -qAt -X -U ${DB_SUPER_USER} -h ${DB_HOST} -p ${DB_PORT} -d ${DB_NAME} -f "${MY_DIR}/sql/install_postgis.sql" -} - -echo "[$(date +"%F %T")] start" -create_user -create_db -setup_postgis -grant_privileges -echo "[$(date +"%F %T")] end" diff --git a/scripts/sql/create_db.sql b/scripts/sql/create_db.sql deleted file mode 100644 index a518c0cb..00000000 --- a/scripts/sql/create_db.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE DATABASE ${DB_NAME} - ENCODING = 'UTF8' - LC_COLLATE = 'en_US.UTF-8' - LC_CTYPE = 'en_US.UTF-8' - CONNECTION LIMIT -1 - TEMPLATE template1; diff --git a/scripts/sql/create_user.sql b/scripts/sql/create_user.sql deleted file mode 100644 index 22ae08bc..00000000 --- a/scripts/sql/create_user.sql +++ /dev/null @@ -1,13 +0,0 @@ -BEGIN; -DO $$ -BEGIN -CREATE ROLE ${DB_USER} WITH - NOSUPERUSER INHERIT NOCREATEROLE NOCREATEDB LOGIN NOREPLICATION NOBYPASSRLS - PASSWORD '${DB_PW}' VALID UNTIL 'infinity'; -EXCEPTION WHEN DUPLICATE_OBJECT THEN - RAISE NOTICE 'not creating role ${DB_USER} -- it already exists'; -END -$$; -ALTER ROLE ${DB_USER} - SET log_statement TO 'all'; -COMMIT; \ No newline at end of file diff --git a/scripts/sql/install_postgis.sql b/scripts/sql/install_postgis.sql deleted file mode 100644 index d358cff8..00000000 --- a/scripts/sql/install_postgis.sql +++ /dev/null @@ -1,17 +0,0 @@ -begin; --- https://docs.aws.amazon.com/de_de/AmazonRDS/latest/UserGuide/Appendix.PostgreSQL.CommonDBATasks.html#Appendix.PostgreSQL.CommonDBATasks.PostGIS -CREATE EXTENSION IF NOT EXISTS postgis; -CREATE EXTENSION IF NOT EXISTS postgis_topology; -alter schema topology owner to rds_superuser; - -CREATE OR REPLACE FUNCTION exec(text) returns text language plpgsql volatile AS $f$ BEGIN EXECUTE $1; RETURN $1; END; $f$; - -SELECT exec('ALTER TABLE ' || quote_ident(s.nspname) || '.' || quote_ident(s.relname) || ' OWNER TO rds_superuser;') - FROM ( - SELECT nspname, relname - FROM pg_class c JOIN pg_namespace n ON (c.relnamespace = n.oid) - WHERE nspname in ('tiger','topology') AND - relkind IN ('r','S','v') ORDER BY relkind = 'S') -s; - -commit; diff --git a/scripts/sql/samples/load_random_data.sql b/scripts/sql/load_random_data.sql similarity index 94% rename from scripts/sql/samples/load_random_data.sql rename to scripts/sql/load_random_data.sql index cd0f4590..be27bdb3 100644 --- a/scripts/sql/samples/load_random_data.sql +++ b/scripts/sql/load_random_data.sql @@ -6,6 +6,10 @@ this query will load random data into: you can set the number of collections and the number of items for each collection. see inline comments +NOTE ######### +As of 2025, this script is outdated. Several new model fields have been added. +If you want to use this, please update the script beforehand. + */ diff --git a/secrets.yml b/secrets.yml deleted file mode 100644 index 9d1bb5ce..00000000 --- a/secrets.yml +++ /dev/null @@ -1,11 +0,0 @@ -DB_NAME: !var /amazon-rds/bgdi-$APP_ENV/service-stac/db_name --profile $PROFILE -DB_USER: !var /amazon-rds/bgdi-$APP_ENV/service-stac/user --profile $PROFILE -DB_PW: !var /amazon-rds/bgdi-$APP_ENV/service-stac/password --profile $PROFILE - -AWS_ACCESS_KEY_ID: !var /service-stac/$APP_ENV/aws_access_key_id --profile $PROFILE -AWS_SECRET_ACCESS_KEY: !var /service-stac/$APP_ENV/aws_secret_access_key --profile $PROFILE - -DB_HOST: !var /amazon-rds/bgdi-$APP_ENV/host/domain --profile $PROFILE -DB_PORT: !var /amazon-rds/bgdi-$APP_ENV/host/port --profile $PROFILE -DB_SUPER_USER: !var /amazon-rds/bgdi-$APP_ENV/admin/user --profile $PROFILE -DB_SUPER_PW: !var /amazon-rds/bgdi-$APP_ENV/admin/password --profile $PROFILE