From ec246a50eda3cf2f73487f2894198a931c5dc51f Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Mon, 8 Feb 2021 08:19:21 -0800 Subject: [PATCH] Fix account list join primary key --- .../DB/Content/ContentDatabase+Migration.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/DB/Sources/DB/Content/ContentDatabase+Migration.swift b/DB/Sources/DB/Content/ContentDatabase+Migration.swift index d2cc517..a0e3f24 100644 --- a/DB/Sources/DB/Content/ContentDatabase+Migration.swift +++ b/DB/Sources/DB/Content/ContentDatabase+Migration.swift @@ -268,6 +268,22 @@ extension ContentDatabase { } } + migrator.registerMigration("1.0.0-pk-fix") { db in + try db.create(table: "new_accountListJoin") { t in + t.column("accountListId", .text).indexed().notNull() + .references("accountList", onDelete: .cascade) + t.column("accountId", .text).indexed().notNull() + .references("accountRecord", onDelete: .cascade) + t.column("order", .integer).notNull() + + t.primaryKey(["accountListId", "accountId"], onConflict: .replace) + } + + try db.execute(sql: "INSERT INTO new_accountListJoin SELECT * FROM accountListJoin") + try db.drop(table: "accountListJoin") + try db.rename(table: "new_accountListJoin", to: "accountListJoin") + } + return migrator } }