Migrate DB to sqlite

This commit is contained in:
coolneng 2020-07-03 02:03:02 +02:00
parent deda3b51b5
commit 1dd62e1ae0
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
6 changed files with 45 additions and 31 deletions

View File

@ -3,7 +3,7 @@ from fastapi import Response, status
from app import app
from app.schemas import *
from app.twilio import send_otp
from database.crud import insert_data, verify_login, verify_otp
from database.crud import insert_data, verify_otp
@app.post("/register", status_code=status.HTTP_200_OK)

View File

@ -1,12 +1,14 @@
from constants import CONNECTION_URI
from constants import DB
from sqlalchemy import MetaData, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from databases import Database
metadata = MetaData()
engine = create_engine(CONNECTION_URI)
engine = create_engine(DB)
metadata.create_all(engine)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
database = Database(CONNECTION_URI)
database = Database(DB)
from database import models

View File

@ -3,7 +3,6 @@ from datetime import datetime
from app import app
from app.schemas import *
from database import database
from werkzeug.security import check_password_hash
from pydoc import locate

View File

@ -1,9 +1,11 @@
from app import Base
from sqlalchemy import Column, Integer, String, DateTime, Text, Enum
from database import Base
from sqlalchemy import Column, Integer, String, DateTime, Text, Enum, text
from sqlalchemy.sql import func
class Users(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True, autoincrement=True)
social_id = Column(Text)
type = Column(Integer)
@ -20,8 +22,8 @@ class Users(Base):
access_key = Column(Text)
lang_type = Column(Integer)
badge = Column(Integer)
status = Column(Integer, server_default=Text("0"))
admin_status = Column(Integer, server_default=Text("0"))
status = Column(Integer, server_default=text("0"))
admin_status = Column(Integer, server_default=text("0"))
device_id = Column(Text)
device_type = Column(Integer)
created = Column(DateTime, nullable=False, server_default=func.now())
@ -62,6 +64,8 @@ class Users(Base):
class Cities(Base):
__tablename__ = "cities"
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String(255))
image = Column(String(255))
@ -78,6 +82,8 @@ class Cities(Base):
class Games(Base):
__tablename__ = "games"
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String(255))
image = Column(String(255))
@ -95,12 +101,12 @@ class Games(Base):
no_of_already_player = Column(Integer)
payment_mode = Column(Integer)
card_id = Column(Integer)
status = Column(Integer, server_default=Text("1"))
game_status = Column(Integer, server_default=Text("0"))
status = Column(Integer, server_default=text("1"))
game_status = Column(Integer, server_default=text("0"))
cancel_status = Column(Integer)
cancel_date = Column(DateTime)
noti_status = Column(Integer, server_default=Text("0"))
conduct_status = Column(Integer, server_default=Text("1"))
noti_status = Column(Integer, server_default=text("0"))
conduct_status = Column(Integer, server_default=text("1"))
created = Column(DateTime, nullable=False, server_default=func.now())
modified = Column(DateTime, nullable=False, onupdate=func.now())
@ -140,6 +146,8 @@ class Games(Base):
class Payments(Base):
__tablename__ = "payments"
id = Column(Integer, primary_key=True, autoincrement=True)
user_id = Column(Integer)
game_id = Column(Integer)
@ -183,6 +191,8 @@ class Payments(Base):
class PlayerAvailabilities(Base):
__tablename__ = "player_availabilities"
id = Column(Integer, primary_key=True, autoincrement=True)
game_id = Column(Integer)
player_id = Column(Integer)
@ -199,6 +209,8 @@ class PlayerAvailabilities(Base):
class PlayerCancelGames(Base):
__tablename__ = "player_cancel_games"
id = Column(Integer, primary_key=True, autoincrement=True)
player_id = Column(Integer)
game_id = Column(Integer)
@ -213,6 +225,8 @@ class PlayerCancelGames(Base):
class PurchaseGames(Base):
__tablename__ = "purchase_games"
id = Column(Integer, primary_key=True, autoincrement=True)
game_id = Column(Integer)
user_id = Column(Integer)
@ -229,6 +243,8 @@ class PurchaseGames(Base):
class Sports(Base):
__tablename__ = "sports"
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String(255))
spanish_name = Column(String(100))
@ -245,6 +261,8 @@ class Sports(Base):
class Teams(Base):
__tablename__ = "teams"
id = Column(Integer, primary_key=True, autoincrement=True)
user_id = Column(Integer)
team_id = Column(Enum("1", "2"))
@ -263,6 +281,8 @@ class Teams(Base):
class UserRatings(Base):
__tablename__ = "user_ratings"
id = Column(Integer, primary_key=True, autoincrement=True)
game_id = Column(Integer)
user_id = Column(Integer)
@ -281,6 +301,8 @@ class UserRatings(Base):
class VenueImages(Base):
__tablename__ = "venue_images"
id = Column(Integer, primary_key=True, autoincrement=True)
venue_id = Column(Integer)
user_id = Column(Integer)
@ -297,6 +319,8 @@ class VenueImages(Base):
class Venues(Base):
__tablename__ = "venues"
id = Column(Integer, primary_key=True, autoincrement=True)
user_id = Column(Integer)
address = Column(Text)
@ -319,6 +343,8 @@ class Venues(Base):
class ViewNews(Base):
__tablename__ = "view_news"
id = Column(Integer, primary_key=True, autoincrement=True)
news_id = Column(Integer)
user_id = Column(Integer)
@ -333,6 +359,8 @@ class ViewNews(Base):
class WebBookings(Base):
__tablename__ = "web_bookings"
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String(255))
email = Column(String(255))

View File

@ -10,29 +10,16 @@ mkShell {
python38Packages.pydantic
python38Packages.email_validator
python38Packages.sqlalchemy
python38Packages.pymysql
python38Packages.aiosqlite
python38Packages.databases
python38Packages.aiomysql
python38Packages.alembic
python38Packages.pytest
python38Packages.twilio
mysql57
sqlite
# Development tools
python38Packages.black
python38Packages.isort
python38Packages.pyflakes
python-language-server
];
shellHook = ''
pkill mysql
rm -rf .mysql && mkdir .mysql
mysqld --datadir="$(pwd)/.mysql" --socket="$(pwd)/.mysql/mysql.sock" --initialize-insecure
mysqld --datadir="$(pwd)/.mysql" --socket="$(pwd)/.mysql/mysql.sock" --skip-networking & sleep 1
mysql --socket="$(pwd)/.mysql/mysql.sock" -u root < $(pwd)/assets/test_db.sql
alias mysql='mysql --socket="$(pwd)/.mysql/mysql.sock" -u root'
'';
}

View File

@ -1,8 +1,6 @@
from app.models import *
from config import Config
from database.models import *
from pytest import fixture
from secrets import token_hex
from werkzeug.security import generate_password_hash
def test_registration(client):