refactor: multiple db migrations
This commit is contained in:
parent
ff04bb44ce
commit
2a08622d79
4 changed files with 11 additions and 6 deletions
|
@ -4,4 +4,4 @@ prices = {
|
|||
}
|
||||
|
||||
db_path = '../db/baseFilms.db'
|
||||
dump_path = '../db/dumpFile'
|
||||
migrations_db = '../db/migrations'
|
||||
|
|
2
db/migrations/0002_imdb
Normal file
2
db/migrations/0002_imdb
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE films
|
||||
ADD idImdb TEXT
|
|
@ -5,6 +5,7 @@ Created on Sun Mar 25 18:20:49 2018
|
|||
|
||||
@author: alice
|
||||
"""
|
||||
import os
|
||||
|
||||
# Enhancements :
|
||||
# * 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 cineclubBlogSQ import filmSQ as f
|
||||
from config import dump_path, db_path
|
||||
from config import migrations_db, db_path
|
||||
import sqlite3
|
||||
|
||||
DEBUG = True
|
||||
|
@ -56,12 +57,14 @@ class FilmInterface():
|
|||
print("\nLe film couramment chargé est", self.filmCharge.nom, "\n")
|
||||
|
||||
def initBDD(self):
|
||||
fichier = open(dump_path, "r")
|
||||
instruction = fichier.read()
|
||||
fichier.close()
|
||||
instructions = []
|
||||
for filename in os.listdir(migrations_db):
|
||||
with open(os.path.join(migrations_db, filename), 'r') as fichier:
|
||||
instructions.append(fichier.read())
|
||||
|
||||
conn = sqlite3.connect(db_path)
|
||||
c = conn.cursor()
|
||||
for instruction in instructions:
|
||||
c.executescript(instruction)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
|
Loading…
Reference in a new issue