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

Reevaluate use of Goose for migrations #675

Open
jrschumacher opened this issue Apr 27, 2024 · 1 comment
Open

Reevaluate use of Goose for migrations #675

jrschumacher opened this issue Apr 27, 2024 · 1 comment
Labels
comp:core Core component

Comments

@jrschumacher
Copy link
Member

During the implementation of #647 we determined a migration was needed to change the original schema value. Ideally, we wanted to implement this as part of the Goose migrations under the policy service, with the intention to support varying situations.

This proved more complicated than expected. The solution we tried to take was creating a migration with a 001 id and using this script. If failed due to how we create schemas outside Goose and figuring out the right conditions to preserve state.

It's curious if using a tool like atlasgo.io had resolved it, since you describe the state of the tables rather than the migration and let the tool determine the migration path.

DO $$
BEGIN
  -- if opentdf schema does exist and opentdf_policy schema does exist but contains no tables, drop it
  IF EXISTS (SELECT 1 FROM information_schema.schemata WHERE schema_name = 'opentdf') THEN
    IF EXISTS (SELECT 1 FROM information_schema.schemata WHERE schema_name = 'opentdf_policy') THEN
      -- if opentdf_policy schema contains only goose_db_version table, drop it
      IF (SELECT count(*) FROM information_schema.tables WHERE table_schema = 'opentdf_policy') = 1 THEN
        DROP SCHEMA opentdf_policy CASCADE;
        ALTER SCHEMA opentdf RENAME TO opentdf_policy;
      END IF;
    ELSE 
      ALTER SCHEMA opentdf RENAME TO opentdf_policy;
    END IF;
  END IF;
END $$;
@jrschumacher jrschumacher added this to the Next major version milestone Apr 27, 2024
@jrschumacher jrschumacher changed the title Review use of Goose for migrations Reevaluate use of Goose for migrations Apr 27, 2024
@pflynn-virtru
Copy link
Member

We used Alembic in the past, in a python service. The nice feature was offline mode: https://alembic.sqlalchemy.org/en/latest/offline.html
Please consider a tool with this feature

Reference:
https://github.com/JeffGradyAtVirtru/python-example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:core Core component
Projects
None yet
Development

No branches or pull requests

2 participants