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

Rolling back 2021080408053529_fix_indices in TO DB tests: pys_location_last_updated_idx" already exists #6127

@zrhoffman

Description

@zrhoffman

This Bug Report affects these Traffic Control components:

  • Traffic Ops

Current behavior:

If run using a database dump, the database tests fail to roll back the 2021080408053529_fix_indices migration:

+ ./db/admin --env=production down
Error running migrate down: migration failed: relation "pys_location_last_updated_idx" already exists in line 0: /*

Line it fails at:

ALTER INDEX phys_location_last_updated_idx RENAME TO pys_location_last_updated_idx;

Somehow, an index named pys_location_last_updated_idx still exists after running

ALTER INDEX pys_location_last_updated_idx RENAME TO phys_location_last_updated_idx;

I cannot reproduce this issue outside of the DB tests, but this is not a Migrate-specific issue. If you run the DB tests with Goose at 3cc78ea~ but add the Goose equivalent of 2021080408053529_fix_indices:

-- +goose Up
-- SQL in section 'Up' is executed when this migration is applied

ALTER INDEX pys_location_last_updated_idx RENAME TO phys_location_last_updated_idx;
DROP INDEX topology_last_updated_idx;
CREATE INDEX topology_last_updated_idx ON topology (last_updated DESC NULLS LAST);

-- +goose Down
-- SQL section 'Down' is executed when this migration is rolled back

ALTER INDEX phys_location_last_updated_idx RENAME TO pys_location_last_updated_idx;
DROP INDEX topology_last_updated_idx;
CREATE INDEX topology_last_updated_idx ON topology_cachegroup (last_updated DESC NULLS LAST);

then the TO DB tests will still fail.

+ ./db/admin --env=production down
Running goose down...
goose: migrating db environment 'production', current version: 2021080408053529, target: 2021070800000000
2021/08/19 18:52:11 FAIL 2021080408053529_fix_indices.sql (pq: relation "pys_location_last_updated_idx" already exists), quitting migration.
Can't run goose: exit status 1

Back to Migrate: If the ALTER INDEX RENAME in the up migration is changed to

DROP INDEX pys_location_last_updated_idx;
CREATE INDEX phys_location_last_updated_idx ON phys_location (last_updated DESC NULLS LAST);

then the pys_location_last_updated_idx still does not get removed in the up migration in the TO DB tests:

+ ./db/admin --env=production down
Error running migrate down: migration failed: relation "pys_location_last_updated_idx" already exists in line 0: /*

Expected behavior:

The Traffic Ops DB tests should succeed on all up/down migrations, with or without a database dump.

Steps to reproduce:

  1. Dump the Traffic Ops database

  2. Run the Traffic Ops DB tests using a database dump.

    cd traffic_ops_db/test/docker
    cp path-to-the-dump.dump initdb.d/
    docker-compose build --parallel
    docker-compose up trafficops-db-admin
    

Metadata

Metadata

Assignees

Labels

Traffic Opsrelated to Traffic Opsbugsomething isn't working as intendeddatabaserelating to setup/installation/structure of the Traffic Ops database

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions