From 404d1cbda0af1a7c4b13236e727c7c6c4e35eab6 Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 14 Sep 2025 00:01:29 +0200 Subject: [PATCH] Migre la table game_bundle si elle a l'ancienne structure --- database/__init__.py | 28 +++++++++++++++++++++++++++- database/database.db | 0 2 files changed, 27 insertions(+), 1 deletion(-) delete mode 100644 database/database.db diff --git a/database/__init__.py b/database/__init__.py index 36795f9..234698c 100644 --- a/database/__init__.py +++ b/database/__init__.py @@ -1,10 +1,36 @@ from flask_sqlalchemy import SQLAlchemy from webapp import webapp +import os -webapp.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db' +basedir = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) +webapp.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///{os.path.join(basedir, "instance", "database.db")}' db = SQLAlchemy(webapp) +def migrate_game_bundle_if_needed(): + """Migre la table game_bundle si elle a l'ancienne structure (id comme clé primaire)""" + try: + connection = db.session.connection().connection + cursor = connection.cursor() + + cursor.execute("PRAGMA table_info(game_bundle)") + columns = cursor.fetchall() + + if columns: + has_id_primary = any(col[1] == 'id' and col[5] == 1 for col in columns) + + if has_id_primary: + print("Migration de game_bundle: ancienne structure détectée") + cursor.execute("DROP TABLE game_bundle") + connection.commit() + print("Ancienne table game_bundle supprimée") + + cursor.close() + except Exception as e: + print(f"Erreur lors de la vérification de migration: {e}") + with webapp.app_context(): + migrate_game_bundle_if_needed() + with open('database/schema.sql', 'r') as f: sql = f.read() connection = db.session.connection().connection diff --git a/database/database.db b/database/database.db deleted file mode 100644 index e69de29..0000000