Skip to content

Commit

Permalink
update readme for database migration
Browse files Browse the repository at this point in the history
  • Loading branch information
quang-ng committed Dec 3, 2024
1 parent 7919cff commit 87de1d3
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,37 +136,36 @@ This project uses Alembic for database migrations. Follow the steps below to gen

### Prerequisites

- Ensure you have Alembic installed in your Python environment. You can install it using pip:
- Ensure your database is running. If you're using Docker, you can start the database with:
```bash
pip install alembic ```
- Make sure your database is running. If you're using Docker, you can start the database with:
```bash
docker-compose -f .docker/postgres-compose.yaml up -d ```
docker-compose -f .docker/postgres-compose.yaml up -d
```

### Running Migrations

1. **Configure Alembic**: Ensure that the `alembic/env.py` file is correctly set up to connect to your database. This involves setting the SQLAlchemy URL in the `alembic.ini` file.
1. **Configure Alembic**: Ensure that the `alembic/env.py` file is correctly set up to connect to your database. The connection settings are managed through environment variables in your `.env` file.

2. **Create a New Migration**: To create a new migration script, run the following command:
```bash
alembic revision --autogenerate -m "Description of changes" ```
alembic revision --autogenerate -m "Description of changes"
```

This will generate a new migration script in the `alembic/versions` directory.

3. **Review the Migration Script**: Open the generated migration script and review it to ensure it accurately reflects the changes you want to make to the database schema.

4. **Apply the Migration**: To apply the migration to the database, run:
```bash
alembic upgrade head ```
alembic upgrade head
```

This command will apply all pending migrations up to the latest one.

5. **Verify the Database**: Check your database to ensure that the schema has been updated as expected.

### Troubleshooting

- If you encounter any issues, ensure that your database connection settings in `alembic.ini` are correct.
- If you encounter any issues, ensure that your database connection settings in the `.env` file are correct.
- Check the Alembic logs for any error messages that might indicate what went wrong.

For more detailed information on using Alembic, refer to the [Alembic documentation](https://alembic.sqlalchemy.org/en/latest/).

0 comments on commit 87de1d3

Please sign in to comment.