diff --git a/app/__init__.py b/app/__init__.py index 0a8fa379d4c31452624496f3a78b653ff07c18b8..78bfa455c89eb6dac846baaa62245ec87ac32114 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,9 +1,37 @@ from flask import Flask +from flask_sqlalchemy import SQLAlchemy + + +db = SQLAlchemy() def create_app(): app = Flask(__name__) + app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///mes.db" + app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False + + db.init_app(app) + + from app.models import Station + + with app.app_context(): + db.create_all() + + for number in range(1, 6): + station_id = f"ST-{number:02d}" + + if db.session.get(Station, station_id) is None: + db.session.add( + Station( + id=station_id, + name=f"Station {number}", + enabled=True, + ) + ) + + db.session.commit() + @app.route("/") def index(): return "Manufacturing Execution System - MES Prototype" diff --git a/app/models.py b/app/models.py new file mode 100644 index 0000000000000000000000000000000000000000..28ad520bb434c03c98b2b81f3f6a69b2a2fefe28 --- /dev/null +++ b/app/models.py @@ -0,0 +1,12 @@ +from app import db + + +class Station(db.Model): + __tablename__ = "stations" + + id = db.Column(db.String(5), primary_key=True) + name = db.Column(db.String(50), nullable=False) + enabled = db.Column(db.Boolean, nullable=False, default=True) + + def __repr__(self): + return f"" \ No newline at end of file