admin tool no seed on upgrade (#7614)
* Move seed to the database creation step
* seeding must only be done after schema is loaded
* update documentation
* Update changelog
* Add manual seeding to t3c and tc-health-client tests
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0b8754a..f6d2c25 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,9 @@
### Added
- [#7812](https://github.com/apache/trafficcontrol/pull/7812) *Traffic Portal*: Expose the `configUpdateFailed` and `revalUpdateFailed` fields on the server table.
+### Changed
+- [#7614](https://github.com/apache/trafficcontrol/pull/7614) *Traffic Ops* The database upgrade process no longer overwrites changes users may have made to the initially seeded data.
+
## [8.0.0] - 2023-09-20
### Added
- [#7672](https://github.com/apache/trafficcontrol/pull/7672) *Traffic Control Health Client*: Added peer monitor flag while using `strategies.yaml`.
diff --git a/cache-config/testing/docker/traffic_ops/run.sh b/cache-config/testing/docker/traffic_ops/run.sh
index 8fb7d1e..eb0f008 100755
--- a/cache-config/testing/docker/traffic_ops/run.sh
+++ b/cache-config/testing/docker/traffic_ops/run.sh
@@ -149,6 +149,7 @@
(
db/admin --env=production reset
db/admin --env=production upgrade
+db/admin --env=production seed
db/admin --trafficvault --env=production reset
db/admin --trafficvault --env=production upgrade
) >> /var/log/traffic_ops/to_admin.log 2>&1) || {
diff --git a/docs/source/admin/traffic_ops.rst b/docs/source/admin/traffic_ops.rst
index 6421678..db97fb5 100644
--- a/docs/source/admin/traffic_ops.rst
+++ b/docs/source/admin/traffic_ops.rst
@@ -226,7 +226,7 @@
=========
To upgrade from older Traffic Ops versions, stop the service, use :manpage:`yum(8)` to upgrade to the latest available Traffic Ops package, and use the :ref:`admin <database-management>` tool to perform the database upgrade.
-.. tip:: In order to upgrade to the latest version of Traffic Ops, please be sure that you have first upgraded to the latest available minor or patch version of your current release. For example, if your current Traffic Ops version is 3.0.0 and version 3.1.0 is available, you must first upgrade to 3.1.0 before proceeding to upgrade to 4.0.0. (Specifically, this means running all migrations, :file:`traffic_ops/app/db/seeds.sql`, and :file:`traffic_ops/app/db/patches.sql` for the latest of your current major version - which should be handled by the :program:`admin` tool). The latest migration available before the release of 4.0.0 (pending at the time of this writing) was :file:`traffic_ops/app/db/migrations/20180814000625_remove_capabilities_for_reseed.sql`, so be sure that migrations up to this point have been run before attempting to upgrade Traffic Ops.
+.. tip:: In order to upgrade to the latest version of Traffic Ops, please be sure that you have first upgraded to the latest available minor or patch version of your current release. For example, if your current Traffic Ops version is 3.0.0 and version 3.1.0 is available, you must first upgrade to 3.1.0 before proceeding to upgrade to 4.0.0. (Specifically, this means running all migrations, :atc-file:`traffic_ops/app/db/seeds.sql`, and :file:`traffic_ops/app/db/patches.sql` for the latest of your current major version - which should be handled by the :program:`admin` tool). The latest migration available before the release of 4.0.0 (pending at the time of this writing) was :file:`traffic_ops/app/db/migrations/20180814000625_remove_capabilities_for_reseed.sql`, so be sure that migrations up to this point have been run before attempting to upgrade Traffic Ops.
.. seealso:: :ref:`database-management` for more details about :program:`admin`.
diff --git a/docs/source/development/traffic_ops.rst b/docs/source/development/traffic_ops.rst
index 7ef96f8..850c4d1 100644
--- a/docs/source/development/traffic_ops.rst
+++ b/docs/source/development/traffic_ops.rst
@@ -208,7 +208,7 @@
The :option:`command` specifies the operation to be performed on the database. It must be one of:
createdb
- Creates the database for the current environment
+ Creates the database for the current environment.
create_migration
Creates a pair of timestamped up/down migrations titled NAME.
create_user
@@ -222,7 +222,7 @@
drop_user
Drops the user defined for the current environment
load_schema
- Sets up the database for the current environment according to the SQL statements in ``app/db/create_tables.sql`` or ``app/db/trafficvault/create_tables.sql`` if the ``--trafficvault`` option is used
+ Sets up the database for the current environment according to the SQL statements in :atc-file:`traffic_ops/app/db/create_tables.sql` or :atc-file:`traffic_ops/app/db/trafficvault/create_tables.sql` if the ``--trafficvault`` option is used
migrate
Runs a migration on the database for the current environment
patch
@@ -232,13 +232,13 @@
reset
Creates the user defined for the current environment, drops the database for the current environment, creates a new one, loads the schema into it, and runs a single migration on it
seed
- Executes the SQL statements from the ``app/db/seeds.sql`` file for loading static data. This command is not supported when using the ``--trafficvault`` option
+ Executes the SQL statements from the ``app/db/seeds.sql`` file for loading static data. This command is not supported when using the ``--trafficvault`` option. The seed data is constructed under the assumption all migrations for the release have been run, so ``migrate``/\ ``upgrade`` *must* be run first.
show_users
Displays a list of all users registered with the PostgreSQL server
status
Deprecated, ``status`` is now an alias for ``dbversion`` and will be removed in a future Traffic Control release.
upgrade
- Performs a migration on the database for the current environment, then seeds it and patches it using the SQL statements from the ``app/db/patches.sql`` file
+ Performs a migration on the database for the current environment, then patches it using the SQL statements from the :atc-file:`traffic_ops/app/db/patches.sql` file.
.. code-block:: bash
:caption: Example Usage
diff --git a/tc-health-client/testing/docker/traffic_ops/run.sh b/tc-health-client/testing/docker/traffic_ops/run.sh
index 874aefc..060c96b 100755
--- a/tc-health-client/testing/docker/traffic_ops/run.sh
+++ b/tc-health-client/testing/docker/traffic_ops/run.sh
@@ -7,9 +7,9 @@
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -102,7 +102,11 @@
if [ -z "$INITIALIZED" ]; then init; fi
# create the 'traffic_ops' database, tables and runs migrations
-(cd /opt/traffic_ops/app && db/admin --env=production reset > /admin.log 2>&1)
+pushd /opt/traffic_ops/app;
+db/admin --env=production reset > /admin.log 2>&1
+db/admin --env=production upgrade >> /admin.log 2>&1
+db/admin --env=production seed >> /admin.log 2>&1
+popd;
# start traffic_ops
start
diff --git a/traffic_ops/app/db/admin.go b/traffic_ops/app/db/admin.go
index 6bbe979..d80c750 100644
--- a/traffic_ops/app/db/admin.go
+++ b/traffic_ops/app/db/admin.go
@@ -353,7 +353,6 @@
func upgrade() {
runMigrations()
if !trafficVault {
- seed()
patch()
}
}
@@ -459,7 +458,7 @@
if trafficVault {
die("seed not supported for trafficvault environment")
}
- fmt.Println("Seeding database w/ required data.")
+ fmt.Println("Seeding database with required data.")
seedsBytes, err := ioutil.ReadFile(dbSeedsPath)
if err != nil {
die("unable to read '" + dbSeedsPath + "': " + err.Error())
@@ -507,9 +506,9 @@
cmd.Stdin = bytes.NewBuffer(patchesBytes)
cmd.Env = append(os.Environ(), "PGPASSWORD="+dbPassword)
out, err := cmd.CombinedOutput()
- fmt.Printf(string(out))
+ fmt.Println(string(out))
if err != nil {
- die("Can't patch database w/ required data")
+ die("Can't patch database with required data")
}
}
@@ -559,19 +558,22 @@
dbversion - Prints the current migration timestamp
drop_user - Execute 'drop_user' the user for the current environment
(traffic_ops).
+ load_schema - Loads the database schema.
patch - Execute sql from db/patches.sql for loading post-migration data
patches (NOTE: not supported with --trafficvault option).
redo - Roll back the most recently applied migration, then run it again.
reset - Execute db 'dropdb', 'createdb', load_schema, migrate on the
database for the current environment.
seed - Execute sql from db/seeds.sql for loading static data (NOTE: not
- supported with --trafficvault option).
+ supported with --trafficvault option). This MUST ONLY be done
+ after the schema is loaded and migrations have been run.
show_users - Execute sql to show all of the user for the current environment.
status - Prints the current migration timestamp (Deprecated, status is now an
alias for dbversion and will be removed in a future Traffic
Control release).
- upgrade - Execute migrate, seed, and patches on the database for the current
- environment.`)
+ upgrade - Execute migrate and patch on the database for the current
+ environment.`,
+ )
return buff.String()
}