Compare commits

..

5 Commits

6 changed files with 107 additions and 44 deletions

View File

@ -4,6 +4,7 @@ from sqlalchemy.orm import sessionmaker
from constants import TESTING_DB as DB 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) SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base() Base = declarative_base()
Base.metadata.create_all(bind=engine)

View File

@ -1,24 +0,0 @@
"""remove test users
Revision ID: c93f3cf71005
Revises: e443e876bf33
Create Date: 2021-02-10 00:41:48.290699
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = "c93f3cf71005"
down_revision = "e443e876bf33"
branch_labels = None
depends_on = None
def upgrade():
query = "DELETE FROM users WHERE email LIKE '%techugo%'"
op.execute(query)
def downgrade():
pass

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; with pkgs;
mkShell { let
buildInputs = [ sql_file = "assets/db_creation.sql";
# Dependencies data_dir = "$(pwd)/.pgdata";
python38Packages.fastapi
python38Packages.uvicorn in mkShell {
python38Packages.pydantic buildInputs = [ python38 poetry postgresql ];
python38Packages.email_validator
python38Packages.sqlalchemy shellHook = ''
python38Packages.alembic trap "kill 0" EXIT
python38Packages.pytest export PGDATA="${data_dir}"
python38Packages.twilio export PGHOST="${data_dir}"
python38Packages.passlib
python38Packages.bcrypt if [ ! -d ${data_dir} ]; then
sqlite initdb --auth-local=trust --no-locale --encoding=UTF8
# Development tools fi
python38Packages.isort
python38Packages.pyflakes 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 app import app
from constants import TESTING_DB 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) TestingSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
client = TestClient(app) client = TestClient(app)