refactor: multiple db migrations

This commit is contained in:
Alice 2023-09-02 17:27:21 +02:00
parent ff04bb44ce
commit 2a08622d79
4 changed files with 11 additions and 6 deletions

View file

@ -4,4 +4,4 @@ prices = {
} }
db_path = '../db/baseFilms.db' db_path = '../db/baseFilms.db'
dump_path = '../db/dumpFile' migrations_db = '../db/migrations'

2
db/migrations/0002_imdb Normal file
View file

@ -0,0 +1,2 @@
ALTER TABLE films
ADD idImdb TEXT

View file

@ -5,6 +5,7 @@ Created on Sun Mar 25 18:20:49 2018
@author: alice @author: alice
""" """
import os
# Enhancements : # Enhancements :
# * utiliser un dictionnaire pour les menus, afin d'avoir un menu de fond (quitter, corriger etc) # * utiliser un dictionnaire pour les menus, afin d'avoir un menu de fond (quitter, corriger etc)
@ -13,7 +14,7 @@ Created on Sun Mar 25 18:20:49 2018
from genCom import GenerateurComm from genCom import GenerateurComm
from cineclubBlogSQ import filmSQ as f from cineclubBlogSQ import filmSQ as f
from config import dump_path, db_path from config import migrations_db, db_path
import sqlite3 import sqlite3
DEBUG = True DEBUG = True
@ -56,12 +57,14 @@ class FilmInterface():
print("\nLe film couramment chargé est", self.filmCharge.nom, "\n") print("\nLe film couramment chargé est", self.filmCharge.nom, "\n")
def initBDD(self): def initBDD(self):
fichier = open(dump_path, "r") instructions = []
instruction = fichier.read() for filename in os.listdir(migrations_db):
fichier.close() with open(os.path.join(migrations_db, filename), 'r') as fichier:
instructions.append(fichier.read())
conn = sqlite3.connect(db_path) conn = sqlite3.connect(db_path)
c = conn.cursor() c = conn.cursor()
for instruction in instructions:
c.executescript(instruction) c.executescript(instruction)
conn.commit() conn.commit()
conn.close() conn.close()