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

Collapse DB migrations that have already been released (pre-ATCv6) #6065

Merged
merged 8 commits into from
Jul 29, 2021
Merged

Collapse DB migrations that have already been released (pre-ATCv6) #6065

merged 8 commits into from
Jul 29, 2021

Conversation

shamrickus
Copy link
Member

@shamrickus shamrickus commented Jul 28, 2021

What does this PR (Pull Request) do?

Which Traffic Control components are affected by this PR?

  • Traffic Ops

What is the best way to verify this PR?

Run the db/admin tool on master and on this fork and compare the DB schema and data to ensure they are the same.
I used pg_dump to fetch the data from the DBs and diff to compare the output.

The following criteria are ALL met by this PR

  • This PR includes tests OR I have explained why tests are unnecessary
  • This PR includes documentation OR I have explained why documentation is unnecessary
  • This PR includes an update to CHANGELOG.md OR such an update is not necessary
  • This PR includes any and all required license headers
  • This PR DOES NOT FIX A SERIOUS SECURITY VULNERABILITY (see the Apache Software Foundation's security guidelines for details)

Additional Information

My diff:

> diff tops tops2
2685,2726c2685,2698
< 1	0	t	2021-07-28 08:22:43.182007
< 2	20181206000000	t	2021-07-28 08:22:43.185251
< 3	20190219000000	t	2021-07-28 08:22:43.186341
< 4	20190319000000	t	2021-07-28 08:22:43.187132
< 5	20190513000000	t	2021-07-28 08:22:43.188108
< 6	20191004000000	t	2021-07-28 08:22:43.191913
< 7	20191005000000	t	2021-07-28 08:22:43.195014
< 8	20191024000000	t	2021-07-28 08:22:43.202873
< 9	20191215000000	t	2021-07-28 08:22:43.206729
< 10	20200218000000	t	2021-07-28 08:22:43.207674
< 11	20200227000000	t	2021-07-28 08:22:43.209716
< 12	20200313000000	t	2021-07-28 08:22:43.210601
< 13	20200408000000	t	2021-07-28 08:22:43.212077
< 14	20200422101648	t	2021-07-28 08:22:43.215578
< 15	20200507000000	t	2021-07-28 08:22:43.231749
< 16	2020061622101648	t	2021-07-28 08:22:43.241121
< 17	2020062923101648	t	2021-07-28 08:22:43.24213
< 18	2020072700000000	t	2021-07-28 08:22:43.308803
< 19	2020081000000000	t	2021-07-28 08:22:43.311069
< 20	2020081108261100	t	2021-07-28 08:22:43.3147
< 21	2020082000000000	t	2021-07-28 08:22:43.315934
< 22	2020082700000000	t	2021-07-28 08:22:43.316662
< 23	2020103000000000	t	2021-07-28 08:22:43.319846
< 24	2020110200000000	t	2021-07-28 08:22:43.320716
< 25	2021010900000000	t	2021-07-28 08:22:43.322472
< 26	2021010900000001	t	2021-07-28 08:22:43.323647
< 27	2021010900000002	t	2021-07-28 08:22:43.327534
< 28	2021010900000003	t	2021-07-28 08:22:43.328402
< 29	2021012200000000	t	2021-07-28 08:22:43.331042
< 30	2021012700000000	t	2021-07-28 08:22:43.332001
< 31	2021012800000000	t	2021-07-28 08:22:43.333272
< 32	2021020500000000	t	2021-07-28 08:22:43.33405
< 33	2021021900000000	t	2021-07-28 08:22:43.334882
< 34	2021022300000000	t	2021-07-28 08:22:43.338818
< 35	2021030300000000	t	2021-07-28 08:22:43.342562
< 36	2021031400000000	t	2021-07-28 08:22:43.344308
< 37	2021040819481469	t	2021-07-28 08:22:43.349096
< 38	2021041200000000	t	2021-07-28 08:22:43.349876
< 39	2021052400000000	t	2021-07-28 08:22:43.351517
< 40	2021061100000000	t	2021-07-28 08:22:43.355434
< 41	2021070600000000	t	2021-07-28 08:22:43.35952
< 42	2021070800000000	t	2021-07-28 08:22:43.360362
---
> 1	0	t	2021-07-28 11:46:25.799758
> 2	2021012700000000	t	2021-07-28 11:46:25.802868
> 3	2021012800000000	t	2021-07-28 11:46:25.804771
> 4	2021020500000000	t	2021-07-28 11:46:25.805634
> 5	2021021900000000	t	2021-07-28 11:46:25.806486
> 6	2021022300000000	t	2021-07-28 11:46:25.810273
> 7	2021030300000000	t	2021-07-28 11:46:25.813885
> 8	2021031400000000	t	2021-07-28 11:46:25.815709
> 9	2021040819481469	t	2021-07-28 11:46:25.820572
> 10	2021041200000000	t	2021-07-28 11:46:25.821395
> 11	2021052400000000	t	2021-07-28 11:46:25.823174
> 12	2021061100000000	t	2021-07-28 11:46:25.826771
> 13	2021070600000000	t	2021-07-28 11:46:25.831382
> 14	2021070800000000	t	2021-07-28 11:46:25.832155
3105c3077
< SELECT pg_catalog.setval('public.goose_db_version_id_seq', 42, true);
---
> SELECT pg_catalog.setval('public.goose_db_version_id_seq', 14, true);

QUOTE_IDENT(table_name)
);
END IF;
IF table_name = 'topology' THEN
Copy link
Member Author

