Add Flask Migrate and update run.sh

This commit is contained in:
Michał Gdula 2023-05-15 22:44:03 +03:00
parent 77c0711a24
commit 36be8993df
8 changed files with 37 additions and 30 deletions

2
DV8-Expo/.gitignore vendored
View file

@ -159,5 +159,5 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
# remove development files
/data
/storage
/logs

View file

@ -1,19 +1,19 @@
#!/bin/sh
# # Check if migrastions folder exists
# if [ ! -d "/data/storage/migrations" ];
# then
# echo "Creating tables..."
# flask --app website db init
# fi
# Check if migrastions folder exists
if [ ! -d "/data/storage/migrations" ];
then
echo "Creating tables..."
flask --app website db init
fi
# # Check if there are any changes to the database
# if ! $(flask --app website db check | grep -q "No changes in schema detected.");
# then
# echo "Database changes detected! Migrating..."
# flask --app website db migrate
# flask --app website db upgrade
# fi
# Check if there are any changes to the database
if ! $(flask --app website db check | grep -q "No changes in schema detected.");
then
echo "Database changes detected! Migrating..."
flask --app website db migrate
flask --app website db upgrade
fi
# Start website!!!!
echo "Starting expo website..."

View file

@ -1,12 +1,13 @@
from flask import Flask, render_template
from flask_assets import Bundle
from website.extensions import db, assets
from website.config import INSTANCE_DIR
from website.extensions import db, migrate, assets
from website.config import INSTANCE_DIR, MIGRATION_DIR
app = Flask(__name__) # instance_path=INSTANCE_DIR
app = Flask(__name__, instance_path=INSTANCE_DIR)
app.config.from_pyfile('config.py')
db.init_app(app)
migrate.init_app(app, db, directory=MIGRATION_DIR)
with app.app_context():
db.create_all()

View file

@ -1,7 +1,9 @@
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_caching import Cache
from flask_assets import Environment
db = SQLAlchemy()
migrate = Migrate()
cache = Cache()
assets = Environment()

View file

@ -7,23 +7,27 @@ from website.extensions import db
class Games(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String, nullable=False)
ageRating = db.Column(db.String, nullable=False)
description = db.Column(db.String, nullable=False)
thumbnail = db.Column(db.String, nullable=False)
background = db.Column(db.String, nullable=False)
downloadLink = db.Column(db.String, nullable=False)
approved = db.Column(db.Boolean, nullable=False, default=False)
class Images(db.Model):
id = db.Column(db.Integer, primary_key=True)
image = db.Column(db.String, nullable=False)
game_id = db.Column(db.Integer, db.ForeignKey('games.id'))
class Tags(db.Model):
id = db.Column(db.Integer, primary_key=True)
tag = db.Column(db.String, nullable=False)
game_id = db.Column(db.Integer, db.ForeignKey('games.id'))
class TriggerWarning(db.Model):
id = db.Column(db.Integer, primary_key=True)
warning = db.Column(db.String, nullable=False)
game_id = db.Column(db.Integer, db.ForeignKey('games.id'))
class Authros(db.Model):
class Authors(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String, nullable=False)
role = db.Column(db.String, nullable=False, default='Developer')

View file

@ -15,7 +15,7 @@ nav
color: $primary
z-index: 100
transition: color 0.2s ease-in-out
transition: color 0.1s ease-in-out
&::before
content: ""
@ -40,7 +40,7 @@ nav
text-decoration: none
color: inherit
transition: color 0.2s ease-in-out, font-weight 0.2s
transition: color 0.1s ease-in-out, font-weight 0.1s ease-in-out
&:hover
color: $accent

View file

@ -159,5 +159,5 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
# remove development files
/data
/storage
/logs

View file

@ -5,7 +5,7 @@ services:
image: caddy:alpine
restart: unless-stopped
ports:
# - 80:80
- 80:80
- 443:443
volumes:
- ./Caddy/Caddyfile:/etc/caddy/Caddyfile
@ -34,7 +34,7 @@ services:
build: ./Highscore-Server
restart: unless-stopped
volumes:
- ./Highscore-Server/data:/data/storage
- ./Highscore-Server/storage:/data/storage
- ./Highscore-Server/logs:/data/logs
environment:
FLASK_KEY: secret
@ -48,7 +48,7 @@ services:
build: ./DV8-Expo
restart: unless-stopped
volumes:
- ./DV8-Expo/data:/data/storage
- ./DV8-Expo/storage:/data/storage
- ./DV8-Expo/logs:/data/logs
environment:
FLASK_KEY: secret