Added a new backend settings system
This can be used for saving runtime-configurable settings in the database.
This commit is contained in:
@@ -1,7 +1,18 @@
|
||||
# Migrations
|
||||
|
||||
Creating a new version:
|
||||
Migrations are used to create and update the database schema. They are run automatically every time Spoolman starts.
|
||||
|
||||
To create a new migration, edit the tables as desired in `spoolman/database/models.py`, then start the Spoolman server to update your local sqlite database.
|
||||
|
||||
```bash
|
||||
pdm run python -m spoolman.main
|
||||
```
|
||||
|
||||
Stop the server once it's up.
|
||||
|
||||
Then, let Alembic automatically create a new migration file:
|
||||
```bash
|
||||
pdm run alembic revision -m "some title" --autogenerate
|
||||
```
|
||||
|
||||
Go into the created migration and make sure it looks good, that the column changes etc are as desired. Format it with Black and Ruff. Commit.
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
"""Added Settings table.
|
||||
|
||||
Revision ID: ccbb17aeda7c
|
||||
Revises: 92793c8a937c
|
||||
Create Date: 2024-01-03 13:46:41.362341
|
||||
"""
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "ccbb17aeda7c"
|
||||
down_revision = "92793c8a937c"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Perform the upgrade."""
|
||||
op.create_table(
|
||||
"setting",
|
||||
sa.Column("key", sa.String(length=64), nullable=False),
|
||||
sa.Column("value", sa.Text(), nullable=False),
|
||||
sa.Column("last_updated", sa.DateTime(), nullable=False),
|
||||
sa.PrimaryKeyConstraint("key"),
|
||||
)
|
||||
op.create_index(op.f("ix_setting_key"), "setting", ["key"], unique=False)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Perform the downgrade."""
|
||||
op.drop_index(op.f("ix_setting_key"), table_name="setting")
|
||||
op.drop_table("setting")
|
||||
Reference in New Issue
Block a user