Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: migrations by app #17

Merged
merged 1 commit into from
Aug 27, 2023
Merged
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
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@ alembic revision --autogenerate -m "init"
## Creata a new migration:

```bash
alembic revision --autogenerate -m "add model core.country"
alembic revision --autogenerate -m "add model core.user"

alembic revision --autogenerate --branch-label core \
--version-path core/infra/database/alembic/versions/ -m 'add core models'

alembic revision --autogenerate --branch-label filmin \
--version-path filmin/infra/database/alembic/versions/ -m 'add filmin models'

```

## Apply the migration to the database:

```bash
alembic upgrade head

alembic upgrade filmin@head

```
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ services:
postgres:
container_name: postgres.filmin
hostname: postgres.filmin
image: postgres:15
image: postgres:15.3
environment:
POSTGRES_DB: ${POSTGRES_DB-filmin}
POSTGRES_USER: ${POSTGRES_USER-postgres}
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ select = [
"YTT", # flake8-2020
"C", # flake8-comprehensions
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"T20", # flake8-print
"RET", # flake8-return
"SLF", # flake8-self
Expand Down Expand Up @@ -82,6 +81,9 @@ known-third-party = [
lines-after-imports = 2
lines-between-types = 1

[tool.ruff.flake8-bugbear]
extend-immutable-calls = ["fastapi.Depends", "fastapi.Query"]

[tool.black]
line-length = 120
skip-string-normalization = true
Expand Down
6 changes: 4 additions & 2 deletions src/alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

[alembic]
# path to migration scripts
script_location = infra/database/alembic core/infra/database/alembic/migrations/ filmin/infra/database/alembic/migrations/
script_location = infra/database/alembic

version_locations = core/infra/database/alembic/versions filmin/infra/database/alembic/versions

# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
# Uncomment the line below if you want the files to be prepended with date and time
Expand Down Expand Up @@ -47,7 +49,7 @@ prepend_sys_path = .
# version_path_separator = :
# version_path_separator = ;
# version_path_separator = space
version_path_separator = os # Use os.pathsep. Default configuration used for new projects.
# version_path_separator = os # Use os.pathsep. Default configuration used for new projects.

# the output encoding used when revision files
# are written from script.py.mako
Expand Down
101 changes: 0 additions & 101 deletions src/core/infra/database/alembic/env.py

This file was deleted.

24 changes: 0 additions & 24 deletions src/core/infra/database/alembic/script.py.mako

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
"""add model core.user
"""add core models

Revision ID: e484f9d6a6af
Revises: 0bfd3f8f6bdf
Create Date: 2023-06-10 07:53:48.208192
Revision ID: 440f205f8ac8
Revises:
Create Date: 2023-08-27 06:40:17.009905

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'e484f9d6a6af'
down_revision = '0bfd3f8f6bdf'
branch_labels = None
revision = '440f205f8ac8'
down_revision = None
branch_labels = ('core',)
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
'core_country',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('code', sa.String(length=2), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('pk_core_country')),
sa.UniqueConstraint('code', name=op.f('uq_core_country_code')),
)
op.create_table(
'core_user',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('uuid', sa.UUID(), nullable=True), # type: ignore
sa.Column('uuid', sa.UUID(), nullable=False), # type: ignore
sa.Column('first_name', sa.String(length=255), nullable=False),
sa.Column('last_name', sa.String(length=255), nullable=True),
sa.Column('email', sa.String(length=255), nullable=False),
Expand All @@ -38,4 +46,5 @@ def upgrade() -> None:
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('core_user')
op.drop_table('core_country')
# ### end Alembic commands ###
2 changes: 1 addition & 1 deletion src/core/infra/database/sqlalchemy/models/country.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
'core_country',
metadata,
Column('id', Integer, primary_key=True),
Column('code', String(2), unique=True),
Column('code', String(2), unique=True, nullable=False),
Column('name', String(255), nullable=False),
)
2 changes: 1 addition & 1 deletion src/core/infra/database/sqlalchemy/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'core_user',
metadata,
Column('id', Integer, primary_key=True),
Column('uuid', UUID(as_uuid=True), unique=True, default=uuid.uuid4),
Column('uuid', UUID(as_uuid=True), unique=True, nullable=False, default=uuid.uuid4),
Column('first_name', String(255), nullable=False),
Column('last_name', String(255), nullable=True),
Column('email', String(255), unique=True, nullable=False),
Expand Down

This file was deleted.

This file was deleted.

Loading