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.
Metadata
Release files for db_plugins 27.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| db_plugins-27.4.0.tar.gz | 13.0 kB | Without provenance | Details for db_plugins-27.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| db_plugins-27.4.0-py3-none-any.whl | Python 3 | none | any | Details for db_plugins-27.4.0-py3-none-any.whl |
Total release size: 29.9 kB
Release files / db_plugins-27.4.0.tar.gz
| Download URL | db_plugins-27.4.0.tar.gz |
|---|---|
| Size | 13.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0d33547e6243cc318ebe6926ba299755af9ec1d7fcc551c9a48e317de4102a44
|
|
BLAKE2b-256 checksum How to use checksums |
aeb34a5b476692e118a53bee5bab02f76040e522f40f9cf02bd3c00524ecb879
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.0.1 CPython/3.11.11 Linux/6.8.0-1020-azure
|
Release files / db_plugins-27.4.0-py3-none-any.whl
| Download URL | db_plugins-27.4.0-py3-none-any.whl |
|---|---|
| Size | 16.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4ca429e92c7bc8abf86e171eda75c628ffe2c35eeffe8b0d395105e4778fa7ee
|
|
BLAKE2b-256 checksum How to use checksums |
6ba04be430dfc9e5ec8c1d14aa598c3d01221735091cabca07d0b2d1ea040204
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.0.1 CPython/3.11.11 Linux/6.8.0-1020-azure
|
Security for db_plugins 27.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.