release: publish saldo 0.1.0

This commit is contained in:
2026-04-21 21:17:36 +02:00
commit 6f5e704739
95 changed files with 9196 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
Single-database configuration for Flask.
+50
View File
@@ -0,0 +1,50 @@
# A generic, single database configuration.
[alembic]
# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s
# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false
# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic,flask_migrate
[handlers]
keys = console
[formatters]
keys = generic
[logger_root]
level = WARN
handlers = console
qualname =
[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine
[logger_alembic]
level = INFO
handlers =
qualname = alembic
[logger_flask_migrate]
level = INFO
handlers =
qualname = flask_migrate
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S
+113
View File
@@ -0,0 +1,113 @@
import logging
from logging.config import fileConfig
from flask import current_app
from alembic import context
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)
logger = logging.getLogger('alembic.env')
def get_engine():
try:
# this works with Flask-SQLAlchemy<3 and Alchemical
return current_app.extensions['migrate'].db.get_engine()
except (TypeError, AttributeError):
# this works with Flask-SQLAlchemy>=3
return current_app.extensions['migrate'].db.engine
def get_engine_url():
try:
return get_engine().url.render_as_string(hide_password=False).replace(
'%', '%%')
except AttributeError:
return str(get_engine().url).replace('%', '%%')
# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
config.set_main_option('sqlalchemy.url', get_engine_url())
target_db = current_app.extensions['migrate'].db
# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.
def get_metadata():
if hasattr(target_db, 'metadatas'):
return target_db.metadatas[None]
return target_db.metadata
def run_migrations_offline():
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url, target_metadata=get_metadata(), literal_binds=True
)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
# this callback is used to prevent an auto-migration from being generated
# when there are no changes to the schema
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
def process_revision_directives(context, revision, directives):
if getattr(config.cmd_opts, 'autogenerate', False):
script = directives[0]
if script.upgrade_ops.is_empty():
directives[:] = []
logger.info('No changes in schema detected.')
conf_args = current_app.extensions['migrate'].configure_args
if conf_args.get("process_revision_directives") is None:
conf_args["process_revision_directives"] = process_revision_directives
connectable = get_engine()
with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=get_metadata(),
**conf_args
)
with context.begin_transaction():
context.run_migrations()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()
+24
View File
@@ -0,0 +1,24 @@
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}
# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
branch_labels = ${repr(branch_labels)}
depends_on = ${repr(depends_on)}
def upgrade():
${upgrades if upgrades else "pass"}
def downgrade():
${downgrades if downgrades else "pass"}
@@ -0,0 +1,39 @@
"""add entry benefit scope
Revision ID: 46efbd09438b
Revises: 71ff8f291d18
Create Date: 2026-04-20 22:26:46.698956
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '46efbd09438b'
down_revision = '71ff8f291d18'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('entry', schema=None) as batch_op:
batch_op.add_column(
sa.Column(
'benefit_scope',
sa.String(length=20),
nullable=False,
server_default='both',
)
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('entry', schema=None) as batch_op:
batch_op.drop_column('benefit_scope')
# ### end Alembic commands ###
@@ -0,0 +1,35 @@
"""add distribution ranges to month
Revision ID: 5f1c2e87a921
Revises: c4a1d9b9e2f1
Create Date: 2026-04-20 15:45:00.000000
"""
from __future__ import annotations
from alembic import op
import sqlalchemy as sa
revision = "5f1c2e87a921"
down_revision = "c4a1d9b9e2f1"
branch_labels = None
depends_on = None
def upgrade() -> None:
op.add_column("month", sa.Column("savings_min_pct", sa.Numeric(5, 2), nullable=False, server_default="15.00"))
op.add_column("month", sa.Column("savings_max_pct", sa.Numeric(5, 2), nullable=False, server_default="20.00"))
op.add_column("month", sa.Column("vacation_min_pct", sa.Numeric(5, 2), nullable=False, server_default="5.00"))
op.add_column("month", sa.Column("vacation_max_pct", sa.Numeric(5, 2), nullable=False, server_default="8.00"))
op.add_column("month", sa.Column("leisure_min_pct", sa.Numeric(5, 2), nullable=False, server_default="5.00"))
op.add_column("month", sa.Column("leisure_max_pct", sa.Numeric(5, 2), nullable=False, server_default="10.00"))
def downgrade() -> None:
op.drop_column("month", "leisure_max_pct")
op.drop_column("month", "leisure_min_pct")
op.drop_column("month", "vacation_max_pct")
op.drop_column("month", "vacation_min_pct")
op.drop_column("month", "savings_max_pct")
op.drop_column("month", "savings_min_pct")
@@ -0,0 +1,239 @@
"""initial schema
Revision ID: 71ff8f291d18
Revises:
Create Date: 2026-04-20 16:47:07.607628
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '71ff8f291d18'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('account',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=120), nullable=False),
sa.Column('slug', sa.String(length=120), nullable=False),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('sort_order', sa.Integer(), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name'),
sa.UniqueConstraint('slug')
)
op.create_table('month',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('label', sa.String(length=7), nullable=False),
sa.Column('year', sa.Integer(), nullable=False),
sa.Column('month', sa.Integer(), nullable=False),
sa.Column('auto_created', sa.Boolean(), nullable=False),
sa.Column('is_locked', sa.Boolean(), nullable=False),
sa.Column('notes', sa.Text(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('label')
)
op.create_table('user',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('username', sa.String(length=80), nullable=False),
sa.Column('email', sa.String(length=255), nullable=False),
sa.Column('password_hash', sa.String(length=255), nullable=False),
sa.Column('role', sa.String(length=20), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email'),
sa.UniqueConstraint('username')
)
op.create_table('allocation_suggestion',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('month_id', sa.Integer(), nullable=False),
sa.Column('target_account_id', sa.Integer(), nullable=False),
sa.Column('suggested_amount', sa.Numeric(precision=12, scale=2), nullable=False),
sa.Column('reason', sa.Text(), nullable=True),
sa.Column('strategy_key', sa.String(length=80), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['month_id'], ['month.id'], ),
sa.ForeignKeyConstraint(['target_account_id'], ['account.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('audit_log',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=True),
sa.Column('action', sa.String(length=120), nullable=False),
sa.Column('entity_type', sa.String(length=80), nullable=False),
sa.Column('entity_id', sa.Integer(), nullable=True),
sa.Column('payload_json', sa.Text(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('category',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('account_id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=120), nullable=False),
sa.Column('slug', sa.String(length=120), nullable=False),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('sort_order', sa.Integer(), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['account_id'], ['account.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('account_id', 'slug')
)
op.create_table('cost_participant',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=120), nullable=False),
sa.Column('is_app_user', sa.Boolean(), nullable=False),
sa.Column('linked_user_id', sa.Integer(), nullable=True),
sa.Column('is_external', sa.Boolean(), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['linked_user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name')
)
op.create_table('in_app_notification',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('type', sa.String(length=50), nullable=False),
sa.Column('title', sa.String(length=150), nullable=False),
sa.Column('body', sa.Text(), nullable=False),
sa.Column('action_url', sa.String(length=255), nullable=True),
sa.Column('is_read', sa.Boolean(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('monthly_allocation',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('month_id', sa.Integer(), nullable=False),
sa.Column('target_account_id', sa.Integer(), nullable=False),
sa.Column('label', sa.String(length=120), nullable=False),
sa.Column('amount', sa.Numeric(precision=12, scale=2), nullable=False),
sa.Column('source', sa.String(length=30), nullable=False),
sa.Column('is_locked', sa.Boolean(), nullable=False),
sa.Column('sort_order', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['month_id'], ['month.id'], ),
sa.ForeignKeyConstraint(['target_account_id'], ['account.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('month_id', 'target_account_id')
)
op.create_table('monthly_income',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('month_id', sa.Integer(), nullable=False),
sa.Column('label', sa.String(length=120), nullable=False),
sa.Column('amount', sa.Numeric(precision=12, scale=2), nullable=False),
sa.Column('sort_order', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['month_id'], ['month.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('notification_preference',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('notify_month_end', sa.Boolean(), nullable=False),
sa.Column('notify_missing_distribution', sa.Boolean(), nullable=False),
sa.Column('notify_missing_values', sa.Boolean(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('user_id')
)
op.create_table('push_subscription',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('endpoint', sa.Text(), nullable=False),
sa.Column('p256dh_key', sa.Text(), nullable=False),
sa.Column('auth_key', sa.Text(), nullable=False),
sa.Column('user_agent', sa.String(length=255), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('entry',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('category_id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=120), nullable=False),
sa.Column('slug', sa.String(length=120), nullable=False),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('default_amount', sa.Numeric(precision=12, scale=2), nullable=False),
sa.Column('amount_type', sa.String(length=20), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=False),
sa.Column('sort_order', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['category_id'], ['category.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('category_id', 'slug')
)
op.create_table('entry_share_rule',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('entry_id', sa.Integer(), nullable=False),
sa.Column('participant_id', sa.Integer(), nullable=False),
sa.Column('share_type', sa.String(length=20), nullable=False),
sa.Column('share_value', sa.Numeric(precision=12, scale=4), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['entry_id'], ['entry.id'], ),
sa.ForeignKeyConstraint(['participant_id'], ['cost_participant.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('entry_id', 'participant_id')
)
op.create_table('monthly_entry_value',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('month_id', sa.Integer(), nullable=False),
sa.Column('entry_id', sa.Integer(), nullable=False),
sa.Column('planned_amount', sa.Numeric(precision=12, scale=2), nullable=False),
sa.Column('note', sa.Text(), nullable=True),
sa.Column('created_by', sa.Integer(), nullable=True),
sa.Column('updated_by', sa.Integer(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['created_by'], ['user.id'], ),
sa.ForeignKeyConstraint(['entry_id'], ['entry.id'], ),
sa.ForeignKeyConstraint(['month_id'], ['month.id'], ),
sa.ForeignKeyConstraint(['updated_by'], ['user.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('month_id', 'entry_id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('monthly_entry_value')
op.drop_table('entry_share_rule')
op.drop_table('entry')
op.drop_table('push_subscription')
op.drop_table('notification_preference')
op.drop_table('monthly_income')
op.drop_table('monthly_allocation')
op.drop_table('in_app_notification')
op.drop_table('cost_participant')
op.drop_table('category')
op.drop_table('audit_log')
op.drop_table('allocation_suggestion')
op.drop_table('user')
op.drop_table('month')
op.drop_table('account')
# ### end Alembic commands ###
@@ -0,0 +1,28 @@
"""add entry allocation target
Revision ID: 8d3f0c61bb21
Revises: 5f1c2e87a921
Create Date: 2026-04-20 16:10:00.000000
"""
from __future__ import annotations
from alembic import op
import sqlalchemy as sa
revision = "8d3f0c61bb21"
down_revision = "5f1c2e87a921"
branch_labels = None
depends_on = None
def upgrade() -> None:
op.add_column(
"entry",
sa.Column("is_allocation_target", sa.Boolean(), nullable=False, server_default=sa.false()),
)
def downgrade() -> None:
op.drop_column("entry", "is_allocation_target")
@@ -0,0 +1,53 @@
"""add community accounts
Revision ID: a91b7c4d2f10
Revises: 8d3f0c61bb21
Create Date: 2026-04-21 11:30:00.000000
"""
from __future__ import annotations
from alembic import op
import sqlalchemy as sa
revision = "a91b7c4d2f10"
down_revision = "8d3f0c61bb21"
branch_labels = None
depends_on = None
def upgrade() -> None:
op.create_table(
"community_account",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("name", sa.String(length=120), nullable=False),
sa.Column("slug", sa.String(length=120), nullable=False),
sa.Column("description", sa.Text(), nullable=True),
sa.Column("account_type", sa.String(length=20), nullable=False),
sa.Column("linked_account_slug", sa.String(length=120), nullable=True),
sa.Column("sort_order", sa.Integer(), nullable=False),
sa.Column("is_active", sa.Boolean(), nullable=False),
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("name"),
sa.UniqueConstraint("slug"),
)
with op.batch_alter_table("category", schema=None) as batch_op:
batch_op.add_column(sa.Column("community_account_id", sa.Integer(), nullable=True))
batch_op.create_foreign_key(
"fk_category_community_account_id",
"community_account",
["community_account_id"],
["id"],
)
def downgrade() -> None:
with op.batch_alter_table("category", schema=None) as batch_op:
batch_op.drop_constraint("fk_category_community_account_id", type_="foreignkey")
batch_op.drop_column("community_account_id")
op.drop_table("community_account")
@@ -0,0 +1,35 @@
"""expand entry benefit scope
Revision ID: ab4c2d1e9a10
Revises: d9f3c6a1b7f0
Create Date: 2026-04-21 16:05:00.000000
"""
from alembic import op
import sqlalchemy as sa
revision = "ab4c2d1e9a10"
down_revision = "d9f3c6a1b7f0"
branch_labels = None
depends_on = None
def upgrade() -> None:
with op.batch_alter_table("entry", schema=None) as batch_op:
batch_op.alter_column(
"benefit_scope",
existing_type=sa.String(length=20),
type_=sa.String(length=120),
existing_nullable=False,
)
def downgrade() -> None:
with op.batch_alter_table("entry", schema=None) as batch_op:
batch_op.alter_column(
"benefit_scope",
existing_type=sa.String(length=120),
type_=sa.String(length=20),
existing_nullable=False,
)
@@ -0,0 +1,33 @@
"""add avatar fields
Revision ID: c1f8d92b4e31
Revises: a91b7c4d2f10
Create Date: 2026-04-21 12:20:00.000000
"""
from __future__ import annotations
from alembic import op
import sqlalchemy as sa
revision = "c1f8d92b4e31"
down_revision = "a91b7c4d2f10"
branch_labels = None
depends_on = None
def upgrade() -> None:
with op.batch_alter_table("user", schema=None) as batch_op:
batch_op.add_column(sa.Column("avatar_url", sa.String(length=255), nullable=True))
with op.batch_alter_table("cost_participant", schema=None) as batch_op:
batch_op.add_column(sa.Column("avatar_url", sa.String(length=255), nullable=True))
def downgrade() -> None:
with op.batch_alter_table("cost_participant", schema=None) as batch_op:
batch_op.drop_column("avatar_url")
with op.batch_alter_table("user", schema=None) as batch_op:
batch_op.drop_column("avatar_url")
@@ -0,0 +1,28 @@
"""add personal split to month
Revision ID: c4a1d9b9e2f1
Revises: 46efbd09438b
Create Date: 2026-04-20 15:10:00.000000
"""
from __future__ import annotations
from alembic import op
import sqlalchemy as sa
revision = "c4a1d9b9e2f1"
down_revision = "46efbd09438b"
branch_labels = None
depends_on = None
def upgrade() -> None:
op.add_column(
"month",
sa.Column("personal_split_desi_pct", sa.Numeric(5, 2), nullable=False, server_default="50.00"),
)
def downgrade() -> None:
op.drop_column("month", "personal_split_desi_pct")
@@ -0,0 +1,31 @@
"""add user display name
Revision ID: d9f3c6a1b7f0
Revises: c1f8d92b4e31
Create Date: 2026-04-21 18:20:00.000000
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "d9f3c6a1b7f0"
down_revision = "c1f8d92b4e31"
branch_labels = None
depends_on = None
def upgrade():
with op.batch_alter_table("user", schema=None) as batch_op:
batch_op.add_column(sa.Column("display_name", sa.String(length=120), nullable=True))
op.execute('UPDATE user SET display_name = username WHERE display_name IS NULL')
with op.batch_alter_table("user", schema=None) as batch_op:
batch_op.alter_column("display_name", existing_type=sa.String(length=120), nullable=False)
def downgrade():
with op.batch_alter_table("user", schema=None) as batch_op:
batch_op.drop_column("display_name")