Choose a reason for hiding this comment

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

Topology index is incorrect, see #6066

QUOTE_IDENT(table_name),
QUOTE_IDENT(table_name)
);
ELSIF table_name = 'phys_location' THEN
Copy link
Member Author

Choose a reason for hiding this comment

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

phys_location index has a typo, see #6066

@ocket8888 ocket8888 added 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 labels Jul 28, 2021
@ocket8888 ocket8888 changed the title TO DB: Collapse <6 migrations Collapse DB migrations that have already been released (pre-ATCv6) Jul 28, 2021
@zrhoffman zrhoffman added this to the 6.0.0 milestone Jul 28, 2021
traffic_ops/app/db/create_tables.sql Outdated Show resolved Hide resolved
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.

Verified that

  • create_tables.sql can still be run twice, and
  • A DB dump with collapsed migrations has the same sha256 sum as a DB dump from apache/master without collapsed migrations:
    (set -o errexit -o nounset;
    create_migrate_dump() {(
        create_migrate_dump() {
          trap 'echo "Error on line ${LINENO} of ${0}" >/dev/stderr; exit 1' ERR;
          set -o errexit -o nounset -o pipefail;
          {
            docker-entrypoint.sh postgres >/dev/stderr &
            sleep 10;
            <create_tables.sql psql;
            <create_tables.sql psql;
            for migration in migrations/*; do
              <"$migration" sed '/+goose Down/,$d' | psql;
            done;
          } >/dev/stderr;
          pg_dump | sed '/^-- Dumped/d';
        };
        docker run --rm -iw/db \
          -v "$(pwd)/traffic_ops/app/db:/db" \
          -e PGUSER=traffic_ops \
          -e PGPASSWORD=twelve \
          -e POSTGRES_USER=traffic_ops \
          -e POSTGRES_PASSWORD=twelve \
          postgres:13-alpine bash -c "$(type create_migrate_dump | tail -n+2); create_migrate_dump";
    )};
    for remote_branch in apache/master shamrickus/to/6.0-migration; do
      git fetch "${remote_branch/\/*}";
      git checkout "${remote_branch}";
      create_migrate_dump >"${remote_branch/\/*}.sql";
    done;
    diff -u master.sql shamrickus.sql;
    openssl sha256 master.sql shamrickus.sql)

@zrhoffman zrhoffman merged commit 3cc78ea into apache:master Jul 29, 2021
@shamrickus shamrickus deleted the to/6.0-migration branch July 29, 2021 17:54
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Database migrations should be collapsed for ATC 6
3 participants