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

[db] A CI job to run alembic migrations would be useful #140

Open
Tracked by #222
frgfm opened this issue Mar 23, 2021 · 4 comments
Open
Tracked by #222

[db] A CI job to run alembic migrations would be useful #140

frgfm opened this issue Mar 23, 2021 · 4 comments
Assignees
Labels
Milestone

Comments

@frgfm
Copy link
Member

frgfm commented Mar 23, 2021

Following up on #112 (more specifically #112 (comment)), we need to automate the alembic migration whenever it needs to be run. Depending on the integration, Github Workflow could help with that!

@frgfm frgfm added help wanted Extra attention is needed topic: build Related to build, installation & CI labels Mar 23, 2021
@frgfm frgfm added this to the 0.1.2 milestone Mar 23, 2021
@jean-pasquier
Copy link
Contributor

Just a draft for a new github action, no idea if it works. Questions:

  • is it okay running the job within the VM and not in a container ?
  • the job runs the upgrade migration method, need a process to rollback running the downgrade (eg connecting to db directly and running alembic downgrade -1) or a new migration with fixes (as upgrade) is sufficient
  • storing production database URL in github secrets is feasible ?
  • SUPERUSER_LOGIN and SUPERUSER_PWD should be set as well to retrieve app.config ?
name: dbmigration-alembic
on:
  push:
    branches: master
    paths:
      - 'src/alembic/**'
      - '!src/alembic/README.md'

jobs:
  run-migration:
    runs-on: ubuntu-latest
    needs: install-deps
    defaults:
      run:
        working-directory: src
    steps:
      - uses: actions/checkout@v2
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements-dev.txt
      - name: Run alembic migration
        env:
          DATABASE_URL: ${{ secrets.DATABASE_URL }}
        run: |
          alembic upgrade head

@frgfm
Copy link
Member Author

frgfm commented Mar 29, 2021

  • When we use docker, we bind the volume of the DB (meaning that actions inside the container about the corresponding folder/data, will also take place outside) so I guess it will do!
  • Not sure I understood?
  • yes just like all the other secrets! But the codebase (github) may be deployed into multiple environments (let's imagine 1 instance per country), so the github secrets should only be used for CI testing purposes. Currently on Heroku we are also using a secret system to achieve this
  • I remember hesitating between storing it in the config and just passing it as an env variable. Why do you think it would be better? (still unsure about the best option)

Thanks a lot for the draft ! Is the paths argument used to limit the event to changes to the files mentioned?

@frgfm
Copy link
Member Author

frgfm commented Jun 16, 2022

I think this was fixed by #112, but let me check if everything still works 👍

@frgfm frgfm self-assigned this Jun 16, 2022
@frgfm frgfm modified the milestones: 0.1.2, 0.2.0 Jun 16, 2022
@frgfm frgfm mentioned this issue Oct 12, 2022
11 tasks
@ajubin
Copy link

ajubin commented Oct 3, 2023

As we're using heroku, what we can do is to perform the migrtation before the app deploy

in Procfile

release: alembic upgrade head # not sure of how to migrate alembic, but it should be something similar

The doc from heroku: https://devcenter.heroku.com/articles/release-phase

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

No branches or pull requests

3 participants