extraction du modul database et creation de page vide

This commit is contained in:
Kepka Ludovic
2025-08-09 08:10:18 +02:00
parent fb836288fd
commit 21b5cf8669
13 changed files with 66 additions and 20 deletions

12
database/__init__.py Normal file
View File

@@ -0,0 +1,12 @@
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.sql import text
from webapp import webapp
webapp.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
db = SQLAlchemy(webapp)
with webapp.app_context():
with open('database/schema.sql', 'r') as f:
sql_script = f.read()
db.session.execute(text(sql_script))
db.session.commit()

9
database/message.py Normal file
View File

@@ -0,0 +1,9 @@
# from webapp import db
from database import db
class Message(db.Model):
id = db.Column(db.Integer, primary_key=True)
enable = db.Column(db.Boolean, default=False)
text = db.Column(db.String(200))
# en seconde
periodicity = db.Column(db.Integer)

6
database/schema.sql Normal file
View File

@@ -0,0 +1,6 @@
CREATE TABLE IF NOT EXISTS `message` (
id INTEGER PRIMARY KEY AUTOINCREMENT,
`enable` BOOLEAN NOT NULL DEFAULT FALSE,
`text` VARCHAR(256) NULL,
periodicity INTEGER NULL
);