[lxc-devel] [lxd/master] DB schema tweak

stgraber on Github lxc-bot at linuxcontainers.org
Wed Sep 4 18:54:03 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190904/d9b39c20/attachment.bin>
-------------- next part --------------
From bc37110e3e72a0ec6ed0f55537f471918f2fdf90 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 4 Sep 2019 14:38:19 -0400
Subject: [PATCH 1/2] Makefile: Fix update-schema target
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>
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index fe8e419f00..0b268c65ba 100644
--- a/Makefile
+++ b/Makefile
@@ -109,7 +109,7 @@ update-protobuf:
 	protoc --go_out=. ./lxd/migration/migrate.proto
 
 .PHONY: update-schema
-generate:
+update-schema:
 	cd shared/generate && go build -o lxd-generate -tags "$(TAG_SQLITE3)" $(DEBUG) && cd -
 	mv shared/generate/lxd-generate $(GOPATH)/bin
 	go generate ./...

From 30777fe8e660e53840037803ac8137ba01b6c1b5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 4 Sep 2019 14:52:44 -0400
Subject: [PATCH 2/2] lxd/db: Add type column to images table
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 | 3 ++-
 lxd/db/cluster/update.go | 7 +++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/lxd/db/cluster/schema.go b/lxd/db/cluster/schema.go
index 3a3ee8979d..78534e25b6 100644
--- a/lxd/db/cluster/schema.go
+++ b/lxd/db/cluster/schema.go
@@ -34,6 +34,7 @@ CREATE TABLE "images" (
     last_use_date DATETIME,
     auto_update INTEGER NOT NULL DEFAULT 0,
     project_id INTEGER NOT NULL,
+    type INTEGER NOT NULL DEFAULT 0,
     UNIQUE (project_id, fingerprint),
     FOREIGN KEY (project_id) REFERENCES projects (id) ON DELETE CASCADE
 );
@@ -480,5 +481,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 (16, strftime("%s"))
+INSERT INTO schema (version, updated_at) VALUES (17, strftime("%s"))
 `
diff --git a/lxd/db/cluster/update.go b/lxd/db/cluster/update.go
index 93925a6f94..67e9a1ca20 100644
--- a/lxd/db/cluster/update.go
+++ b/lxd/db/cluster/update.go
@@ -51,6 +51,13 @@ var updates = map[int]schema.Update{
 	14: updateFromV13,
 	15: updateFromV14,
 	16: updateFromV15,
+	17: updateFromV16,
+}
+
+// Add image type column
+func updateFromV16(tx *sql.Tx) error {
+	_, err := tx.Exec("ALTER TABLE images ADD COLUMN type INTEGER NOT NULL DEFAULT 0;")
+	return err
 }
 
 // Create new snapshot tables and migrate data to them.


More information about the lxc-devel mailing list