diff --git a/pages/_meta.json b/pages/_meta.json index b47ac23..361aa95 100644 --- a/pages/_meta.json +++ b/pages/_meta.json @@ -14,6 +14,6 @@ "type": "separator", "title": "Developers" }, - "setup-dev-environment": "Dev Environment", + "dev": "Dev Environment", "concepts": "Concepts" -} \ No newline at end of file +} diff --git a/pages/dev/backend-migrations.mdx b/pages/dev/backend-migrations.mdx new file mode 100644 index 0000000..2a04968 --- /dev/null +++ b/pages/dev/backend-migrations.mdx @@ -0,0 +1,75 @@ +import { Callout } from "nextra-theme-docs"; +import { Steps } from "nextra-theme-docs"; + +# Backend Migrations + +This is a guide to use migrations for LearnHouse, it will walk you through the process of using migrations in the backend. + +## Prerequisites + +- [Docker](https://docs.docker.com/get-docker/) +- [Python 3.12.x](https://www.python.org/downloads/) +- [Poetry](https://python-poetry.org/docs/) +- [Alembic](https://alembic.sqlalchemy.org/en/latest/) +- macOS, Linux or Windows + + + For details on setting up the backend dev environment, see [Setting Up Your Dev Environment](/dev/setup-dev-environment) + + +## General Concepts + +Generally, we use Alembic for SQL migrations. +Make sure to check out their [tutorial](https://alembic.sqlalchemy.org/en/latest/tutorial.html) if you have never used it before. + +## Adding Migrations + + + +### Navigate to your backend directory at `apps/api` + +Then use the following command to indicate that the database is already using the newest state. + + + Make sure that the production app (in the container stack) was running at least once. + This way, you can guarantee that the DB is up-to-date. + + +```bash +poetry run alembic stamp head +``` + +### Perform Changes In The DB + +Perform any change on the schema of the database, you could add a table for the "Example" feature, for instance. +To generate a revision with the changes you did on your DB. + +```bash +poetry run alembic revision --autogenerate -m "Example" +``` + +### Check Migrations History + +Check your migrations history + +```bash +poetry run alembic history +``` + +### Perform all the Migrations + +Do all the migrations + +```bash +poetry run alembic upgrade head +``` + +In order to check the migrations, visit a local directory that maps to [this path](https://github.com/learnhouse/learnhouse/tree/dev/apps/api/migrations). + + + + + + For downgrading the latest migration, you can use `alembic downgrade -2`. + Make sure to consult the Alembic docs for further information. + diff --git a/pages/setup-dev-environment.mdx b/pages/dev/setup-dev-environment.mdx similarity index 100% rename from pages/setup-dev-environment.mdx rename to pages/dev/setup-dev-environment.mdx