Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.

Idempotentiate Traffic Vault create_tables.sql#6717

Merged
zrhoffman merged 5 commits intoapache:masterfrom
davidc0le:tv_sql_idempotent
May 16, 2022
Merged

Idempotentiate Traffic Vault create_tables.sql#6717
zrhoffman merged 5 commits intoapache:masterfrom
davidc0le:tv_sql_idempotent

Conversation

@davidc0le
Copy link
Copy Markdown
Contributor

What does this PR (Pull Request) do?

Closes: #6712
Related: #4984

This PR makes changes to the Traffic Vault 'seed' schema file create_tables.sql to allow it to be run more than once. Even if db/admin --trafficvault load_schema is run more than once (for example, installing TO, with a shared database, on more than 1 host simultaneously), an SQL error should not result.

Which Traffic Control components are affected by this PR?

  • Traffic Ops (Traffic Vault seed SQL file )

What is the best way to verify this PR?

A test as implemented previously in 9250b20 has been added to the Traffic Vault DB test script https://github.com/apache/trafficcontrol/blob/master/traffic_ops/app/db/trafficvault/test/run-tvdb-test.sh . Running the test as described in https://github.com/apache/trafficcontrol/blob/master/traffic_ops/app/db/trafficvault/test/README.md

PR submission checklist

  • This PR has tests
  • You should never actually run TV create_tables.sql twice, no documentation necessary
  • This PR has a CHANGELOG.md entry
  • This PR DOES NOT FIX A SERIOUS SECURITY VULNERABILITY (see the Apache Software Foundation's security guidelines for details)

@zrhoffman zrhoffman added Traffic Ops related to Traffic Ops Traffic Vault related to Traffic Vault database relating to setup/installation/structure of the Traffic Ops database improvement The functionality exists but it could be improved in some way. labels Apr 4, 2022
@zrhoffman zrhoffman self-assigned this May 3, 2022
@zrhoffman zrhoffman added this to the 7.0.0 milestone May 3, 2022
Copy link
Copy Markdown
Member

@zrhoffman zrhoffman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is close, but the indices are missing:

--- upstream.sql  2022-05-04 08:20:44.952817606 -0600
+++ davidc0le.sql   2022-05-04 08:21:45.057162887 -0600
@@ -155,27 +155,6 @@


 --
--- Name: sslkey_cdn_idx; Type: INDEX; Schema: public; Owner: traffic_ops
---
-
-CREATE INDEX sslkey_cdn_idx ON public.sslkey USING btree (cdn);
-
-
---
--- Name: sslkey_deliveryservice_idx; Type: INDEX; Schema: public; Owner: traffic_ops
---
-
-CREATE INDEX sslkey_deliveryservice_idx ON public.sslkey USING btree (deliveryservice);
-
-
---
--- Name: sslkey_version_idx; Type: INDEX; Schema: public; Owner: traffic_ops
---
-
-CREATE INDEX sslkey_version_idx ON public.sslkey USING btree (version);
-
-
---
 -- Name: dnssec dnssec_last_updated; Type: TRIGGER; Schema: public; Owner: traffic_ops
 --

checked using

import_and_dump_tv_schema() {
    output_file="$1";
    <<'DOCKER_COMMANDS' docker run --rm -i \
        -v "$(pwd)/traffic_ops/app/db/trafficvault/create_tables.sql:/create_tables.sql" \
        -e POSTGRES_USER=traffic_ops \
        -e POSTGRES_PASSWORD=twelve \
        -e PGPASSWORD=twelve \
        -e POSTGRES_DB=traffic_ops \
        postgres:13.6-alpine bash >"$output_file";
    trap 'echo "Error on line ${LINENO} of ${0}" >/dev/stderr; exit 1' ERR;
    set -o errexit;
    docker-entrypoint.sh postgres >/dev/stderr &
    echo 'Waiting for Postgres to start...' >/dev/stderr;
    sleep 10;
    psql -Utraffic_ops -fcreate_tables.sql >/dev/stderr;
    pg_dump -Utraffic_ops;
DOCKER_COMMANDS
};

Comment thread traffic_ops/app/db/trafficvault/create_tables.sql Outdated
Comment thread traffic_ops/app/db/trafficvault/create_tables.sql Outdated
Comment thread traffic_ops/app/db/trafficvault/create_tables.sql Outdated
Comment thread traffic_ops/app/db/trafficvault/create_tables.sql Outdated
Comment thread traffic_ops/app/db/trafficvault/create_tables.sql Outdated
Comment thread traffic_ops/app/db/trafficvault/create_tables.sql Outdated
@mitchell852 mitchell852 mentioned this pull request May 10, 2022
4 tasks
Copy link
Copy Markdown
Member

@zrhoffman zrhoffman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look good. Thank you for your contribution!

@zrhoffman zrhoffman merged commit c66a5f5 into apache:master May 16, 2022
zrhoffman pushed a commit to zrhoffman/trafficcontrol that referenced this pull request Oct 2, 2022
* Idempotentiate TV create_tables.sql

* CHANGELOG

* Correcting issues identified by zrhoffman
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

database relating to setup/installation/structure of the Traffic Ops database improvement The functionality exists but it could be improved in some way. Traffic Ops related to Traffic Ops Traffic Vault related to Traffic Vault

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Postinstall can no longer be run twice (Traffic Vault load_schema error)

2 participants