Skip to content
Snippets Groups Projects
Commit f3fd9e22 authored by Maximilian Schaldach's avatar Maximilian Schaldach :cactus:
Browse files

Merge branch 'main' into 114-switch-to-hubterra-tsmdl

parents 93439988 d5fc3820
No related branches found
No related tags found
1 merge request!180Resolve "Switch to HubTerra TSMDL"
Pipeline #409645 passed
......@@ -170,7 +170,7 @@ ALLOWED_VOS=UFZ-Timeseries-Management
############################################################
# frost (tomcat)
############################################################
TOMCAT_IMAGE_TAG=9
TOMCAT_IMAGE_TAG=9.0.90
############################################################
......@@ -180,6 +180,7 @@ TSM_DL_IMAGE_TAG=latest
TSM_DL_ENVIRONMENT=local # one of: local, staging, production
UVICORN_ARGS=
DB_API_IMAGE_TAG=latest
############################################################
# flyway
############################################################
......
......@@ -316,6 +316,29 @@ services:
database:
condition: service_healthy
# Summary
# =======
# brief:
# dir:
# see also:
#
# Description
# ===========
# TODO
timeio-db-api:
image: "registry.hzdr.de/ufz-tsm/timeio-db-api/timeio-db-api:${DB_API_IMAGE_TAG}"
restart: "${RESTART}"
entrypoint: "sh /app/start.sh"
environment:
DB_URL: "postgresql://\
${CREATEDB_POSTGRES_USER}:\
${CREATEDB_POSTGRES_PASSWORD}@\
${CREATEDB_POSTGRES_HOST}/\
${CREATEDB_POSTGRES_DATABASE}"
UVICORN_ARGS: "${UVICORN_ARGS} --root-path /db_api"
depends_on:
database:
condition: service_healthy
# Summary
# =======
......@@ -350,6 +373,7 @@ services:
# TODO
flyway:
image: flyway/flyway:${FLYWAY_IMAGE_TAG}
user: "${UID}:${UID}"
command: -configFiles=/flyway/conf/flyway.conf migrate
volumes:
- ./flyway/migrations:/flyway/sql
......
flyway.baselineOnMigrate=true
flyway.locations=filesystem:/flyway/sql
flyway.defaultSchema=public
flyway.schemas=public,config_db
\ No newline at end of file
flyway.schemas=public,config_db
flyway.jdbcProperties.sslrootcert=/etc/ssl/certs/ca-certificates.crt
\ No newline at end of file
import os
import sys
import psycopg
from psycopg.rows import dict_row
INSERT_QUERY = """
INSERT INTO public.schema_thing_mapping (schema, thing_uuid)
VALUES (%(schema_name)s, %(thing_uuid)s)
"""
def get_schemas_with_things(cur):
return cur.execute(
"""SELECT schemaname FROM pg_tables
WHERE tablename = 'thing';"""
).fetchall()
def get_things(cur, schema):
return cur.execute(
f"""SELECT uuid::varchar from {schema}.thing;"""
).fetchall()
def get_schema_thing_dict(cur):
schemas_things_dict = list()
schemas = get_schemas_with_things(cur)
for schema in schemas:
things = get_things(cur, schema["schemaname"])
for thing in things:
schemas_things_dict.append({"schema_name": schema["schemaname"],
"thing_uuid": thing["uuid"]})
return schemas_things_dict
usage = f"""{os.path.basename(__file__)} DB_URL
Maps things to the related schema/datasource of existing schemas and things
and inserts it into the public.schema_thing_mapping table.
DB_URL is the connection string of the respective database
Example:
DB_URL=postgresql://postgres:postgres@localhost:5432/postgres
"""
if __name__ == "__main__":
if len(sys.argv) != 2:
print(usage)
sys.exit(1)
with psycopg.connect(sys.argv[1]) as conn:
with conn.cursor(row_factory=dict_row) as cursor:
schemas_things = get_schema_thing_dict(cursor)
try:
cursor.executemany(INSERT_QUERY, schemas_things)
conn.commit()
print("Data inserted successfully")
except Exception as error:
conn.rollback()
print(f"Failed to insert data: {error}")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment