Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ prepend_sys_path = .

version_path_separator = os

sqlalchemy.url = postgresql+asyncpg://workout:workout@localhost/workout
sqlalchemy.url = postgresql+psycopg://workout:workout@localhost/workout

[post_write_hooks]

Expand Down
14 changes: 7 additions & 7 deletions alembic/env.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import asyncio
from logging.config import fileConfig

from sqlalchemy import pool
from sqlalchemy.engine import Connection
from sqlalchemy.ext.asyncio import async_engine_from_config
from sqlalchemy import pool

from alembic import context
from workout_api.contrib.models import BaseModel
from workout_api.contrib.repository.models import *
from workout_api.contrib.repository.models import * # noqa: F403

config = context.config

Expand All @@ -20,29 +20,29 @@


def run_migrations_offline() -> None:
url = config.get_main_option("sqlalchemy.url")
url = config.get_main_option('sqlalchemy.url')
context.configure(
url=url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
dialect_opts={'paramstyle': 'named'},
)

with context.begin_transaction():
context.run_migrations()


def do_run_migrations(connection: Connection) -> None:
def do_run_migrations(connection: Connection) -> None:
context.configure(connection=connection, target_metadata=target_metadata)

with context.begin_transaction():
context.run_migrations()


async def run_async_migrations() -> None:
connectable = async_engine_from_config(
config.get_section(config.config_ini_section, {}),
prefix="sqlalchemy.",
prefix='sqlalchemy.',
poolclass=pool.NullPool,
)
async with connectable.connect() as connection:
Expand Down
77 changes: 77 additions & 0 deletions alembic/versions/12b6aed6a26d_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
"""initial

Revision ID: 12b6aed6a26d
Revises:
Create Date: 2025-07-23 17:11:04.246843

"""

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision = '12b6aed6a26d'
down_revision = None
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
'categorias',
sa.Column('pk_id', sa.Integer(), nullable=False),
sa.Column('nome', sa.String(length=50), nullable=False),
sa.Column('id', sa.UUID(), nullable=False),
sa.PrimaryKeyConstraint('pk_id'),
sa.UniqueConstraint('nome'),
)
op.create_table(
'centros_treinamento',
sa.Column('pk_id', sa.Integer(), nullable=False),
sa.Column('nome', sa.String(length=50), nullable=False),
sa.Column('endereco', sa.String(length=60), nullable=False),
sa.Column('proprietario', sa.String(length=30), nullable=False),
sa.Column('id', sa.UUID(), nullable=False),
sa.PrimaryKeyConstraint('pk_id'),
sa.UniqueConstraint('nome'),
)
op.create_table(
'atletas',
sa.Column('pk_id', sa.Integer(), nullable=False),
sa.Column('nome', sa.String(length=50), nullable=False),
sa.Column('cpf', sa.String(length=11), nullable=False),
sa.Column('idade', sa.Integer(), nullable=False),
sa.Column('peso', sa.Float(), nullable=False),
sa.Column('altura', sa.Float(), nullable=False),
sa.Column('sexo', sa.String(length=1), nullable=False),
sa.Column(
'created_at',
sa.DateTime(timezone=True),
server_default=sa.text("timezone('utc', now())"),
nullable=False,
),
sa.Column('categoria_id', sa.Integer(), nullable=False),
sa.Column('centro_treinamento_id', sa.Integer(), nullable=False),
sa.Column('id', sa.UUID(), nullable=False),
sa.ForeignKeyConstraint(
['categoria_id'],
['categorias.pk_id'],
),
sa.ForeignKeyConstraint(
['centro_treinamento_id'],
['centros_treinamento.pk_id'],
),
sa.PrimaryKeyConstraint('pk_id'),
sa.UniqueConstraint('cpf'),
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('atletas')
op.drop_table('centros_treinamento')
op.drop_table('categorias')
# ### end Alembic commands ###
62 changes: 0 additions & 62 deletions alembic/versions/c006e8463eb4_init_db.py

This file was deleted.

1 change: 1 addition & 0 deletions migrations/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Generic single-database configuration.
78 changes: 78 additions & 0 deletions migrations/env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from logging.config import fileConfig

from sqlalchemy import engine_from_config
from sqlalchemy import pool

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.
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() -> 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()
28 changes: 28 additions & 0 deletions migrations/script.py.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""${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, Sequence[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:
"""Upgrade schema."""
${upgrades if upgrades else "pass"}


def downgrade() -> None:
"""Downgrade schema."""
${downgrades if downgrades else "pass"}
Loading