From 3906acd297c0b08ea9e8ef091d3137333b2f6cf6 Mon Sep 17 00:00:00 2001 From: Nameru Thapa Date: Sat, 8 Aug 2026 11:03:30 +0200 Subject: [PATCH] feat: add SQLite database and fixed stations --- app/__init__.py | 28 ++++++++++++++++++++++++++++ app/models.py | 12 ++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 app/models.py diff --git a/app/__init__.py b/app/__init__.py index 0a8fa37..78bfa45 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 0000000..28ad520 --- /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 -- GitLab