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. # option (not recommended) you can uncomment the following to ignore the entire idea folder.
# remove development files # remove development files
/data /storage
/logs /logs

View file

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

View file

@ -1,12 +1,13 @@
from flask import Flask, render_template from flask import Flask, render_template
from flask_assets import Bundle from flask_assets import Bundle
from website.extensions import db, assets from website.extensions import db, migrate, assets
from website.config import INSTANCE_DIR 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') app.config.from_pyfile('config.py')
db.init_app(app) db.init_app(app)
migrate.init_app(app, db, directory=MIGRATION_DIR)
with app.app_context(): with app.app_context():
db.create_all() db.create_all()

View file

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

View file

@ -7,23 +7,27 @@ from website.extensions import db
class Games(db.Model): class Games(db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String, nullable=False) 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) downloadLink = db.Column(db.String, nullable=False)
approved = db.Column(db.Boolean, nullable=False, default=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): class Tags(db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
tag = db.Column(db.String, nullable=False) tag = db.Column(db.String, nullable=False)
game_id = db.Column(db.Integer, db.ForeignKey('games.id')) game_id = db.Column(db.Integer, db.ForeignKey('games.id'))
class TriggerWarning(db.Model): class Authors(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):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String, nullable=False) name = db.Column(db.String, nullable=False)
role = db.Column(db.String, nullable=False, default='Developer') role = db.Column(db.String, nullable=False, default='Developer')

View file

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

View file

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

View file

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