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 Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ COPY pyproject.toml pyproject.toml

RUN pip install poetry
RUN poetry config virtualenvs.create false
RUN poetry install --no-dev
RUN poetry install --no-root

COPY . /app

Expand Down
2 changes: 1 addition & 1 deletion alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ version_path_separator = os # Use os.pathsep. Default configuration used for ne
# are written from script.py.mako
# output_encoding = utf-8

#sqlalchemy.url = driver://user:pass@localhost/dbname
sqlalchemy.url = ${POSTGRES__URL}


[post_write_hooks]
Expand Down
3 changes: 0 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.8'

services:
web:
build: .
Expand All @@ -9,7 +7,6 @@ services:
- "8000:8000"
env_file:
- ./ops/environment/.default.env
- ./ops/environment/.local.env
depends_on:
# db:
# condition: service_healthy
Expand Down
2 changes: 1 addition & 1 deletion migrations/README
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Generic single-database configuration with an async dbapi.
Generic single-database configuration.
60 changes: 17 additions & 43 deletions migrations/env.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
import asyncio
import os
from logging.config import fileConfig

from sqlalchemy import engine_from_config
from sqlalchemy import pool
from sqlalchemy.engine import Connection
from sqlalchemy.ext.asyncio import async_engine_from_config
from sqlmodel import SQLModel

from alembic import context

from src.catalogue.models.database import Product, ProductCategory, ProductDiscount, ProductImage, Category, StockRecord
from src.users.models.database import User, UserAddress
from src.company.models.database import Company

postgres_url = os.getenv('POSTGRES__URL')


# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config

from sqlmodel import SQLModel
from src.catalogue.models.database import *
# Interpret the config file for Python logging.
# This line sets up loggers basically.
if config.config_file_name is not None:
Expand All @@ -29,13 +19,8 @@
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
target_metadata = SQLModel.metadata


def include_object(object, name, type_, reflected, compare_to):
if type_ == "table":
return object.name in target_metadata.tables
return True
target_metadata = SQLModel.metadata

# other values from the config, defined by the needs of env.py,
# can be acquired:
Expand All @@ -55,7 +40,7 @@ def run_migrations_offline() -> None:
script output.

"""
url = config.get_main_option("sqlalchemy.url", postgres_url)
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url,
target_metadata=target_metadata,
Expand All @@ -67,37 +52,26 @@ def run_migrations_offline() -> None:
context.run_migrations()


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

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

def run_migrations_online() -> None:
"""Run migrations in 'online' mode.

async def run_async_migrations() -> None:
"""In this scenario we need to create an Engine
In this scenario we need to create an Engine
and associate a connection with the context.
"""

config_section = config.get_section(config.config_ini_section)
config_section['sqlalchemy.url'] = postgres_url

connectable = async_engine_from_config(
config_section,
"""
connectable = engine_from_config(
config.get_section(config.config_ini_section, {}),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)

async with connectable.connect() as connection:
await connection.run_sync(do_run_migrations)

await connectable.dispose()


def run_migrations_online() -> None:
"""Run migrations in 'online' mode."""
with connectable.connect() as connection:
context.configure(
connection=connection, target_metadata=target_metadata
)

asyncio.run(run_async_migrations())
with context.begin_transaction():
context.run_migrations()


if context.is_offline_mode():
Expand Down
1 change: 0 additions & 1 deletion migrations/script.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
import sqlmodel
${imports if imports else ""}

# revision identifiers, used by Alembic.
Expand Down
135 changes: 0 additions & 135 deletions migrations/versions/799909f2b79d_init.py

This file was deleted.

Loading