Database memes
This commit is contained in:
parent
e25c28b04c
commit
6eb2fe1879
@ -10,4 +10,7 @@ flask-sqlalchemy
|
|||||||
flask-cors
|
flask-cors
|
||||||
requests
|
requests
|
||||||
psycopg2-binary
|
psycopg2-binary
|
||||||
email_validator
|
email_validator
|
||||||
|
minio
|
||||||
|
flask-minio
|
||||||
|
bleach
|
10
src/app.py
10
src/app.py
@ -7,11 +7,12 @@ from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration
|
|||||||
from healthcheck import HealthCheck
|
from healthcheck import HealthCheck
|
||||||
from flask_cors import CORS
|
from flask_cors import CORS
|
||||||
|
|
||||||
from utils.config import SENTRY_DSN, RELEASE_ID, RELEASEMODE, POSTGRES_DB, PORT, POSTGRES_HOSTNAME, POSTGRES_PASSWORD, \
|
from utils.config import SENTRY_DSN, RELEASE_ID, RELEASEMODE, PORT, DEBUG, SECRET_KEY, ALLOWED_ORIGINS, SQLALCHEMY_URI
|
||||||
POSTGRES_USERNAME, DEBUG, SECRET_KEY, ALLOWED_ORIGINS
|
from utils import health_database_status, security, user_datastore
|
||||||
from utils import db, health_database_status, security, user_datastore
|
|
||||||
from views import ItemView, ProfileView, UploadView, IndexView
|
from views import ItemView, ProfileView, UploadView, IndexView
|
||||||
|
|
||||||
|
from models import db
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Main Flask entrypoint
|
Main Flask entrypoint
|
||||||
"""
|
"""
|
||||||
@ -33,8 +34,7 @@ if SENTRY_DSN:
|
|||||||
)
|
)
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config['SQLALCHEMY_DATABASE_URI'] = \
|
app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_URI
|
||||||
f"postgresql://{POSTGRES_USERNAME}:{POSTGRES_PASSWORD}@{POSTGRES_HOSTNAME}:5432/{POSTGRES_DB}"
|
|
||||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||||
app.config['SECRET_KEY'] = SECRET_KEY
|
app.config['SECRET_KEY'] = SECRET_KEY
|
||||||
app.config['SECURITY_REGISTERABLE'] = True
|
app.config['SECURITY_REGISTERABLE'] = True
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from .db import db
|
||||||
from .user import User
|
from .user import User
|
||||||
from .role import Role
|
from .role import Role
|
||||||
from .item import Item
|
from .item import Item
|
||||||
|
17
src/models/comment.py
Normal file
17
src/models/comment.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
from sqlalchemy import func
|
||||||
|
|
||||||
|
from . import db
|
||||||
|
|
||||||
|
|
||||||
|
class Comment(db.Model):
|
||||||
|
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||||
|
timestamp = db.Column(db.TIMESTAMP, nullable=False, server_default=func.now())
|
||||||
|
|
||||||
|
commenter_id = db.Column(db.Integer, db.ForeignKey("user.id", ondelete="CASCADE"), nullable=False)
|
||||||
|
commenter = db.relationship("User", backref=db.backref("comments", lazy=True))
|
||||||
|
|
||||||
|
item_id = db.Column(db.Integer, db.ForeignKey("item.id", ondelete="CASCADE"), nullable=False)
|
||||||
|
item = db.relationship("Item", backref=db.backref("comments", lazy=True))
|
||||||
|
|
||||||
|
text = db.Text(4096, nullable=False)
|
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from sqlalchemy import func
|
from sqlalchemy import func
|
||||||
|
|
||||||
from utils import db
|
from . import db
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Item model
|
Item model
|
||||||
@ -16,4 +16,7 @@ __version__text__ = "1"
|
|||||||
class Item(db.Model):
|
class Item(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||||
name = db.Column(db.String, nullable=False)
|
name = db.Column(db.String, nullable=False)
|
||||||
creation_date = db.Column(db.TIMESTAMP, nullable=False, server_default=func.now())
|
upload_date = db.Column(db.TIMESTAMP, nullable=False, server_default=func.now())
|
||||||
|
|
||||||
|
uploader_id = db.Column(db.Integer, db.ForeignKey("user.id", ondelete="CASCADE"), nullable=False)
|
||||||
|
uploader = db.relationship("User", backref=db.backref("uploads", lazy=True))
|
15
src/models/purchase.py
Normal file
15
src/models/purchase.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
from sqlalchemy import func
|
||||||
|
|
||||||
|
from . import db
|
||||||
|
|
||||||
|
|
||||||
|
class Purchase(db.Model):
|
||||||
|
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||||
|
timestamp = db.Column(db.TIMESTAMP, nullable=False, server_default=func.now())
|
||||||
|
|
||||||
|
purchaser_id = db.Column(db.Integer, db.ForeignKey("user.id", ondelete="CASCADE"), nullable=False)
|
||||||
|
purchaser = db.relationship("User", backref=db.backref("purchases", lazy=True))
|
||||||
|
|
||||||
|
item_id = db.Column(db.Integer, db.ForeignKey("item.id", ondelete="CASCADE"), nullable=False)
|
||||||
|
item = db.relationship("Item", backref=db.backref("purchases", lazy=True))
|
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from flask_security import RoleMixin
|
from flask_security import RoleMixin
|
||||||
|
|
||||||
from utils import db
|
from . import db
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Role model
|
Role model
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
from flask_security import UserMixin
|
from flask_security import UserMixin
|
||||||
|
|
||||||
from .role import roles_users
|
from .role import roles_users
|
||||||
from utils import db
|
from . import db
|
||||||
|
|
||||||
"""
|
"""
|
||||||
User model
|
User model
|
||||||
|
@ -1,3 +1,2 @@
|
|||||||
from .db import db
|
|
||||||
from .healthchecks import health_database_status
|
from .healthchecks import health_database_status
|
||||||
from .security import security, user_datastore
|
from .security import security, user_datastore
|
||||||
|
@ -19,10 +19,7 @@ SENTRY_DSN = os.environ.get("SENTRY_DSN")
|
|||||||
RELEASE_ID = os.environ.get("RELEASE_ID", "test")
|
RELEASE_ID = os.environ.get("RELEASE_ID", "test")
|
||||||
RELEASEMODE = os.environ.get("RELEASEMODE", "dev")
|
RELEASEMODE = os.environ.get("RELEASEMODE", "dev")
|
||||||
|
|
||||||
POSTGRES_HOSTNAME = os.getenv("POSTGRES_HOSTNAME", "localhost")
|
SQLALCHEMY_URI = os.environ.get("SQLALCHEMY_URI", "sqlite://")
|
||||||
POSTGRES_USERNAME = os.getenv("POSTGRES_USERNAME", "webshop")
|
|
||||||
POSTGRES_PASSWORD = os.getenv("POSTGRES_PASSWORD", "webshop")
|
|
||||||
POSTGRES_DB = os.getenv("POSTGRES_DB", "webshop")
|
|
||||||
|
|
||||||
SECRET_KEY = os.getenv("SECRET_KEY")
|
SECRET_KEY = os.getenv("SECRET_KEY")
|
||||||
ALLOWED_ORIGINS = os.environ.get('ALLOWED_ORIGINS', '*')
|
ALLOWED_ORIGINS = os.environ.get('ALLOWED_ORIGINS', '*')
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from .db import db
|
from models.db import db
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Healthchek functions
|
Healthchek functions
|
||||||
|
@ -11,8 +11,7 @@ __version__text__ = "1"
|
|||||||
|
|
||||||
from flask_security import Security, SQLAlchemyUserDatastore
|
from flask_security import Security, SQLAlchemyUserDatastore
|
||||||
|
|
||||||
from models import User, Role
|
from models import db, User, Role
|
||||||
from utils import db
|
|
||||||
|
|
||||||
user_datastore = SQLAlchemyUserDatastore(db, User, Role)
|
user_datastore = SQLAlchemyUserDatastore(db, User, Role)
|
||||||
security = Security()
|
security = Security()
|
||||||
|
Loading…
Reference in New Issue
Block a user