Compare commits

...

5 Commits

5 changed files with 107 additions and 20 deletions

View File

@ -4,6 +4,7 @@ from sqlalchemy.orm import sessionmaker
from constants import TESTING_DB as DB
engine = create_engine(DB, connect_args={"check_same_thread": False})
engine = create_engine(DB)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
Base.metadata.create_all(bind=engine)

View File

@ -0,0 +1,52 @@
"""resolve foreign key conflicts
Revision ID: f6ec7393c858
Revises: e35936e392dd
Create Date: 2021-02-10 17:31:22.145457
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = "f6ec7393c858"
down_revision = "e443e876bf33"
branch_labels = None
depends_on = None
def upgrade():
foreign_keys = {
"users": "city_id",
"games": "sports_id",
"venues": "user_id",
"venue_images": "user_id",
}
for table, field in foreign_keys.items():
if table == "venues" or table == "venue_images":
query = f"UPDATE {table} SET {field} = 1976 WHERE {field} = 0"
else:
query = f"UPDATE {table} SET {field} = 1 WHERE {field} = 0"
op.execute(query)
game_id_tables = [
"player_availabilities",
"teams",
"user_ratings",
"purchase_games",
"payments",
"player_cancel_games",
]
venue_id_tables = [
"venue_images",
"games",
]
for table in game_id_tables:
query = f"DELETE FROM {table} WHERE game_id NOT IN (SELECT id from games)"
op.execute(query)
for table in venue_id_tables:
query = f"DELETE FROM {table} WHERE venue_id NOT IN (SELECT id from venues)"
op.execute(query)
def downgrade():
pass

28
pyproject.toml Normal file
View File

@ -0,0 +1,28 @@
[tool.poetry]
name = "odapi"
version = "0.1.0"
description = "Odyfo RESTful API"
authors = ["coolneng <akasroua@gmail.com>"]
license = "GPL-3.0-or-later"
[tool.poetry.dependencies]
python = "^3.8"
fastapi = "^0.63.0"
uvicorn = "^0.13.3"
pydantic = "^1.7.3"
email-validator = "^1.1.2"
SQLAlchemy = "^1.3.23"
alembic = "^1.5.4"
twilio = "^6.51.1"
passlib = "^1.7.4"
bcrypt = "^3.2.0"
psycopg2 = "^2.8.6"
[tool.poetry.dev-dependencies]
pytest = "^6.2.2"
isort = "^5.7.0"
pyflakes = "^2.2.0"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

View File

@ -2,22 +2,28 @@
with pkgs;
mkShell {
buildInputs = [
# Dependencies
python38Packages.fastapi
python38Packages.uvicorn
python38Packages.pydantic
python38Packages.email_validator
python38Packages.sqlalchemy
python38Packages.alembic
python38Packages.pytest
python38Packages.twilio
python38Packages.passlib
python38Packages.bcrypt
sqlite
# Development tools
python38Packages.isort
python38Packages.pyflakes
];
let
sql_file = "assets/db_creation.sql";
data_dir = "$(pwd)/.pgdata";
in mkShell {
buildInputs = [ python38 poetry postgresql ];
shellHook = ''
trap "kill 0" EXIT
export PGDATA="${data_dir}"
export PGHOST="${data_dir}"
if [ ! -d ${data_dir} ]; then
initdb --auth-local=trust --no-locale --encoding=UTF8
fi
if ! pg_ctl status; then
pg_ctl start -o "--unix_socket_directories=${data_dir} --listen_addresses='''"
fi
alias psql='psql -d postgres'
alias create_db='psql -d postgres -f ${sql_file}'
alias nuke='rm -rf ${data_dir}'
'';
}

View File

@ -5,6 +5,6 @@ from sqlalchemy.orm import sessionmaker
from app import app
from constants import TESTING_DB
engine = create_engine(TESTING_DB, connect_args={"check_same_thread": False})
engine = create_engine(TESTING_DB)
TestingSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
client = TestClient(app)