init
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
# venv
|
||||
.venv/
|
||||
__pycache__/
|
||||
|
||||
# python
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# env
|
||||
.env
|
||||
.flaskenv
|
||||
|
||||
#db
|
||||
instance/
|
||||
@@ -0,0 +1,5 @@
|
||||
from flask import Flask
|
||||
from settings import app, db
|
||||
|
||||
|
||||
from routes.routes import *
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
"""Auth."""
|
||||
|
||||
from flask_httpauth import HTTPBasicAuth, HTTPTokenAuth
|
||||
from models.user import User
|
||||
from errors import error_response
|
||||
|
||||
basic_auth = HTTPBasicAuth()
|
||||
token_auth = HTTPTokenAuth()
|
||||
|
||||
|
||||
@basic_auth.verify_password
|
||||
def verify_password(email, password):
|
||||
"""Verify password."""
|
||||
user = User.query.filter_by(email=email).first()
|
||||
if user and user.check_password(password):
|
||||
return user
|
||||
|
||||
|
||||
@basic_auth.error_handler
|
||||
def basic_auth_error(status):
|
||||
"""Basic auth error."""
|
||||
return error_response(status)
|
||||
|
||||
|
||||
@token_auth.verify_token
|
||||
def verify_token(token):
|
||||
"""Verify token."""
|
||||
return User.check_token(token) if token else None
|
||||
|
||||
|
||||
@token_auth.error_handler
|
||||
def token_auth_error(status):
|
||||
"""Token auth error."""
|
||||
return error_response(status)
|
||||
@@ -0,0 +1,112 @@
|
||||
strategy_dicts = [
|
||||
{
|
||||
"name": "Brets Low Roller",
|
||||
"initial_bets": [
|
||||
{"name": "Dozen", "value": 1, "stake": 1},
|
||||
{"name": "Dozen", "value": 2, "stake": 1},
|
||||
],
|
||||
"actions": [
|
||||
{
|
||||
"requirements": [
|
||||
{
|
||||
"conditions": [
|
||||
{"name": "milestone_passed", "invert": False},
|
||||
{"name": "at_milestone", "invert": False},
|
||||
],
|
||||
"operator": "or",
|
||||
}
|
||||
],
|
||||
"updates": [{"name": "reset_bet"}, {"name": "inc_milestone"}],
|
||||
"stage": "on_win",
|
||||
},
|
||||
{
|
||||
"requirements": [
|
||||
{
|
||||
"conditions": [
|
||||
{"name": "lost_since_reset", "invert": True},
|
||||
]
|
||||
}
|
||||
],
|
||||
"updates": [{"name": "inc_bet"}],
|
||||
"stage": "on_loss",
|
||||
},
|
||||
{
|
||||
"requirements": [
|
||||
{
|
||||
"conditions": [
|
||||
{"name": "lost_since_reset", "invert": False},
|
||||
]
|
||||
}
|
||||
],
|
||||
"updates": [{"name": "inc_bet"}],
|
||||
"stage": "on_spin",
|
||||
},
|
||||
{
|
||||
"requirements": [
|
||||
{
|
||||
"conditions": [
|
||||
{"name": "min_time_reached", "invert": False},
|
||||
{"name": "at_milestone", "invert": False},
|
||||
],
|
||||
}
|
||||
],
|
||||
"updates": [],
|
||||
"stage": "end_requirements",
|
||||
},
|
||||
],
|
||||
"stake_ratio": 200,
|
||||
"milestone_perc": 5,
|
||||
},
|
||||
{
|
||||
"name": "Second Dozen Second Column",
|
||||
"initial_bets": [
|
||||
{"name": "Column", "value": 2, "stake": 1},
|
||||
{"name": "Dozen", "value": 2, "stake": 1},
|
||||
],
|
||||
"actions": [
|
||||
{
|
||||
"requirements": [
|
||||
{
|
||||
"conditions": [
|
||||
{"name": "session_profit", "invert": False}
|
||||
],
|
||||
}
|
||||
],
|
||||
"updates": [{"name": "reset_bet"}],
|
||||
"stage": "on_win",
|
||||
},
|
||||
{
|
||||
"requirements": [],
|
||||
"updates": [{"name": "inc_bet"}],
|
||||
"stage": "on_loss",
|
||||
},
|
||||
],
|
||||
"stake_ratio": 200,
|
||||
},
|
||||
{
|
||||
"name": "Holy Grail",
|
||||
"initial_bets": [
|
||||
{"name": "Dozen", "value": 1, "stake": 1},
|
||||
{"name": "Dozen", "value": 2, "stake": 1},
|
||||
],
|
||||
"actions": [
|
||||
{
|
||||
"requirements": [
|
||||
{
|
||||
"conditions": [
|
||||
{"name": "session_profit", "invert": False}
|
||||
],
|
||||
}
|
||||
],
|
||||
"updates": [{"name": "reset_bet"}],
|
||||
"stage": "on_win",
|
||||
},
|
||||
{
|
||||
"requirements": [],
|
||||
"updates": [{"name": "inc_bet"}],
|
||||
"stage": "on_loss",
|
||||
},
|
||||
],
|
||||
"stake_ratio": 200,
|
||||
},
|
||||
]
|
||||
@@ -0,0 +1,6 @@
|
||||
Flask
|
||||
flask-Migrate
|
||||
flask-sqlalchemy
|
||||
sqlalchemy_serializer
|
||||
python-dotenv
|
||||
flask_httpauth
|
||||
@@ -0,0 +1,18 @@
|
||||
"""Response errors."""
|
||||
from flask import jsonify
|
||||
from werkzeug.http import HTTP_STATUS_CODES
|
||||
|
||||
|
||||
def error_response(status_code, message=None):
|
||||
"""Error response."""
|
||||
payload = {"error": HTTP_STATUS_CODES.get(status_code, "Unknown error")}
|
||||
if message:
|
||||
payload["message"] = message
|
||||
response = jsonify(payload)
|
||||
response.status_code = status_code
|
||||
return response
|
||||
|
||||
|
||||
def bad_request(message):
|
||||
"""Bad request."""
|
||||
return error_response(400, message)
|
||||
@@ -0,0 +1,16 @@
|
||||
from settings import app, db
|
||||
from models.user import User
|
||||
|
||||
|
||||
def import_user():
|
||||
user = User(
|
||||
email="rob@test.com",
|
||||
username="rob",
|
||||
password_hash="pbkdf2:sha256:260000$ox0WH3KrvKXBNT1C$48624cc8b59a7ca1d510f12410b8c7e4c4a61f9e1b488f980f1ca352c86eee5b", # noqa E501
|
||||
)
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
with app.app_context():
|
||||
import_user()
|
||||
@@ -0,0 +1 @@
|
||||
Single-database configuration for Flask.
|
||||
@@ -0,0 +1,50 @@
|
||||
# A generic, single database configuration.
|
||||
|
||||
[alembic]
|
||||
# template used to generate migration files
|
||||
# file_template = %%(rev)s_%%(slug)s
|
||||
|
||||
# set to 'true' to run the environment during
|
||||
# the 'revision' command, regardless of autogenerate
|
||||
# revision_environment = false
|
||||
|
||||
|
||||
# Logging configuration
|
||||
[loggers]
|
||||
keys = root,sqlalchemy,alembic,flask_migrate
|
||||
|
||||
[handlers]
|
||||
keys = console
|
||||
|
||||
[formatters]
|
||||
keys = generic
|
||||
|
||||
[logger_root]
|
||||
level = WARN
|
||||
handlers = console
|
||||
qualname =
|
||||
|
||||
[logger_sqlalchemy]
|
||||
level = WARN
|
||||
handlers =
|
||||
qualname = sqlalchemy.engine
|
||||
|
||||
[logger_alembic]
|
||||
level = INFO
|
||||
handlers =
|
||||
qualname = alembic
|
||||
|
||||
[logger_flask_migrate]
|
||||
level = INFO
|
||||
handlers =
|
||||
qualname = flask_migrate
|
||||
|
||||
[handler_console]
|
||||
class = StreamHandler
|
||||
args = (sys.stderr,)
|
||||
level = NOTSET
|
||||
formatter = generic
|
||||
|
||||
[formatter_generic]
|
||||
format = %(levelname)-5.5s [%(name)s] %(message)s
|
||||
datefmt = %H:%M:%S
|
||||
@@ -0,0 +1,113 @@
|
||||
import logging
|
||||
from logging.config import fileConfig
|
||||
|
||||
from flask import current_app
|
||||
|
||||
from alembic import context
|
||||
|
||||
# this is the Alembic Config object, which provides
|
||||
# access to the values within the .ini file in use.
|
||||
config = context.config
|
||||
|
||||
# Interpret the config file for Python logging.
|
||||
# This line sets up loggers basically.
|
||||
fileConfig(config.config_file_name)
|
||||
logger = logging.getLogger('alembic.env')
|
||||
|
||||
|
||||
def get_engine():
|
||||
try:
|
||||
# this works with Flask-SQLAlchemy<3 and Alchemical
|
||||
return current_app.extensions['migrate'].db.get_engine()
|
||||
except (TypeError, AttributeError):
|
||||
# this works with Flask-SQLAlchemy>=3
|
||||
return current_app.extensions['migrate'].db.engine
|
||||
|
||||
|
||||
def get_engine_url():
|
||||
try:
|
||||
return get_engine().url.render_as_string(hide_password=False).replace(
|
||||
'%', '%%')
|
||||
except AttributeError:
|
||||
return str(get_engine().url).replace('%', '%%')
|
||||
|
||||
|
||||
# add your model's MetaData object here
|
||||
# for 'autogenerate' support
|
||||
# from myapp import mymodel
|
||||
# target_metadata = mymodel.Base.metadata
|
||||
config.set_main_option('sqlalchemy.url', get_engine_url())
|
||||
target_db = current_app.extensions['migrate'].db
|
||||
|
||||
# other values from the config, defined by the needs of env.py,
|
||||
# can be acquired:
|
||||
# my_important_option = config.get_main_option("my_important_option")
|
||||
# ... etc.
|
||||
|
||||
|
||||
def get_metadata():
|
||||
if hasattr(target_db, 'metadatas'):
|
||||
return target_db.metadatas[None]
|
||||
return target_db.metadata
|
||||
|
||||
|
||||
def run_migrations_offline():
|
||||
"""Run migrations in 'offline' mode.
|
||||
|
||||
This configures the context with just a URL
|
||||
and not an Engine, though an Engine is acceptable
|
||||
here as well. By skipping the Engine creation
|
||||
we don't even need a DBAPI to be available.
|
||||
|
||||
Calls to context.execute() here emit the given string to the
|
||||
script output.
|
||||
|
||||
"""
|
||||
url = config.get_main_option("sqlalchemy.url")
|
||||
context.configure(
|
||||
url=url, target_metadata=get_metadata(), literal_binds=True
|
||||
)
|
||||
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
def run_migrations_online():
|
||||
"""Run migrations in 'online' mode.
|
||||
|
||||
In this scenario we need to create an Engine
|
||||
and associate a connection with the context.
|
||||
|
||||
"""
|
||||
|
||||
# this callback is used to prevent an auto-migration from being generated
|
||||
# when there are no changes to the schema
|
||||
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
|
||||
def process_revision_directives(context, revision, directives):
|
||||
if getattr(config.cmd_opts, 'autogenerate', False):
|
||||
script = directives[0]
|
||||
if script.upgrade_ops.is_empty():
|
||||
directives[:] = []
|
||||
logger.info('No changes in schema detected.')
|
||||
|
||||
conf_args = current_app.extensions['migrate'].configure_args
|
||||
if conf_args.get("process_revision_directives") is None:
|
||||
conf_args["process_revision_directives"] = process_revision_directives
|
||||
|
||||
connectable = get_engine()
|
||||
|
||||
with connectable.connect() as connection:
|
||||
context.configure(
|
||||
connection=connection,
|
||||
target_metadata=get_metadata(),
|
||||
**conf_args
|
||||
)
|
||||
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
if context.is_offline_mode():
|
||||
run_migrations_offline()
|
||||
else:
|
||||
run_migrations_online()
|
||||
@@ -0,0 +1,24 @@
|
||||
"""${message}
|
||||
|
||||
Revision ID: ${up_revision}
|
||||
Revises: ${down_revision | comma,n}
|
||||
Create Date: ${create_date}
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
${imports if imports else ""}
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = ${repr(up_revision)}
|
||||
down_revision = ${repr(down_revision)}
|
||||
branch_labels = ${repr(branch_labels)}
|
||||
depends_on = ${repr(depends_on)}
|
||||
|
||||
|
||||
def upgrade():
|
||||
${upgrades if upgrades else "pass"}
|
||||
|
||||
|
||||
def downgrade():
|
||||
${downgrades if downgrades else "pass"}
|
||||
@@ -0,0 +1,55 @@
|
||||
"""user table
|
||||
|
||||
Revision ID: 70b40a0d8417
|
||||
Revises:
|
||||
Create Date: 2024-08-28 13:35:01.725865
|
||||
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "70b40a0d8417"
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.create_table(
|
||||
"user",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("email", sa.String(length=80), nullable=True),
|
||||
sa.Column("username", sa.String(length=100), nullable=True),
|
||||
sa.Column("password_hash", sa.String(length=255), nullable=True),
|
||||
sa.Column("token", sa.String(length=32), nullable=True),
|
||||
sa.Column("token_expiration", sa.DateTime(), nullable=True),
|
||||
sa.Column("refresh_token", sa.String(length=32), nullable=True),
|
||||
sa.Column("reset_password_code", sa.String(length=8), nullable=True),
|
||||
sa.Column("reset_password_expiration", sa.DateTime(), nullable=True),
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("pk_user")),
|
||||
sa.UniqueConstraint("email", name=op.f("uq_user_email")),
|
||||
)
|
||||
with op.batch_alter_table("user", schema=None) as batch_op:
|
||||
batch_op.create_index(
|
||||
batch_op.f("ix_user_refresh_token"), ["refresh_token"], unique=True
|
||||
)
|
||||
batch_op.create_index(
|
||||
batch_op.f("ix_user_reset_password_code"),
|
||||
["reset_password_code"],
|
||||
unique=True,
|
||||
)
|
||||
batch_op.create_index(
|
||||
batch_op.f("ix_user_token"), ["token"], unique=True
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
with op.batch_alter_table("user", schema=None) as batch_op:
|
||||
batch_op.drop_index(batch_op.f("ix_user_token"))
|
||||
batch_op.drop_index(batch_op.f("ix_user_reset_password_code"))
|
||||
batch_op.drop_index(batch_op.f("ix_user_refresh_token"))
|
||||
|
||||
op.drop_table("user")
|
||||
@@ -0,0 +1,14 @@
|
||||
from sqlalchemy.orm import DeclarativeBase
|
||||
from sqlalchemy import MetaData
|
||||
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
__abstract__ = True
|
||||
naming_convention = {
|
||||
"ix": "ix_%(column_0_label)s",
|
||||
"uq": "uq_%(table_name)s_%(column_0_name)s",
|
||||
"ck": "ck_%(table_name)s_%(constraint_name)s",
|
||||
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
|
||||
"pk": "pk_%(table_name)s",
|
||||
}
|
||||
metadata = MetaData(naming_convention=naming_convention)
|
||||
@@ -0,0 +1,77 @@
|
||||
from sqlalchemy_serializer import SerializerMixin
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
from settings import db
|
||||
import base64
|
||||
from datetime import datetime, timedelta
|
||||
import os
|
||||
|
||||
|
||||
class User(db.Model, SerializerMixin):
|
||||
__tablename__ = "user"
|
||||
serialize_only = ("id", "username")
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
email = db.Column(db.String(80), unique=True)
|
||||
username = db.Column(db.String(100))
|
||||
password_hash = db.Column(db.String(255))
|
||||
token = db.Column(db.String(32), index=True, unique=True)
|
||||
token_expiration = db.Column(db.DateTime)
|
||||
refresh_token = db.Column(db.String(32), index=True, unique=True)
|
||||
reset_password_code = db.Column(db.String(8), index=True, unique=True)
|
||||
reset_password_expiration = db.Column(db.DateTime)
|
||||
|
||||
def set_password(self, password):
|
||||
self.password_hash = generate_password_hash(password)
|
||||
|
||||
def check_password(self, password):
|
||||
return check_password_hash(self.password_hash, password)
|
||||
|
||||
def __repr__(self):
|
||||
return "<User {}, {}>".format(self.id, self.username)
|
||||
|
||||
def get_token(self, expires_in=3600):
|
||||
now = datetime.utcnow()
|
||||
if self.token and self.token_expiration > now + timedelta(seconds=60):
|
||||
return self.token
|
||||
self.token = base64.b64encode(os.urandom(24)).decode("utf-8")
|
||||
self.token_expiration = now + timedelta(seconds=expires_in)
|
||||
db.session.add(self)
|
||||
return self.token
|
||||
|
||||
def get_refresh_token(self):
|
||||
if self.refresh_token:
|
||||
return self.refresh_token
|
||||
self.refresh_token = base64.b64encode(os.urandom(24)).decode("utf-8")
|
||||
db.session.add(self)
|
||||
return self.refresh_token
|
||||
|
||||
def revoke_tokens(self):
|
||||
self.token_expiration = datetime.utcnow() - timedelta(seconds=1)
|
||||
self.refresh_token = None
|
||||
|
||||
def get_reset_code(self, expires_in=300):
|
||||
now = datetime.utcnow()
|
||||
if (
|
||||
self.reset_password_code
|
||||
and self.reset_password_expiration > now + timedelta(seconds=60)
|
||||
):
|
||||
return self.reset_password_code
|
||||
self.reset_password_code = base64.b64encode(os.urandom(8)).decode(
|
||||
"utf-8"
|
||||
)[:8]
|
||||
self.reset_password_expiration = now + timedelta(seconds=expires_in)
|
||||
db.session.add(self)
|
||||
return self.reset_password_code
|
||||
|
||||
@staticmethod
|
||||
def check_token(token):
|
||||
user = User.query.filter_by(token=token).first()
|
||||
if user is None or user.token_expiration < datetime.utcnow():
|
||||
return None
|
||||
return user
|
||||
|
||||
@staticmethod
|
||||
def check_reset_code(reset_code):
|
||||
user = User.query.filter_by(reset_password_code=reset_code).first()
|
||||
if user is None or user.reset_password_expiration < datetime.utcnow():
|
||||
return None
|
||||
return user
|
||||
@@ -0,0 +1 @@
|
||||
auth_routes.py
|
||||
@@ -0,0 +1,4 @@
|
||||
from settings import app
|
||||
|
||||
from routes.token_routes import *
|
||||
from routes.user_routes import *
|
||||
@@ -0,0 +1,56 @@
|
||||
"""Token routes."""
|
||||
|
||||
from flask import jsonify, make_response, request
|
||||
from settings import db, app
|
||||
from auth import token_auth, basic_auth
|
||||
from models.user import User
|
||||
from errors import error_response
|
||||
|
||||
# todo - put in basic_auth
|
||||
basic_auth.scheme = "Custom"
|
||||
basic_auth.realm = "Incorrect Credentials"
|
||||
|
||||
|
||||
@app.route("/api/auth/token", methods=["POST"])
|
||||
@basic_auth.login_required
|
||||
def get_token():
|
||||
"""Get token."""
|
||||
token = basic_auth.current_user().get_token()
|
||||
refresh_token = basic_auth.current_user().get_refresh_token()
|
||||
db.session.commit()
|
||||
response = make_response(
|
||||
jsonify(
|
||||
{
|
||||
"token": token,
|
||||
"username": basic_auth.current_user().username,
|
||||
"user_id": basic_auth.current_user().id,
|
||||
}
|
||||
)
|
||||
)
|
||||
response.set_cookie("refresh_token", value=refresh_token, httponly=True)
|
||||
return response
|
||||
|
||||
|
||||
@app.route("/api/auth/tokens", methods=["DELETE"])
|
||||
@token_auth.login_required
|
||||
def revoke_token():
|
||||
"""Revoke token."""
|
||||
token_auth.current_user().revoke_tokens()
|
||||
db.session.commit()
|
||||
return {"success": True}
|
||||
|
||||
|
||||
@app.route("/api/auth/refresh", methods=["GET"])
|
||||
def refresh_token():
|
||||
"""Refresh token."""
|
||||
refresh_token = request.cookies.get("refresh_token")
|
||||
if refresh_token is None:
|
||||
return error_response(400, "Bad request, no refresh token")
|
||||
user = User.query.filter_by(refresh_token=refresh_token).first()
|
||||
if user is not None:
|
||||
access_token = user.get_token()
|
||||
db.session.commit()
|
||||
return {
|
||||
"token": access_token,
|
||||
"user_id": user.id,
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
"""User routes."""
|
||||
|
||||
from settings import app, db
|
||||
from flask import request
|
||||
from models.user import User
|
||||
from errors import error_response
|
||||
import os
|
||||
|
||||
# from flask_mail import Message
|
||||
|
||||
|
||||
@app.route("/api/user/register", methods=["POST"])
|
||||
def register_user():
|
||||
"""Register user."""
|
||||
req = request.get_json()
|
||||
user = User.query.filter_by(email=req["email"]).first()
|
||||
if user is None:
|
||||
user = User(username=req["username"], email=req["email"])
|
||||
user.set_password(req["password"])
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
return {"success": True}
|
||||
else:
|
||||
return error_response(409, "Email exists")
|
||||
|
||||
|
||||
# @app.route("/api/user/reset-password", methods=["POST"])
|
||||
# def reset_password():
|
||||
# """Reset password."""
|
||||
# email = request.get_json()["email"]
|
||||
# user = User.query.filter_by(email=email).first()
|
||||
# if user is None:
|
||||
# return error_response(400, "Email not found")
|
||||
# else:
|
||||
# reset_code = user.get_reset_code()
|
||||
# db.session.commit()
|
||||
# sender = os.environ.get("MAIL_USERNAME")
|
||||
# msg = Message(
|
||||
# "PitchInvader password reset code",
|
||||
# sender=sender,
|
||||
# recipients=[email],
|
||||
# )
|
||||
# msg.body = (
|
||||
# "Please enter the following reset code when prompted. {}".format(
|
||||
# reset_code
|
||||
# )
|
||||
# )
|
||||
# msg.html = "<p>{}</p>".filesat(msg.body)
|
||||
# # mail.send(msg)
|
||||
# return {"success": True}
|
||||
|
||||
|
||||
# @app.route("/api/user/update-password", methods=["POST"])
|
||||
# def update_password():
|
||||
# """Update password."""
|
||||
# req = request.get_json()
|
||||
# if "reset_code" not in req.keys() or req["reset_code"] is None:
|
||||
# return error_response(400, "Bad request")
|
||||
# user = User.check_reset_code(req["reset_code"])
|
||||
# if user is None:
|
||||
# return error_response(400, "Bad request")
|
||||
# else:
|
||||
# user.set_password(req["password"])
|
||||
# db.session.add(user)
|
||||
# db.session.commit()
|
||||
# return {"success": True}
|
||||
@@ -0,0 +1,23 @@
|
||||
from flask import Flask
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_migrate import Migrate
|
||||
from dotenv import load_dotenv
|
||||
from models.base import Base
|
||||
import os
|
||||
|
||||
load_dotenv()
|
||||
|
||||
app = Flask(__name__, static_folder="static")
|
||||
app.config.update(
|
||||
{
|
||||
"DEBUG": bool(os.environ.get("DEBUG") == "True"),
|
||||
"SQLALCHEMY_DATABASE_URI": "sqlite:///database.sqlite",
|
||||
"SQLALCHEMY_ECHO": bool(os.environ.get("SQLALCHEMY_ECHO") == "True"),
|
||||
"SQLALCHEMY_TRACK_MODIFICATIONS": bool(
|
||||
os.environ.get("SQLALCHEMY_TRACK_MODIFICATIONS") == "True"
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
db = SQLAlchemy(app, model_class=Base)
|
||||
migrate = Migrate(app, db, render_as_batch=True)
|
||||
Reference in New Issue
Block a user