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

DM-47507: Add workflow for automatically generating migration scripts #54

Merged
merged 3 commits into from
Nov 15, 2024

Conversation

JeremyMcCormick
Copy link
Contributor

This will generate migration scripts automatically.

It accepts a branch name and a commit SHA representing the PR merge in sdm_schemas which made the schema changes.

@@ -42,7 +40,7 @@

# Loop over each of the instruments
pattern = os.environ["SDM_SCHEMAS_DIR"] + "/yml/cdb_*.yaml"
instruments = [re.search(r"cdb_(.+)\.yaml$", file).group(1) for file in glob.glob(pattern)]
instruments = ["latiss", "lsstcomcam", "lsstcomcamsim"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

We will need to include the glob again after I add the startracker tables

Copy link
Contributor Author

@JeremyMcCormick JeremyMcCormick Nov 13, 2024

Choose a reason for hiding this comment

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

We will need to include the glob again after I add the startracker tables

Or you can just add the new schemas to the instrument list. It's a small enough set of files that it could just be maintained by hand in this script for now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was at first agreeing with you, then thinking through what it would mean to add new instruments. (will we continue to add any more new instruments ever??)

When one adds a new table, that instrument would have to be manually added here;
If they try to add a new table to the schema, but don't know to edit this list, they won't get an error.
(wouldn't receive the 'no section in alembic.ini file' error)

I think I would prefer it to give an error when one attempts to add a cdb_*.yml rather than a success on an empty or no migration created. maybe accidentally skipping the 'need to test in TTS, etc' step.

opinions welcome.

Copy link
Collaborator

@Vebop Vebop left a comment

Choose a reason for hiding this comment

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

Conversation welcome on the hard coded list of instruments, I'm convince-able either way just want us to be knowingly intentional with the direction we choose.

- name: Generate the migration scripts
working-directory: $GITHUB_WORKSPACE/consdb
run: |
python alembic-autogenerate.py ${{ env.TICKET_NAME }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should make sure people understand the ticket name will be the name of the version migration, I think we generally try to keep the migration names more concise, and they are directly put into the migration file name via underscores.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For automatically generated migrations, I can't think of a much better way to do it. Agree users should be made aware that the scripts will reference tickets in this new way.

@@ -42,7 +40,7 @@

# Loop over each of the instruments
pattern = os.environ["SDM_SCHEMAS_DIR"] + "/yml/cdb_*.yaml"
instruments = [re.search(r"cdb_(.+)\.yaml$", file).group(1) for file in glob.glob(pattern)]
instruments = ["latiss", "lsstcomcam", "lsstcomcamsim"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was at first agreeing with you, then thinking through what it would mean to add new instruments. (will we continue to add any more new instruments ever??)

When one adds a new table, that instrument would have to be manually added here;
If they try to add a new table to the schema, but don't know to edit this list, they won't get an error.
(wouldn't receive the 'no section in alembic.ini file' error)

I think I would prefer it to give an error when one attempts to add a cdb_*.yml rather than a success on an empty or no migration created. maybe accidentally skipping the 'need to test in TTS, etc' step.

opinions welcome.

alembic/env.py Show resolved Hide resolved
@JeremyMcCormick
Copy link
Contributor Author

JeremyMcCormick commented Nov 14, 2024

Conversation welcome on the hard coded list of instruments, I'm convince-able either way just want us to be knowingly intentional with the direction we choose.

I'm planning to merge this soon (probably within a day) so let's change to the hardcoded list, as it won't work otherwise.

I am fine with changing it back to the generic file glob once all the schema migrations are handled without errors. You could do this in your PR which adds the startracker schema migrations.

@JeremyMcCormick
Copy link
Contributor Author

I would like to point out that merging this PR won't make the migrations trigger automatically until this PR is merged on sdm_schemas:

lsst/sdm_schemas#278

I still have to verify that the trigger works - the sdm_schemas workflow needs to use a GitHub Personal Access Token (PAT) on my account for authorization of the call. I'll have to play with it a bit to get this working.

@JeremyMcCormick JeremyMcCormick merged commit cc074d8 into main Nov 15, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants