Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idempotentiate Traffic Vault create_tables.sql #6717

Merged
merged 5 commits into from
May 16, 2022

Conversation

davidc0le
Copy link
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
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
};

traffic_ops/app/db/trafficvault/create_tables.sql Outdated Show resolved Hide resolved
traffic_ops/app/db/trafficvault/create_tables.sql Outdated Show resolved Hide resolved
traffic_ops/app/db/trafficvault/create_tables.sql Outdated Show resolved Hide resolved
traffic_ops/app/db/trafficvault/create_tables.sql Outdated Show resolved Hide resolved
traffic_ops/app/db/trafficvault/create_tables.sql Outdated Show resolved Hide resolved
traffic_ops/app/db/trafficvault/create_tables.sql Outdated Show resolved Hide resolved
@mitchell852 mitchell852 mentioned this pull request May 10, 2022
4 tasks
Copy link
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 join this conversation on GitHub. Already have an account? Sign in to comment
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