You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/dev/development.rst
+38-1Lines changed: 38 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -70,7 +70,44 @@ Database migrations
70
70
71
71
Times Square uses Alembic_ for database migrations.
72
72
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`.
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>`__.
74
111
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.
0 commit comments