Vibe coded a bit more ... now we have session, attached picture and analysis, MOA group computation

This commit is contained in:
Gérald Colangelo
2026-03-17 17:20:54 +01:00
parent 120dc70cf5
commit 5b18fadb60
55 changed files with 5419 additions and 59 deletions

1
migrations/README Normal file
View File

@@ -0,0 +1 @@
Single-database configuration for Flask.

50
migrations/alembic.ini Normal file
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
migrations/env.py Normal file
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
migrations/script.py.mako Normal file
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"}

View File

@@ -0,0 +1,32 @@
"""user bio
Revision ID: 03057ef71b9c
Revises: 52a38793e62e
Create Date: 2026-03-17 14:57:43.452741
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '03057ef71b9c'
down_revision = '52a38793e62e'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('users', schema=None) as batch_op:
batch_op.add_column(sa.Column('bio', sa.Text(), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('users', schema=None) as batch_op:
batch_op.drop_column('bio')
# ### end Alembic commands ###

View File

@@ -0,0 +1,32 @@
"""drop session title
Revision ID: 1bc445c89261
Revises: a403e38c1c2e
Create Date: 2026-03-17 13:32:53.010390
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '1bc445c89261'
down_revision = 'a403e38c1c2e'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('shooting_sessions', schema=None) as batch_op:
batch_op.drop_column('title')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('shooting_sessions', schema=None) as batch_op:
batch_op.add_column(sa.Column('title', sa.VARCHAR(length=255), autoincrement=False, nullable=False))
# ### end Alembic commands ###

View File

@@ -0,0 +1,101 @@
"""initial schema
Revision ID: 1ec8afb14573
Revises:
Create Date: 2026-03-17 09:30:15.508359
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '1ec8afb14573'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('users',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('email', sa.String(length=255), nullable=False),
sa.Column('display_name', sa.String(length=120), nullable=True),
sa.Column('avatar_url', sa.Text(), nullable=True),
sa.Column('provider', sa.String(length=20), nullable=False),
sa.Column('provider_id', sa.String(length=255), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('last_login_at', sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email'),
sa.UniqueConstraint('provider', 'provider_id')
)
op.create_table('equipment_items',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('category', sa.String(length=30), nullable=False),
sa.Column('name', sa.String(length=200), nullable=False),
sa.Column('brand', sa.String(length=120), nullable=True),
sa.Column('model', sa.String(length=120), nullable=True),
sa.Column('serial_number', sa.String(length=120), nullable=True),
sa.Column('caliber', sa.String(length=60), nullable=True),
sa.Column('notes', sa.Text(), nullable=True),
sa.Column('photo_path', 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.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('shooting_sessions',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('title', sa.String(length=255), nullable=False),
sa.Column('session_date', sa.Date(), nullable=False),
sa.Column('location_name', sa.String(length=255), nullable=True),
sa.Column('location_lat', sa.Double(), nullable=True),
sa.Column('location_lon', sa.Double(), nullable=True),
sa.Column('distance_m', sa.Integer(), nullable=True),
sa.Column('weather_temp_c', sa.Numeric(precision=5, scale=1), nullable=True),
sa.Column('weather_wind_kph', sa.Numeric(precision=5, scale=1), nullable=True),
sa.Column('weather_cond', sa.String(length=80), nullable=True),
sa.Column('rifle_id', sa.Integer(), nullable=True),
sa.Column('scope_id', sa.Integer(), nullable=True),
sa.Column('ammo_brand', sa.String(length=120), nullable=True),
sa.Column('ammo_weight_gr', sa.Numeric(precision=7, scale=2), nullable=True),
sa.Column('ammo_lot', sa.String(length=80), nullable=True),
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.ForeignKeyConstraint(['rifle_id'], ['equipment_items.id'], ondelete='SET NULL'),
sa.ForeignKeyConstraint(['scope_id'], ['equipment_items.id'], ondelete='SET NULL'),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('analyses',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('session_id', sa.Integer(), nullable=True),
sa.Column('title', sa.String(length=255), nullable=False),
sa.Column('is_public', sa.Boolean(), nullable=False),
sa.Column('csv_path', sa.Text(), nullable=False),
sa.Column('pdf_path', sa.Text(), nullable=True),
sa.Column('overall_stats', sa.JSON(), nullable=False),
sa.Column('group_stats', sa.JSON(), nullable=False),
sa.Column('shot_count', sa.Integer(), nullable=False),
sa.Column('group_count', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['session_id'], ['shooting_sessions.id'], ondelete='SET NULL'),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('analyses')
op.drop_table('shooting_sessions')
op.drop_table('equipment_items')
op.drop_table('users')
# ### end Alembic commands ###

View File

@@ -0,0 +1,38 @@
"""local auth fields
Revision ID: 2b8adad5972b
Revises: 1ec8afb14573
Create Date: 2026-03-17 09:46:47.843894
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '2b8adad5972b'
down_revision = '1ec8afb14573'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('users', schema=None) as batch_op:
batch_op.add_column(sa.Column('password_hash', sa.Text(), nullable=True))
batch_op.add_column(sa.Column('email_confirmed', sa.Boolean(), nullable=False))
batch_op.add_column(sa.Column('email_confirm_token', sa.String(length=128), nullable=True))
batch_op.create_index('ix_users_email_confirm_token', ['email_confirm_token'], unique=False)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('users', schema=None) as batch_op:
batch_op.drop_index('ix_users_email_confirm_token')
batch_op.drop_column('email_confirm_token')
batch_op.drop_column('email_confirmed')
batch_op.drop_column('password_hash')
# ### end Alembic commands ###

