Skip to content

Commit

Permalink
alembic: move developer info from README.rst to migration/README
Browse files Browse the repository at this point in the history
  • Loading branch information
pboettch committed Mar 29, 2024
1 parent a2cd398 commit 61e03dd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 38 deletions.
37 changes: 0 additions & 37 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,3 @@ dynamic catalogues (filter-based).

* Free software: GNU General Public License v3
* Documentation: https://tscat.readthedocs.io.

Alembic integration for database migrations
-------------------------------------------

This library uses alembic for database migrations. Alembic was added
later on when the database model was already created and used in production.

The goal is to use alembic to create migration scripts that can be used to
migrate production databases to the current state of the model after an
upgrade of tscat to a newer version by the user.

Initial steps that were taken starting from the 0.2.0-release (tag ``v0.2.0``):

1. Install alembic with ``pip install alembic``
2. Go to ``tscat/orm_sqlalchemy``
3. Create an alembic environment with ``alembic init migrations``. This creates
a directory called ``migrations``.
4. Edit the ``alembic.ini`` file to point to the database URL.
As in development we use a sqlite-database in its production location, we need to
resolve: e.g. with ``python -c "from appdirs import user_data_dir; print(user_data_dir('tscat'))"``
The URL is then the output of the above command with ``backend.sqlite`` appended.
As an example: (see the two extra forward slashes after sqlite://)

``sqlalchemy.url = sqlite:////home/pboettch/.local/share/tscat/backend.sqlite``

5. Edit the ``env.py`` file to point to the database model.
6. Remove the database file and create a new one corresponding to the orm of this tscat-version
7. Create the first migration with ``alembic revision --autogenerate -m "Initial migration"``.
8. Edit the create migration-script and empty out upgrade and downgrade functions. As we add alembic to
an existing production database we do not want to change the database, but only add the migration.
9. Run the migration with ``alembic upgrade head``. Now alembic should be in sync with the current
database model and later migrations are possible.

Steps 7 and 9 are to be repeated when the database model changes.



37 changes: 36 additions & 1 deletion tscat/orm_sqlalchemy/migrations/README
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
Generic single-database configuration.
Alembic integration for database migrations
-------------------------------------------

This library uses alembic for database migrations. Alembic was added
later on when the database model was already created and used in production.

The goal is to use alembic to create migration scripts that can be used to
migrate production databases to the current state of the model after an
upgrade of tscat to a newer version by the user.

Initial steps that were taken starting from the 0.2.0-release (tag ``v0.2.0``):

1. Install alembic with ``pip install alembic``
2. Go to ``tscat/orm_sqlalchemy``
3. Create an alembic environment with ``alembic init migrations``. This creates
a directory called ``migrations``.
4. Edit the ``alembic.ini`` file to point to the database URL.
As in development we use a sqlite-database in its production location, we need to
resolve: e.g. with ``python -c "from appdirs import user_data_dir; print(user_data_dir('tscat'))"``
The URL is then the output of the above command with ``backend.sqlite`` appended.
As an example: (see the two extra forward slashes after sqlite://)

``sqlalchemy.url = sqlite:////home/pboettch/.local/share/tscat/backend.sqlite``

5. Edit the ``env.py`` file to point to the database model.
6. Remove the database file and create a new one corresponding to the orm of this tscat-version
7. Create the first migration with ``alembic revision --autogenerate -m "Initial migration"``.
8. Edit the create migration-script and empty out upgrade and downgrade functions. As we add alembic to
an existing production database we do not want to change the database, but only add the migration.
9. Run the migration with ``alembic upgrade head``. Now alembic should be in sync with the current
database model and later migrations are possible.

Steps 7 and 9 are to be repeated when the database model changes.



0 comments on commit 61e03dd

Please sign in to comment.