aurweb/migrations
Kevin Morris a29701459c
feat: add Decision column to TUVote
In preparation for allowing TUs to change their votes on proposals,
we need a way to track what users vote for.

Without this, the vote decisions are stored within the related
TU_VoteInfo record, decoupled from the user who made the vote.

That being the case meant we cannot actually change a vote, because
we can't figure out what TU_VoteInfo decision columns to decrement
when the vote has changed.

You may be wondering why we aren't removing the decision columns out
of TU_VoteInfo with the advent of this new column. The reason being:
previous votes are all calculated off of the TU_VoteInfo columns, so
without a manual DB rework, relocating them to the user-related vote
records would break outcomes of old proposals. So, the plan is:
we'll solely use this column for votes from this point on to track
what decision a user made internally, which will open up TUs changing
their decision.

In addition, this migration resets all running proposals:
- all votes are deleted
- time is reset to Start when migration is run

This was necessary to put running proposals into a state that can
take advantage of the new revote system.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2022-03-07 22:35:52 -08:00
..
versions feat: add Decision column to TUVote 2022-03-07 22:35:52 -08:00
env.py change(aurweb): add parallel tests and improve aurweb.db 2021-11-17 01:34:59 -08:00
README Set up Alembic for database migrations 2020-02-27 16:44:36 +01:00
script.py.mako Set up Alembic for database migrations 2020-02-27 16:44:36 +01:00

This directory contains Alembic's environment for managing database migrations.

From Alembic's documentation: Alembic is a lightweight database migration tool
for usage with the SQLAlchemy Database Toolkit for Python.
https://alembic.sqlalchemy.org/en/latest/index.html


Upgrading to the latest version
-------------------------------

Simply run `alembic upgrade head` from aurweb's root.


Creating new migrations
-----------------------

When working with Alembic and SQLAlchemy, you should never edit the database
schema manually. Please proceed like this instead:

1. Edit `aurweb/schema.py` to your liking.
2. Run `alembic revision --autogenerate -m "your message"`
3. Proofread the generated migration.
4. Run `alembic upgrade head` to apply the changes to the database.
5. Commit the new migration.

To revert a migration, you may run `alembic downgrade -1` and then manually
delete the migration file. Note that SQLite is limited and that it's sometimes
easier to recreate the database.

For anything more complicated, please read Alembic's documentation.


Troubleshooting
---------------

- `ModuleNotFoundError: No module named 'aurweb'`

  You may either install the aurweb module with pip, or set PYTHONPATH to your
  aurweb repository. Since alembic must be run from the aurweb root, you may
  simply use: `PYTHONPATH=. alembic [...]`.

- `FAILED: No config file 'alembic.ini' found, or file has no '[alembic]' section`

  You need to run Alembic from the project's root, and not from `migrations/`.

- `configparser.NoSectionError: No section: 'database'`

  You need to set AUR_CONFIG, as explained in `TESTING`.