View File

@@ -0,0 +1,32 @@
"""user show equipment public
Revision ID: 52a38793e62e
Revises: 1bc445c89261
Create Date: 2026-03-17 14:47:03.751535
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '52a38793e62e'
down_revision = '1bc445c89261'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('users', schema=None) as batch_op:
batch_op.add_column(sa.Column('show_equipment_public', sa.Boolean(), nullable=False, server_default=sa.false()))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('users', schema=None) as batch_op:
batch_op.drop_column('show_equipment_public')
# ### end Alembic commands ###

View File

@@ -0,0 +1,36 @@
"""scope fields
Revision ID: 875675ed7b5a
Revises: eb04fe02f528
Create Date: 2026-03-17 11:17:08.772131
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '875675ed7b5a'
down_revision = 'eb04fe02f528'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('equipment_items', schema=None) as batch_op:
batch_op.add_column(sa.Column('magnification', sa.String(length=50), nullable=True))
batch_op.add_column(sa.Column('reticle', sa.String(length=10), nullable=True))
batch_op.add_column(sa.Column('unit', sa.String(length=10), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('equipment_items', schema=None) as batch_op:
batch_op.drop_column('unit')
batch_op.drop_column('reticle')
batch_op.drop_column('magnification')
# ### end Alembic commands ###

View File

@@ -0,0 +1,32 @@
"""user avatar path
Revision ID: a403e38c1c2e
Revises: b94b21ec5fa9
Create Date: 2026-03-17 12:50:50.122814
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'a403e38c1c2e'
down_revision = 'b94b21ec5fa9'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('users', schema=None) as batch_op:
batch_op.add_column(sa.Column('avatar_path', sa.Text(), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('users', schema=None) as batch_op:
batch_op.drop_column('avatar_path')
# ### end Alembic commands ###

View File

@@ -0,0 +1,36 @@
"""session photos
Revision ID: b94b21ec5fa9
Revises: 875675ed7b5a
Create Date: 2026-03-17 11:41:05.860460
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'b94b21ec5fa9'
down_revision = '875675ed7b5a'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('session_photos',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('session_id', sa.Integer(), nullable=False),
sa.Column('photo_path', sa.Text(), nullable=False),
sa.Column('caption', sa.String(length=255), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['session_id'], ['shooting_sessions.id'], ),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('session_photos')
# ### end Alembic commands ###

View File

@@ -0,0 +1,32 @@
"""session_photo annotations
Revision ID: d46dc696b3c3
Revises: 03057ef71b9c
Create Date: 2026-03-17 15:35:22.180323
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'd46dc696b3c3'
down_revision = '03057ef71b9c'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('session_photos', schema=None) as batch_op:
batch_op.add_column(sa.Column('annotations', sa.JSON(), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('session_photos', schema=None) as batch_op:
batch_op.drop_column('annotations')
# ### end Alembic commands ###

View File

@@ -0,0 +1,32 @@
"""session is_public
Revision ID: eb04fe02f528
Revises: 2b8adad5972b
Create Date: 2026-03-17 10:13:53.102589
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'eb04fe02f528'
down_revision = '2b8adad5972b'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('shooting_sessions', schema=None) as batch_op:
batch_op.add_column(sa.Column('is_public', sa.Boolean(), nullable=False))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('shooting_sessions', schema=None) as batch_op:
batch_op.drop_column('is_public')
# ### end Alembic commands ###