From 06a401204b31683bb4e46e919a57cdaac6a34949 Mon Sep 17 00:00:00 2001 From: cymed <102035587+cymed@users.noreply.github.com> Date: Thu, 25 Apr 2024 11:46:42 +0200 Subject: [PATCH 01/12] set obj_id sequences when importing --- .../interlis/interlis_importer_exporter.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py b/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py index 0138dde7a..bd2f43795 100644 --- a/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py +++ b/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py @@ -136,6 +136,10 @@ def interlis_import(self, xtf_file_input, show_selection_dialog=False, logs_next tww_session.commit() tww_session.close() + # Update the sequence values + self._progress_done(92, "Update sequence values...") + self._import_set_od_sequences() + # Update main_cover and main_wastewater_node self._progress_done(95, "Update main cover and refresh materialized views...") self._import_update_main_cover_and_refresh_mat_views() @@ -254,6 +258,37 @@ def _import_from_intermediate_schema(self, import_model): return interlisImporterToIntermediateSchema.session_tww + def _import_set_od_sequences(self): + connection = psycopg.connect(get_pgconf_as_psycopg_dsn(), **DEFAULTS_CONN_ARG) + if PSYCOPG_VERSION == 2: + connection.set_session(autocommit=True) + cursor = connection.cursor() + cursor.execute("SELECT tablename,shortcut_en FROM tww_sys.dictionary_od_table;") + tbl_instances = cursor.fetchall() + for instance in tbl_instances: + # check if a sequence exists + query = """SELECT 1 + FROM information_schema.sequences + WHERE sequence_schema = 'tww_od' + AND sequence_name = 'seq_{tbl_name}_oid'; + """.format(tbl_name = instance[0]) + cursor.execute(query) + is_seq = cursor.fetchone() + if is_seq: + logger.info(f"Update sequence of tww_od.{instance[0]}") + query = """ + SELECT SETVAL('tww_od.seq_{tbl_name}_oid' ,(SELECT max(seqs) FROM( + SELECT RIGHT(obj_id, 6)::int as seqs FROM tww_od.{tbl_name} WHERE obj_id ~ '{rgx}' + UNION + SELECT last_value as seqs FROM tww_od.seq_{tbl_name}_oid)foo)); + """.format(tbl_name = instance[0],rgx= ''.join([r'^.{8}', instance[1], r'\d{6}$'])) + cursor.execute(query) + seqval = cursor.fetchone() + logger.info(f"Updated sequence of tww_od.{instance[0]} to {seqval[0]}") + + connection.commit() + connection.close() + def _import_update_main_cover_and_refresh_mat_views(self): connection = psycopg.connect(get_pgconf_as_psycopg_dsn(), **DEFAULTS_CONN_ARG) if PSYCOPG_VERSION == 2: From 5ca0c81543ca19cf08c4872ef0f8e31f36216250 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 25 Apr 2024 09:51:15 +0000 Subject: [PATCH 02/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../interlis/interlis_importer_exporter.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py b/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py index bd2f43795..86b6d49a5 100644 --- a/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py +++ b/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py @@ -264,14 +264,16 @@ def _import_set_od_sequences(self): connection.set_session(autocommit=True) cursor = connection.cursor() cursor.execute("SELECT tablename,shortcut_en FROM tww_sys.dictionary_od_table;") - tbl_instances = cursor.fetchall() + tbl_instances = cursor.fetchall() for instance in tbl_instances: # check if a sequence exists query = """SELECT 1 FROM information_schema.sequences WHERE sequence_schema = 'tww_od' AND sequence_name = 'seq_{tbl_name}_oid'; - """.format(tbl_name = instance[0]) + """.format( + tbl_name=instance[0] + ) cursor.execute(query) is_seq = cursor.fetchone() if is_seq: @@ -281,7 +283,9 @@ def _import_set_od_sequences(self): SELECT RIGHT(obj_id, 6)::int as seqs FROM tww_od.{tbl_name} WHERE obj_id ~ '{rgx}' UNION SELECT last_value as seqs FROM tww_od.seq_{tbl_name}_oid)foo)); - """.format(tbl_name = instance[0],rgx= ''.join([r'^.{8}', instance[1], r'\d{6}$'])) + """.format( + tbl_name=instance[0], rgx="".join([r"^.{8}", instance[1], r"\d{6}$"]) + ) cursor.execute(query) seqval = cursor.fetchone() logger.info(f"Updated sequence of tww_od.{instance[0]} to {seqval[0]}") From 64effdb66ab9bdb42bad0ab62e583e8055f4d05d Mon Sep 17 00:00:00 2001 From: cymed <102035587+cymed@users.noreply.github.com> Date: Tue, 30 Apr 2024 14:04:03 +0200 Subject: [PATCH 03/12] move logic to sql --- datamodel/changelogs/0001/oid_generation.sql | 45 +++++++++++++++++++ .../interlis/interlis_importer_exporter.py | 28 +----------- 2 files changed, 46 insertions(+), 27 deletions(-) diff --git a/datamodel/changelogs/0001/oid_generation.sql b/datamodel/changelogs/0001/oid_generation.sql index 8cf4e115e..20acdf692 100644 --- a/datamodel/changelogs/0001/oid_generation.sql +++ b/datamodel/changelogs/0001/oid_generation.sql @@ -81,3 +81,48 @@ END; $BODY$ LANGUAGE plpgsql STABLE COST 100; + +CREATE OR REPLACE FUNCTION tww_sys.reset_od_seqval() + RETURNS void + LANGUAGE 'plpgsql' + COST 100 + VOLATILE NOT LEAKPROOF +AS $BODY$ +DECLARE + +tbl_name text; +rgx text; +BEGIN + BEGIN + FOR tbl_name,rgx IN ( + SELECT dot.tablename,pfx.prefix||dot.shortcut_en + FROM information_schema.sequences seq + LEFT JOIN tww_sys.dictionary_od_table dot ON seq.sequence_name = 'seq_'||dot.tablename||'_oid' + LEFT JOIN (SELECT prefix FROM tww_sys.oid_prefixes WHERE active) pfx on True + WHERE seq.sequence_schema = 'tww_od' AND dot.tablename IS NOT NULL) LOOP + EXECUTE FORMAT('SELECT SETVAL(''tww_od.seq_%1$I_oid'',(SELECT max(seqs) FROM( + SELECT RIGHT(obj_id, 6)::int as seqs FROM tww_od.%1$I WHERE regexp_match(obj_id, ''%2$s\d{6}$'') IS NOT NULL + UNION + SELECT last_value as seqs FROM tww_od.seq_%1$I_oid)foo));',tbl_name,rgx); + END LOOP; + END; +END; +$BODY$; + +CREATE OR REPLACE FUNCTION tww_sys.tr_reset_od_seqval() + RETURNS trigger + LANGUAGE 'plpgsql' + COST 100 + VOLATILE NOT LEAKPROOF +AS $BODY$ +BEGIN + PERFORM tww_sys.reset_od_seqval(); + RETURN NULL; +END; +$BODY$; + +CREATE TRIGGER update_od_seqval_from_prefixes + AFTER UPDATE + ON tww_sys.oid_prefixes + FOR EACH STATEMENT + EXECUTE FUNCTION tww_sys.tr_reset_od_seqval(); \ No newline at end of file diff --git a/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py b/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py index 86b6d49a5..00bd0bd83 100644 --- a/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py +++ b/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py @@ -263,33 +263,7 @@ def _import_set_od_sequences(self): if PSYCOPG_VERSION == 2: connection.set_session(autocommit=True) cursor = connection.cursor() - cursor.execute("SELECT tablename,shortcut_en FROM tww_sys.dictionary_od_table;") - tbl_instances = cursor.fetchall() - for instance in tbl_instances: - # check if a sequence exists - query = """SELECT 1 - FROM information_schema.sequences - WHERE sequence_schema = 'tww_od' - AND sequence_name = 'seq_{tbl_name}_oid'; - """.format( - tbl_name=instance[0] - ) - cursor.execute(query) - is_seq = cursor.fetchone() - if is_seq: - logger.info(f"Update sequence of tww_od.{instance[0]}") - query = """ - SELECT SETVAL('tww_od.seq_{tbl_name}_oid' ,(SELECT max(seqs) FROM( - SELECT RIGHT(obj_id, 6)::int as seqs FROM tww_od.{tbl_name} WHERE obj_id ~ '{rgx}' - UNION - SELECT last_value as seqs FROM tww_od.seq_{tbl_name}_oid)foo)); - """.format( - tbl_name=instance[0], rgx="".join([r"^.{8}", instance[1], r"\d{6}$"]) - ) - cursor.execute(query) - seqval = cursor.fetchone() - logger.info(f"Updated sequence of tww_od.{instance[0]} to {seqval[0]}") - + cursor.execute("PERFORM tww_sys.reset_od_seqval();") connection.commit() connection.close() From d381179b413991af17f787b8ab2087cab0d0a01c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 30 Apr 2024 12:04:22 +0000 Subject: [PATCH 04/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- datamodel/changelogs/0001/oid_generation.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/datamodel/changelogs/0001/oid_generation.sql b/datamodel/changelogs/0001/oid_generation.sql index 20acdf692..cc9770f4c 100644 --- a/datamodel/changelogs/0001/oid_generation.sql +++ b/datamodel/changelogs/0001/oid_generation.sql @@ -95,7 +95,7 @@ rgx text; BEGIN BEGIN FOR tbl_name,rgx IN ( - SELECT dot.tablename,pfx.prefix||dot.shortcut_en + SELECT dot.tablename,pfx.prefix||dot.shortcut_en FROM information_schema.sequences seq LEFT JOIN tww_sys.dictionary_od_table dot ON seq.sequence_name = 'seq_'||dot.tablename||'_oid' LEFT JOIN (SELECT prefix FROM tww_sys.oid_prefixes WHERE active) pfx on True @@ -105,7 +105,7 @@ BEGIN UNION SELECT last_value as seqs FROM tww_od.seq_%1$I_oid)foo));',tbl_name,rgx); END LOOP; - END; + END; END; $BODY$; @@ -122,7 +122,7 @@ END; $BODY$; CREATE TRIGGER update_od_seqval_from_prefixes - AFTER UPDATE + AFTER UPDATE ON tww_sys.oid_prefixes FOR EACH STATEMENT - EXECUTE FUNCTION tww_sys.tr_reset_od_seqval(); \ No newline at end of file + EXECUTE FUNCTION tww_sys.tr_reset_od_seqval(); From ea39657251cf84840d904bc79afae814e5b04c8a Mon Sep 17 00:00:00 2001 From: cymed <102035587+cymed@users.noreply.github.com> Date: Tue, 30 Apr 2024 14:10:59 +0200 Subject: [PATCH 05/12] swap perform to select --- plugin/teksi_wastewater/interlis/interlis_importer_exporter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py b/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py index 00bd0bd83..83cec2bd9 100644 --- a/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py +++ b/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py @@ -263,7 +263,7 @@ def _import_set_od_sequences(self): if PSYCOPG_VERSION == 2: connection.set_session(autocommit=True) cursor = connection.cursor() - cursor.execute("PERFORM tww_sys.reset_od_seqval();") + cursor.execute("SELECT tww_sys.reset_od_seqval();") connection.commit() connection.close() From 22b26ff5329dba39d7682dee14ef7e0c9491267b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 16 Jul 2024 12:45:05 +0000 Subject: [PATCH 06/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- plugin/teksi_wastewater/interlis/interlis_importer_exporter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py b/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py index 4e16a8c00..8f3d1ba37 100644 --- a/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py +++ b/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py @@ -267,7 +267,7 @@ def _import_set_od_sequences(self): connection = psycopg.connect(get_pgconf_as_psycopg_dsn(), **DEFAULTS_CONN_ARG) if PSYCOPG_VERSION == 2: connection.set_session(autocommit=True) - cursor = connection.cursor() + cursor = connection.cursor() cursor.execute("SELECT tww_sys.reset_od_seqval();") connection.commit() connection.close() From c7582061cfc7081f7daaed1f47f352519a1c6abb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 23 Jul 2024 08:55:35 +0000 Subject: [PATCH 07/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- plugin/teksi_wastewater/interlis/interlis_importer_exporter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py b/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py index 7aefd905e..040fc338b 100644 --- a/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py +++ b/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py @@ -123,7 +123,7 @@ def interlis_import(self, xtf_file_input, show_selection_dialog=False, logs_next # Update the sequence values self._progress_done(92, "Update sequence values...") self._import_set_od_sequences() - + # Update main_cover and main_wastewater_node self._progress_done(95, "Update main cover and refresh materialized views...") self._import_update_main_cover_and_refresh_mat_views() From b71f3320379240d91d3fbbd41c975df58e22c08c Mon Sep 17 00:00:00 2001 From: cymed <102035587+cymed@users.noreply.github.com> Date: Thu, 25 Jul 2024 16:47:54 +0200 Subject: [PATCH 08/12] fix indent --- plugin/teksi_wastewater/interlis/interlis_importer_exporter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py b/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py index 040fc338b..1718361c5 100644 --- a/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py +++ b/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py @@ -267,7 +267,7 @@ def _import_from_intermediate_schema(self, import_model): return interlisImporterToIntermediateSchema.session_tww def _import_set_od_sequences(self): - logger.info("Set Sequence values") + logger.info("Set Sequence values") DatabaseUtils.execute("SELECT tww_sys.reset_od_seqval();") def _import_manage_organisations(self): From 3768def43ea8cf273d0c2e3cc8753b613773a6fe Mon Sep 17 00:00:00 2001 From: cymed <102035587+cymed@users.noreply.github.com> Date: Thu, 5 Sep 2024 14:09:14 +0200 Subject: [PATCH 09/12] move to app --- datamodel/app/functions/oid_functions.sql | 88 +++++++++++++++++++ .../interlis/interlis_importer_exporter.py | 2 +- 2 files changed, 89 insertions(+), 1 deletion(-) diff --git a/datamodel/app/functions/oid_functions.sql b/datamodel/app/functions/oid_functions.sql index fec5483ff..b9b1a6483 100644 --- a/datamodel/app/functions/oid_functions.sql +++ b/datamodel/app/functions/oid_functions.sql @@ -40,3 +40,91 @@ END; $BODY$ LANGUAGE plpgsql STABLE COST 100; + +-- function for generating StandardOIDs + +CREATE OR REPLACE FUNCTION tww_sys.generate_oid(schema_name text, table_name text) + RETURNS text AS +$BODY$ +DECLARE + myrec_prefix record; + myrec_shortcut record; + myrec_seq record; +BEGIN + -- first we have to get the OID prefix + BEGIN + SELECT prefix::text INTO myrec_prefix FROM tww_sys.oid_prefixes WHERE active = TRUE; + EXCEPTION + WHEN NO_DATA_FOUND THEN + RAISE EXCEPTION 'no active record found in table tww_sys.oid_prefixes'; + WHEN TOO_MANY_ROWS THEN + RAISE EXCEPTION 'more than one active records found in table tww_sys.oid_prefixes'; + END; + -- test if prefix is of correct length + IF char_length(myrec_prefix.prefix) != 8 THEN + RAISE EXCEPTION 'character length of prefix must be 8'; + END IF; + --get table 2char shortcut + BEGIN + SELECT shortcut_en INTO STRICT myrec_shortcut FROM tww_sys.dictionary_od_table WHERE tablename = table_name; + EXCEPTION + WHEN NO_DATA_FOUND THEN + RAISE EXCEPTION 'dictionary entry for table % not found', table_name; + WHEN TOO_MANY_ROWS THEN + RAISE EXCEPTION 'dictonary entry for table % not unique', table_name; + END; + --get sequence for table + EXECUTE format('SELECT nextval(''%1$I.seq_%2$I_oid'') AS seqval', schema_name, table_name) INTO myrec_seq; + IF NOT FOUND THEN + RAISE EXCEPTION 'sequence for table % not found', table_name; + END IF; + RETURN myrec_prefix.prefix || myrec_shortcut.shortcut_en || to_char(myrec_seq.seqval,'FM000000'); +END; +$BODY$ + LANGUAGE plpgsql STABLE + COST 100; + +CREATE OR REPLACE FUNCTION tww_app.reset_od_seqval() + RETURNS void + LANGUAGE 'plpgsql' + COST 100 + VOLATILE NOT LEAKPROOF +AS $BODY$ +DECLARE + +tbl_name text; +rgx text; +BEGIN + BEGIN + FOR tbl_name,rgx IN ( + SELECT dot.tablename,pfx.prefix||dot.shortcut_en + FROM information_schema.sequences seq + LEFT JOIN tww_sys.dictionary_od_table dot ON seq.sequence_name = 'seq_'||dot.tablename||'_oid' + LEFT JOIN (SELECT prefix FROM tww_sys.oid_prefixes WHERE active) pfx on True + WHERE seq.sequence_schema = 'tww_od' AND dot.tablename IS NOT NULL) LOOP + EXECUTE FORMAT('SELECT SETVAL(''tww_od.seq_%1$I_oid'',(SELECT max(seqs) FROM( + SELECT RIGHT(obj_id, 6)::int as seqs FROM tww_od.%1$I WHERE regexp_match(obj_id, ''%2$s\d{6}$'') IS NOT NULL + UNION + SELECT last_value as seqs FROM tww_od.seq_%1$I_oid)foo));',tbl_name,rgx); + END LOOP; + END; +END; +$BODY$; + +CREATE OR REPLACE FUNCTION tww_app.tr_reset_od_seqval() + RETURNS trigger + LANGUAGE 'plpgsql' + COST 100 + VOLATILE NOT LEAKPROOF +AS $BODY$ +BEGIN + PERFORM tww_app.reset_od_seqval(); + RETURN NULL; +END; +$BODY$; + +CREATE TRIGGER update_od_seqval_from_prefixes + AFTER UPDATE + ON tww_sys.oid_prefixes + FOR EACH STATEMENT + EXECUTE FUNCTION tww_app.tr_reset_od_seqval(); \ No newline at end of file diff --git a/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py b/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py index 3bff784b7..10b27a636 100644 --- a/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py +++ b/plugin/teksi_wastewater/interlis/interlis_importer_exporter.py @@ -268,7 +268,7 @@ def _import_from_intermediate_schema(self, import_model): def _import_set_od_sequences(self): logger.info("Set Sequence values") - DatabaseUtils.execute("SELECT tww_sys.reset_od_seqval();") + DatabaseUtils.execute("SELECT tww_app.reset_od_seqval();") def _import_manage_organisations(self): logger.info("Update organisation tww_active") From 1c4391b08078f5847409d3b1cc52b844c1f4d42a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Sep 2024 12:09:53 +0000 Subject: [PATCH 10/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- datamodel/app/functions/oid_functions.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datamodel/app/functions/oid_functions.sql b/datamodel/app/functions/oid_functions.sql index b9b1a6483..0f3afea86 100644 --- a/datamodel/app/functions/oid_functions.sql +++ b/datamodel/app/functions/oid_functions.sql @@ -127,4 +127,4 @@ CREATE TRIGGER update_od_seqval_from_prefixes AFTER UPDATE ON tww_sys.oid_prefixes FOR EACH STATEMENT - EXECUTE FUNCTION tww_app.tr_reset_od_seqval(); \ No newline at end of file + EXECUTE FUNCTION tww_app.tr_reset_od_seqval(); From 46f6c5244c59627a2444e6b9e6719dcbf9891c9d Mon Sep 17 00:00:00 2001 From: cymed <102035587+cymed@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:08:21 +0200 Subject: [PATCH 11/12] duplicate function --- datamodel/app/functions/oid_functions.sql | 43 ----------------------- 1 file changed, 43 deletions(-) diff --git a/datamodel/app/functions/oid_functions.sql b/datamodel/app/functions/oid_functions.sql index 0f3afea86..a48062402 100644 --- a/datamodel/app/functions/oid_functions.sql +++ b/datamodel/app/functions/oid_functions.sql @@ -41,49 +41,6 @@ $BODY$ LANGUAGE plpgsql STABLE COST 100; --- function for generating StandardOIDs - -CREATE OR REPLACE FUNCTION tww_sys.generate_oid(schema_name text, table_name text) - RETURNS text AS -$BODY$ -DECLARE - myrec_prefix record; - myrec_shortcut record; - myrec_seq record; -BEGIN - -- first we have to get the OID prefix - BEGIN - SELECT prefix::text INTO myrec_prefix FROM tww_sys.oid_prefixes WHERE active = TRUE; - EXCEPTION - WHEN NO_DATA_FOUND THEN - RAISE EXCEPTION 'no active record found in table tww_sys.oid_prefixes'; - WHEN TOO_MANY_ROWS THEN - RAISE EXCEPTION 'more than one active records found in table tww_sys.oid_prefixes'; - END; - -- test if prefix is of correct length - IF char_length(myrec_prefix.prefix) != 8 THEN - RAISE EXCEPTION 'character length of prefix must be 8'; - END IF; - --get table 2char shortcut - BEGIN - SELECT shortcut_en INTO STRICT myrec_shortcut FROM tww_sys.dictionary_od_table WHERE tablename = table_name; - EXCEPTION - WHEN NO_DATA_FOUND THEN - RAISE EXCEPTION 'dictionary entry for table % not found', table_name; - WHEN TOO_MANY_ROWS THEN - RAISE EXCEPTION 'dictonary entry for table % not unique', table_name; - END; - --get sequence for table - EXECUTE format('SELECT nextval(''%1$I.seq_%2$I_oid'') AS seqval', schema_name, table_name) INTO myrec_seq; - IF NOT FOUND THEN - RAISE EXCEPTION 'sequence for table % not found', table_name; - END IF; - RETURN myrec_prefix.prefix || myrec_shortcut.shortcut_en || to_char(myrec_seq.seqval,'FM000000'); -END; -$BODY$ - LANGUAGE plpgsql STABLE - COST 100; - CREATE OR REPLACE FUNCTION tww_app.reset_od_seqval() RETURNS void LANGUAGE 'plpgsql' From 967f46665b6ec2b277b9eb5d80531d3dac339c67 Mon Sep 17 00:00:00 2001 From: cymed <102035587+cymed@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:10:35 +0200 Subject: [PATCH 12/12] remove variables from oid_functions messes with regex --- datamodel/app/create_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datamodel/app/create_app.py b/datamodel/app/create_app.py index 01853e48b..6331c1e44 100755 --- a/datamodel/app/create_app.py +++ b/datamodel/app/create_app.py @@ -65,7 +65,7 @@ def create_app( run_sql("CREATE SCHEMA tww_app;", pg_service) - run_sql_file("functions/oid_functions.sql", pg_service, variables) + run_sql_file("functions/oid_functions.sql", pg_service) run_sql_file("functions/modification_functions.sql", pg_service) run_sql_file("functions/symbology_functions.sql", pg_service) run_sql_file("functions/reach_direction_change.sql", pg_service, variables)