@@ -32,19 +32,33 @@ Running Migrations
3232==================
3333
3434Prerequisites
35- ~~~~~~~~~~~~~
35+ =============
36+
37+ Before running migrations, ensure:
38+
39+ 1. All required environment variables are configured (see ``.env.example ``)
40+ 2. Database connection string is valid (``DB_URL ``)
41+ 3. GitHub App credentials are configured (required by settings validation)
42+
43+ Minimal ``.env `` for migrations:
3644
37- 1. PostgreSQL database running (use docker-compose):
45+ .. code-block :: bash
3846
39- .. code-block :: bash
47+ DB_URL=postgresql+asyncpg://byte:bot@localhost:5432/byte
48+ SECRET_KEY=your-secret-key-here
49+ GITHUB_APP_ID=123456
50+ GITHUB_APP_PRIVATE_KEY=/path/to/private-key.pem
51+ GITHUB_APP_CLIENT_ID=Iv1.xxxxx
52+ GITHUB_APP_CLIENT_SECRET=xxxxx
4053
41- docker compose -f docker-compose.infra.yml up -d db
54+ Database Setup
55+ ~~~~~~~~~~~~~~
4256
43- 2. Environment variables configured (create `` .env `` from `` .env.example `` ):
57+ PostgreSQL database running (use docker-compose ):
4458
45- .. code-block :: bash
59+ .. code-block :: bash
4660
47- DB_URL=postgresql+asyncpg://byte:bot@localhost:5432/byte
61+ docker compose -f docker-compose.infra.yml up -d db
4862
4963 Upgrade to Latest
5064~~~~~~~~~~~~~~~~~
@@ -225,8 +239,17 @@ Model Location
225239
226240All database models are defined in the ``byte-common `` package:
227241
228- - **Location **: ``packages/byte-common/src/byte_common/models.py ``
229- - **Import **: ``from byte_common.models import Guild, User, GitHubConfig, etc. ``
242+ - **Location **: ``packages/byte-common/src/byte_common/models/ `` (directory with separate model files)
243+ - **Import **: ``from byte_common.models import Guild, User, GitHubConfig, ForumConfig, SOTagsConfig, AllowedUsersConfig ``
244+
245+ Models are organized as follows:
246+
247+ - ``guild.py `` - Guild configuration
248+ - ``user.py `` - User model
249+ - ``github_config.py `` - GitHub integration settings
250+ - ``forum_config.py `` - Forum channel configuration
251+ - ``sotags_config.py `` - Stack Overflow tags
252+ - ``allowed_users_config.py `` - User permissions
230253
231254This allows models to be shared between the API service and bot service.
232255
@@ -261,16 +284,29 @@ Ensure you're importing from ``byte_common.models``, not the old ``byte_bot.serv
261284Production Deployment
262285=====================
263286
264- On Railway, migrations are automatically applied before the service starts via the start command :
287+ On Railway, migrations are run programmatically before the service starts using the migration script :
265288
266289.. code-block :: bash
267290
268- uv run app database upgrade --no-prompt && uv run app run-all ...
291+ # From railway.json or nixpacks.toml
292+ uv run python -m byte_api.scripts.migrate && uv run litestar run --app byte_api.app:create_app --host 0.0.0.0 --port $PORT
293+
294+ The migration script (``services/api/src/byte_api/scripts/migrate.py ``) uses the Advanced Alchemy Python API:
295+
296+ .. code-block :: python
297+
298+ from advanced_alchemy.alembic.commands import AlembicCommands
299+ from byte_api.lib.db.base import config
300+
301+ if __name__ == " __main__" :
302+ print (" Running database migrations..." )
303+ AlembicCommands(sqlalchemy_config = config).upgrade()
304+ print (" Migrations complete!" )
269305
270306 .. note ::
271307
272- The ``app `` CLI is currently only available in the monolithic setup. For microservices, migrations should be run
273- programmatically as shown above or through a dedicated migration service .
308+ The monolithic ``app `` CLI was removed in Phase 1.4 of the microservices migration.
309+ All migrations now use the Advanced Alchemy Python API directly .
274310
275311Rollback Plan
276312=============
0 commit comments