Skip to content

Commit

Permalink
Remise de l'atelier
Browse files Browse the repository at this point in the history
La migration et le rollback s'effectuent correctement
  • Loading branch information
RaphaelChheang committed Apr 1, 2024
1 parent b948170 commit ced86b8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
12 changes: 6 additions & 6 deletions database.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ def __init__(self):
"""
Chargez les variables d'environnement de votre fichier .env, puis complétez les lignes 15 à 19 afin de récupérer les valeurs de ces variables
"""

self.host =
self.port =
self.database =
self.user =
self.password =
load_dotenv()
self.host = os.environ.get("HOST")
self.port = int(os.environ.get("PORT"))
self.database = os.environ.get("DATABASE")
self.user = os.environ.get("USER")
self.password = os.environ.get("PASSWORD")

self._open_sql_connection()

Expand Down
25 changes: 25 additions & 0 deletions db_scripts/migrate_1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
CREATE TABLE band (
bandName VARCHAR(50),
creation YEAR,
genre VARCHAR(50),
PRIMARY KEY (bandName)
);

INSERT INTO band (bandName, creation, genre) VALUES
('Crazy Duo', 2015, 'rock'),
('Luna', 2009, 'classical'),
('Mysterio', 2019, 'pop');

ALTER TABLE singer RENAME TO musician;
ALTER TABLE musician CHANGE singerName musicianName VARCHAR(50);
ALTER TABLE musician ADD COLUMN role VARCHAR(50);
ALTER TABLE musician ADD COLUMN bandName VARCHAR(50);

UPDATE musician m SET m.role = 'vocals' WHERE m.musicianName = 'Alina';
UPDATE musician m SET m.bandName = 'Crazy Duo' WHERE m.musicianName = 'Alina';
UPDATE musician m SET m.role = 'guitar' WHERE m.musicianName = 'Mysterio';
UPDATE musician m SET m.bandName = 'Mysterio' WHERE m.musicianName = 'Mysterio';
UPDATE musician m SET m.role = 'percussion' WHERE m.musicianName = 'Rainbow';
UPDATE musician m SET m.bandName = 'Crazy Duo' WHERE m.musicianName = 'Rainbow';
UPDATE musician m SET m.role = 'piano' WHERE m.musicianName = 'Luna';
UPDATE musician m SET m.bandName = 'Luna' WHERE m.musicianName = 'Luna';
6 changes: 6 additions & 0 deletions db_scripts/rollback_1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DROP TABLE band;

ALTER TABLE musician RENAME TO singer;
ALTER TABLE singer CHANGE musicianName singerName VARCHAR(50);
ALTER TABLE singer DROP COLUMN role;
ALTER TABLE singer DROP COLUMN bandName;

0 comments on commit ced86b8

Please sign in to comment.