PAIG Database Setup¶
Paig Supports database setup and migration using Alembic. Paig provides the ability for users to set up various database types like Postgres, MySQL, SQLite, etc.
This section is optional
PAIG creates a database schema for you when you first run the application. If you want to customize the database schema, you can use the Alembic migration tool to create and manage database migrations.
How to Setup Database Configuration ¶
-
Configure the database URL in the configuration file as per your environment You have to follow the below format to configure the database URL. Format should be as follows:
If you are using Postgres :-YAML yaml database: url: postgresql+asyncpg://<username>:<password>@<host>:<port>/<database_name>
If you are using sqlite :-yaml database: url: sqlite+aiosqlite:///db/database.db
Note - Paig uses Async SQLAlchemy to connect to the database.Database driver should support async operations
Create and apply migrations for new Tables¶
-
Import the newly created models in the
alembic_db/env.py
fileExample:
Bash -
Create migration run below command
Bash - To apply latest or all pending migration on Database
Bash
Developers Guide¶
If developers want to add new tables or modify existing tables, they can take note of the following commands:-
-
Import the newly created models in the
alembic_db/env.py
fileExample:
Bash -
Create migration run below command
Bash -
To apply latest or all pending migration on Database
Bash -
To apply migrations till any specific migration
Bash -
Revert last applied migration on database
Bash -
Revert migrations till any specific migration
Bash -
Revert all applied migrations.(Don't use this command )
Bash