From 73197fb26f1a251451525c50e7a336ca85f433ce Mon Sep 17 00:00:00 2001 From: Automated Action Date: Thu, 19 Jun 2025 00:42:38 +0000 Subject: [PATCH] Update code via agent code generation --- alembic.ini | 98 +++++++++++++++++++++ alembic/README | 1 + alembic/env.py | 83 +++++++++++++++++ alembic/script.py.mako | 26 ++++++ alembic/versions/0001_initial_todo_model.py | 40 +++++++++ app/__init__.py | 1 - app/api/__init__.py | 1 - app/api/endpoints/__init__.py | 0 app/api/router.py | 15 ++++ 9 files changed, 263 insertions(+), 2 deletions(-) create mode 100644 alembic.ini create mode 100644 alembic/README create mode 100644 alembic/env.py create mode 100644 alembic/script.py.mako create mode 100644 alembic/versions/0001_initial_todo_model.py create mode 100644 app/api/endpoints/__init__.py create mode 100644 app/api/router.py diff --git a/alembic.ini b/alembic.ini new file mode 100644 index 0000000..1f6862b --- /dev/null +++ b/alembic.ini @@ -0,0 +1,98 @@ +# A generic, single database configuration. + +[alembic] +# path to migration scripts +script_location = alembic + +# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s +file_template = %%(year)d%%(month).2d%%(day).2d_%%(hour).2d%%(minute).2d_%%(rev)s_%%(slug)s + +# sys.path path, will be prepended to sys.path if present. +# defaults to the current working directory. +prepend_sys_path = . + +# timezone to use when rendering the date within the migration file +# as well as the filename. +# If specified, requires the python-dateutil library that can be +# installed by adding `alembic[tz]` to the pip requirements +# string value is passed to dateutil.tz.gettz() +# leave blank for localtime +# timezone = + +# max length of characters to apply to the +# "slug" field +# truncate_slug_length = 40 + +# set to 'true' to run the environment during +# the 'revision' command, regardless of autogenerate +# revision_environment = false + +# set to 'true' to allow .pyc and .pyo files without +# a source .py file to be detected as revisions in the +# versions/ directory +# sourceless = false + +# version number format; this is the primary format +# for generating new revision numbers +version_num_format = %04d + +# version locations; This can be a list of directories +# or a comma-separated list of paths +version_locations = %(here)s/alembic/versions + +# version path separator; As mentioned above, this is the character used to split +# version_locations. The default within new alembic.ini files is "os.pathsep", +# which is ";" on Windows and ":" on most Unix platforms. +version_path_separator = os.pathsep + +# the output encoding used when revision files +# are written from script.py.mako +# output_encoding = utf-8 + +sqlalchemy.url = sqlite:////app/storage/db/db.sqlite + +[post_write_hooks] +# post_write_hooks defines scripts or Python functions that are run +# on newly generated revision scripts. See the documentation for further +# detail and examples + +# format using "black" - use the console_scripts runner, against the "black" entrypoint +# hooks = black +# black.type = console_scripts +# black.entrypoint = black +# black.options = -l 79 REVISION_SCRIPT_FILENAME + +# Logging configuration +[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 = INFO +handlers = +qualname = alembic + +[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 \ No newline at end of file diff --git a/alembic/README b/alembic/README new file mode 100644 index 0000000..98e4f9c --- /dev/null +++ b/alembic/README @@ -0,0 +1 @@ +Generic single-database configuration. \ No newline at end of file diff --git a/alembic/env.py b/alembic/env.py new file mode 100644 index 0000000..dff1f85 --- /dev/null +++ b/alembic/env.py @@ -0,0 +1,83 @@ +import sys +from logging.config import fileConfig +from pathlib import Path + +from sqlalchemy import engine_from_config, pool +from alembic import context + +# Add the app directory to the path +sys.path.append(str(Path(__file__).resolve().parents[1])) + +# Import the models and Base +from app.db.base import Base +from app.models import todo # Import to register models with Base + +# 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. +if config.config_file_name is not None: + fileConfig(config.config_file_name) + +# add your model's MetaData object here +# for 'autogenerate' support +target_metadata = Base.metadata + +# 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() -> None: + """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() -> None: + """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() \ No newline at end of file diff --git a/alembic/script.py.mako b/alembic/script.py.mako new file mode 100644 index 0000000..3cf5352 --- /dev/null +++ b/alembic/script.py.mako @@ -0,0 +1,26 @@ +"""${message} + +Revision ID: ${up_revision} +Revises: ${down_revision | comma,n} +Create Date: ${create_date} + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa +${imports if imports else ""} + +# revision identifiers, used by Alembic. +revision: str = ${repr(up_revision)} +down_revision: Union[str, None] = ${repr(down_revision)} +branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)} +depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)} + + +def upgrade() -> None: + ${upgrades if upgrades else "pass"} + + +def downgrade() -> None: + ${downgrades if downgrades else "pass"} \ No newline at end of file diff --git a/alembic/versions/0001_initial_todo_model.py b/alembic/versions/0001_initial_todo_model.py new file mode 100644 index 0000000..18b103c --- /dev/null +++ b/alembic/versions/0001_initial_todo_model.py @@ -0,0 +1,40 @@ +"""Initial todo model + +Revision ID: 0001 +Revises: +Create Date: 2025-06-19 12:00:00.000000 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + +# revision identifiers, used by Alembic. +revision: str = '0001' +down_revision: Union[str, None] = None +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + """Create todos table""" + op.create_table( + 'todos', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('title', sa.String(length=200), nullable=False), + sa.Column('description', sa.Text(), nullable=True), + sa.Column('completed', sa.Boolean(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + op.create_index(op.f('ix_todos_id'), 'todos', ['id'], unique=False) + op.create_index(op.f('ix_todos_title'), 'todos', ['title'], unique=False) + + +def downgrade() -> None: + """Drop todos table""" + op.drop_index(op.f('ix_todos_title'), table_name='todos') + op.drop_index(op.f('ix_todos_id'), table_name='todos') + op.drop_table('todos') \ No newline at end of file diff --git a/app/__init__.py b/app/__init__.py index bdff6c4..e69de29 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1 +0,0 @@ -# App package \ No newline at end of file diff --git a/app/api/__init__.py b/app/api/__init__.py index a757e69..e69de29 100644 --- a/app/api/__init__.py +++ b/app/api/__init__.py @@ -1 +0,0 @@ -# API package \ No newline at end of file diff --git a/app/api/endpoints/__init__.py b/app/api/endpoints/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/api/router.py b/app/api/router.py new file mode 100644 index 0000000..5c59c4e --- /dev/null +++ b/app/api/router.py @@ -0,0 +1,15 @@ +""" +Main API router that includes all endpoint routers +""" +from fastapi import APIRouter + +from app.api.endpoints import todos + +api_router = APIRouter() + +# Include todos endpoints +api_router.include_router( + todos.router, + prefix="/todos", + tags=["todos"] +) \ No newline at end of file