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

Initialize the database automatically when starting mquery #402

Closed
msm-cert opened this issue Sep 17, 2024 · 1 comment · Fixed by #421
Closed

Initialize the database automatically when starting mquery #402

msm-cert opened this issue Sep 17, 2024 · 1 comment · Fixed by #421
Assignees
Labels
zone:backend Backend oriented tasks
Milestone

Comments

@msm-cert
Copy link
Member

msm-cert commented Sep 17, 2024

Currently the installation procedure is:

docker compose up --scale daemon=3  # this will take a while
docker compose exec web python3 -m mquery.db

Web container should initialize the database (run migrations) automatically.

This should happen when the web container is started.

Also update the documentation (remove the initialization step when it's not needed).

@msm-cert msm-cert added the zone:backend Backend oriented tasks label Sep 17, 2024
@msm-cert msm-cert added this to the v1.5.0 milestone Sep 29, 2024
@msm-cert
Copy link
Member Author

msm-cert commented Oct 2, 2024

This overlaps a bit with #412

Some hints how to do it:

  1. executing mquery.db is actually not the best solution here, just alembic upgrade head would be better. See teste2e:
      - name: run web with docker compose
        run: docker compose up --build -d web --wait
      - name: init the database
        run: docker compose exec -it -w /usr/src/app/src/ web alembic upgrade head
      - name: run the rest of the code
        run: docker compose up -d
  1. But we want to remove this line altogether. You can google for something like "fastapi automatic alembic migrations" etc. One of the resutls: https://stackoverflow.com/questions/77170361/running-alembic-migrations-on-fastapi-startup

  2. You can also take a look at how mwdb does it:
    https://github.com/CERT-Polska/mwdb-core/blob/d593f697ebf37e036e778641038d5613ed852a5f/docker/start.sh#L10
    https://github.com/CERT-Polska/mwdb-core/blob/d593f697ebf37e036e778641038d5613ed852a5f/mwdb/cli/cli.py#L60
    https://github.com/CERT-Polska/mwdb-core/blob/d593f697ebf37e036e778641038d5613ed852a5f/mwdb/cli/database.py#L57

But this is more complex than we need for our needs.

msm-cert pushed a commit that referenced this issue Oct 15, 2024
Automatically init database with alembic upgrade head

Co-authored-by: Michał Jura <[email protected]>
Co-authored-by: msm <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
zone:backend Backend oriented tasks
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants