From 8ef2928ab3e062a91b8c62da717ec3ea9b5ea75d Mon Sep 17 00:00:00 2001 From: augustin64 Date: Sun, 19 Nov 2023 16:05:23 +0100 Subject: [PATCH] Fix minor details of the migration script --- scripts/hooks/utils.py | 2 +- scripts/hooks/v1.py | 14 ++++++++------ scripts/migration.py | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/scripts/hooks/utils.py b/scripts/hooks/utils.py index 1ef91dc..6dd113b 100644 --- a/scripts/hooks/utils.py +++ b/scripts/hooks/utils.py @@ -2,7 +2,7 @@ import sqlite3 def run_sqlite_command(cmd): """Run a command against the database""" - con = sqlite3.connect("instance/partitioncloud.db") + con = sqlite3.connect("instance/partitioncloud.sqlite") cur = con.cursor() cur.execute(cmd) con.commit() diff --git a/scripts/hooks/v1.py b/scripts/hooks/v1.py index 887a18e..3d8f263 100644 --- a/scripts/hooks/v1.py +++ b/scripts/hooks/v1.py @@ -12,16 +12,18 @@ def add_groupes(): id INTEGER PRIMARY KEY, name TEXT NOT NULL, uuid TEXT(36) NOT NULL - ); - - CREATE TABLE groupe_contient_user ( + );""" + ) + utils.run_sqlite_command( + """CREATE TABLE groupe_contient_user ( groupe_id INTEGER NOT NULL, user_id INTEGER NOT NULL, is_admin INTEGER NOT NULL DEFAULT 0, PRIMARY KEY (groupe_id, user_id) - ); - - CREATE TABLE groupe_contient_album ( + );""" + ) + utils.run_sqlite_command( + """CREATE TABLE groupe_contient_album ( groupe_id INTEGER NOT NULL, album_id INTEGER NOT NULL, PRIMARY KEY (groupe_id, album_id) diff --git a/scripts/migration.py b/scripts/migration.py index bb9928a..eef1d66 100644 --- a/scripts/migration.py +++ b/scripts/migration.py @@ -129,7 +129,7 @@ def restore(version): exit(1) dest = os.path.join("backups", version) - print(f"Restoring from {dst}") + print(f"Restoring from {dest}") paths = [ ("instance", os.path.join(dest, "instance")), (os.path.join("partitioncloud", "partitions"), os.path.join(dest, "partitions")), @@ -144,7 +144,7 @@ def restore(version): print(f"\tRestoring {src}") copy_tree(dst, src) else: - print(f"{Fore.RED}No available backup for {src}, deleting current content to avoid any conflict{Style.RESET_ALL}") + print(f"\t{Fore.RED}No available backup for {src}, deleting current content to avoid any conflict{Style.RESET_ALL}") if __name__ == "__main__":