working again

This commit is contained in:
2025-08-22 05:41:12 -07:00
parent 837bda1706
commit 9c4e652047
6 changed files with 396 additions and 0 deletions

37
migrations/alembic.ini Normal file
View File

@@ -0,0 +1,37 @@
[alembic]
script_location = migrations/versions
sqlalchemy.url = sqlite:///data/garmin.db
[loggers]
keys = root,sqlalchemy,alembic
[handlers]
keys = console
[formatters]
keys = generic
[logger_root]
level = WARN
handlers = console
qualname =
[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine
[logger_alembic]
level = WARN
handlers =
qualname = alembic
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
[formatter_generic]
format = %(asctime)s.%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S

View File

@@ -0,0 +1,36 @@
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('power_analysis', sa.Column('peak_power_1s', sa.Float(), nullable=True))
op.add_column('power_analysis', sa.Column('peak_power_5s', sa.Float(), nullable=True))
op.add_column('power_analysis', sa.Column('peak_power_20s', sa.Float(), nullable=True))
op.add_column('power_analysis', sa.Column('peak_power_300s', sa.Float(), nullable=True))
op.add_column('power_analysis', sa.Column('normalized_power', sa.Float(), nullable=True))
op.add_column('power_analysis', sa.Column('intensity_factor', sa.Float(), nullable=True))
op.add_column('power_analysis', sa.Column('training_stress_score', sa.Float(), nullable=True))
op.add_column('gearing_analysis', sa.Column('estimated_chainring_teeth', sa.Integer(), nullable=True))
op.add_column('gearing_analysis', sa.Column('estimated_cassette_teeth', sa.Integer(), nullable=True))
op.add_column('gearing_analysis', sa.Column('gear_ratio', sa.Float(), nullable=True))
op.add_column('gearing_analysis', sa.Column('gear_inches', sa.Float(), nullable=True))
op.add_column('gearing_analysis', sa.Column('development_meters', sa.Float(), nullable=True))
op.add_column('gearing_analysis', sa.Column('confidence_score', sa.Float(), nullable=True))
op.add_column('gearing_analysis', sa.Column('analysis_method', sa.String(), default="singlespeed_estimation"))
def downgrade():
op.drop_column('power_analysis', 'peak_power_1s')
op.drop_column('power_analysis', 'peak_power_5s')
op.drop_column('power_analysis', 'peak_power_20s')
op.drop_column('power_analysis', 'peak_power_300s')
op.drop_column('power_analysis', 'normalized_power')
op.drop_column('power_analysis', 'intensity_factor')
op.drop_column('power_analysis', 'training_stress_score')
op.drop_column('gearing_analysis', 'estimated_chainring_teeth')
op.drop_column('gearing_analysis', 'estimated_cassette_teeth')
op.drop_column('gearing_analysis', 'gear_ratio')
op.drop_column('gearing_analysis', 'gear_inches')
op.drop_column('gearing_analysis', 'development_meters')
op.drop_column('gearing_analysis', 'confidence_score')
op.drop_column('gearing_analysis', 'analysis_method')

View File

@@ -0,0 +1,72 @@
from alembic import context
from sqlalchemy import engine_from_config, pool
from logging.config import fileConfig
# this is the Alembic Config object, which provides
# access to the values within the .ini file you've provided
config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
if config.config_file_name is not None:
fileConfig(config.config_file_name)
# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
target_metadata = None
# 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 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=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
)
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.
"""
connectable = engine_from_config(
config.get_section(config.config_ini_section, {}),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
with connectable.connect() as connection:
context.configure(
connection=connection, target_metadata=target_metadata
)
with context.begin_transaction():
context.run_migrations()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()