ALeRCE database plugins.
Project description
Database Models for ALeRCE
This lib offers database initialization procedures for MongoDB and PostgreSQL, using the ALeRCE core models.
Installing db_plugins
For local development:
db_plugins installation is recommended with poetry. You can clone the repository and then
cd libs/db-plugins
poetry install
Alternatively, you can use pip
cd libs/db-plugins
pip install -e .
As a local dependency:
cd some_package
poetry add ../libs/db-plugins
As a remote dependency .. code-block:: console
poetry add “https://github.com/alercebroker/db-plugins.git#subdirectory=libs/db-plugins”
Database
1. Database Initialization
Database plugins will read the configuration you define in a settings.py file. This file should have a DB_CONFIG dictionary with the database connection parameters.
Here is and example on the params used with the SQL plugin:
DB_CONFIG: {
"SQL": {
"SQLALCHEMY_DATABASE_URL": "sqlite:///:memory:"
}
}
After defining DB_CONFIG you can now initialize your database. To do so, run the initdb command as follows
dbp initdb
2. Migrations (SQL only)
When changes to models are made you would want to update the database without creating it all again, or maybe you want to undo some changes and return to a previous state.
The solution is to create migrations. Migrations keep track of your database changes and let you detect differences between your database and models and update the database accordingly.
Migrations will be created by running dbp make_migrations. This command will read your database credentials from DB_CONFIG inside settings.py.
Then, to update your database to latest changes execute dbp migrate.
Database plugins
1. SQL
Initialize database
Before you connect to your database, make sure you initialize it first. To do that execute the following command from your step root folder
dbp initdb
When you run this command with an empty database it will create the following schema:
Migrations
Migrations keep track of database changes. To fully initialize the database with your step configuration run
dbp make_migrations
dbp migrate
This will set the head state for tracking changes on the database and also execute any migrations that might be present.
The first command dbp make_migrations will create migration files according to differences from dbp models and your database.
The seccond command dbp migrate will execute the migrations and update your database.
What migrations can and can’t detect
Migrations will detect:
Table additions, removals.
Column additions, removals.
Change of nullable status on columns.
Basic changes in indexes
Migrations can’t detect:
Changes of table name. These will come out as an add/drop of two different tables, and should be hand-edited into a name change instead.
Changes of column name. Like table name changes, these are detected as a column add/drop pair, which is not at all the same as a name change.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file db_plugins-25.0.1a26.tar.gz
.
File metadata
- Download URL: db_plugins-25.0.1a26.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.11.10 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00502c0f6e2671d3566e7c7143b42097a574472f4b20cf4fb11c051e7550b37c |
|
MD5 | 22e8b56104358f3aab6cb673e7846635 |
|
BLAKE2b-256 | 899b4fc999979067791fa64d16cb232d347c7549838de990eb1c242d86e05401 |
File details
Details for the file db_plugins-25.0.1a26-py3-none-any.whl
.
File metadata
- Download URL: db_plugins-25.0.1a26-py3-none-any.whl
- Upload date:
- Size: 16.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.11.10 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed760045afe50687f3d117c4f54386079cdabd98256cde3c95bdd7c219bed819 |
|
MD5 | fb06ac4ac0b1bc687a36cb6e4b12b3d3 |
|
BLAKE2b-256 | 4c7f643018eccaec94ec027940a6c087db6f0fc38b7515fb5c3a2060bc12bc25 |