Skip to content

Commit 6b312df

Browse files
committed
Document concrete steps for database migrations
The steps for Times Square are slightly different from the generic Safir docs, so we'll provide the exact copy-and-pastable steps here.
1 parent dfd3b5b commit 6b312df

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

docs/dev/development.rst

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,44 @@ Database migrations
7070

7171
Times Square uses Alembic_ for database migrations.
7272
If your work involves changing the database schema (in :file:`/src/timessquare/dbschema`) you will need to prepare an Alembic migration in the same PR.
73-
This process is outlined in the `Safir documentation <https://safir.lsst.io/user-guide/database/schema.html#testing-database-migrations>`__.
73+
To create the migration, you will need to run a local postgres database for Alembic to compare the current schema to the new schema:
74+
75+
1. With your existing codebase (before your changes; switch branches or stash changes if necessary), start up the database:
76+
77+
.. code-block:: sh
78+
79+
docker-compose -f docker-compose.yaml up
80+
81+
2. Initialize the database:
82+
83+
.. code-block:: sh
84+
85+
tox run -e cli -- init
86+
87+
3. Apply code changes to the database schema in :file:`/src/timessquare/dbschema`.
88+
89+
4. Generate the Alembic migration:
90+
91+
.. code-block:: sh
92+
93+
tox run -e alembic -- revision --autogenerate -m "Your migration message."
94+
95+
5. Review the migration in :file:`alembic/versions/` and make any necessary changes.
96+
In particular, enums require special handling. See the `Safir documentation <https://safir.lsst.io/user-guide/database/schema.html#creating-database-migrations>`__ for more information.
97+
98+
6. Apply the migration to the running database:
99+
100+
.. code-block:: sh
101+
102+
tox run -e cli -- update-db-schema --alembic-config-path alembic.ini
103+
104+
7. Shut down the database:
105+
106+
.. code-block:: sh
107+
108+
docker-compose -f docker-compose.yaml down
109+
110+
For more general information about preparing Alembic migrations, see the `Safir documentation <https://safir.lsst.io/user-guide/database/schema.html#testing-database-migrations>`__.
74111
Note that in Times Square the :file:`docker-compose.yaml` is hosted in the root of the repository rather than in the :file:`alembic` directory.
75112

76113
Building documentation

0 commit comments

Comments
 (0)