[lxc-devel] [lxd/master] lxd/db: Add upgrade logic for UNIQUE fix
stgraber on Github
lxc-bot at linuxcontainers.org
Thu Dec 12 20:15:55 UTC 2019
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20191212/bd80b0c6/attachment.bin>
-------------- next part --------------
From 27a1566615c406a2c92a7b3eb81fad41a7284a91 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 12 Dec 2019 15:14:49 -0500
Subject: [PATCH] lxd/db: Add upgrade logic for UNIQUE fix
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd/db/cluster/schema.go | 2 +-
lxd/db/cluster/update.go | 19 +++++++++++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/lxd/db/cluster/schema.go b/lxd/db/cluster/schema.go
index 8a2cfd5b39..f81b8c4aa6 100644
--- a/lxd/db/cluster/schema.go
+++ b/lxd/db/cluster/schema.go
@@ -495,5 +495,5 @@ CREATE TABLE storage_volumes_config (
FOREIGN KEY (storage_volume_id) REFERENCES storage_volumes (id) ON DELETE CASCADE
);
-INSERT INTO schema (version, updated_at) VALUES (21, strftime("%s"))
+INSERT INTO schema (version, updated_at) VALUES (22, strftime("%s"))
`
diff --git a/lxd/db/cluster/update.go b/lxd/db/cluster/update.go
index a4ffcc1f16..e468aa1fc0 100644
--- a/lxd/db/cluster/update.go
+++ b/lxd/db/cluster/update.go
@@ -57,6 +57,25 @@ var updates = map[int]schema.Update{
19: updateFromV18,
20: updateFromV19,
21: updateFromV20,
+ 22: updateFromV21,
+}
+
+// Fix "images_profiles" table (missing UNIQUE)
+func updateFromV21(tx *sql.Tx) error {
+ stmts := `
+ALTER TABLE images_profiles RENAME TO old_images_profiles;
+CREATE TABLE images_profiles (
+ image_id INTEGER NOT NULL,
+ profile_id INTEGER NOT NULL,
+ FOREIGN KEY (image_id) REFERENCES images (id) ON DELETE CASCADE,
+ FOREIGN KEY (profile_id) REFERENCES profiles (id) ON DELETE CASCADE,
+ UNIQUE (image_id, profile_id)
+);
+INSERT INTO images_profiles SELECT * FROM old_images_profiles;
+DROP TABLE old_images_profiles;
+`
+ _, err := tx.Exec(stmts)
+ return err
}
// Add "images_profiles" table
More information about the lxc-devel
mailing list