summaryrefslogtreecommitdiff
path: root/glance/db/sqlalchemy/migrate_repo/versions/006_sqlite_upgrade.sql
blob: 108d1ee9899e4c2fcd3c226808f5e481d43c1eac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
--
-- This is necessary because SQLite does not support
-- RENAME INDEX or ALTER TABLE CHANGE COLUMN.
--
CREATE TEMPORARY TABLE image_properties_backup (
	id INTEGER NOT NULL,
	image_id INTEGER NOT NULL,
	name VARCHAR(255) NOT NULL,
	value TEXT,
	created_at DATETIME NOT NULL,
	updated_at DATETIME,
	deleted_at DATETIME,
	deleted BOOLEAN NOT NULL,
	PRIMARY KEY (id)
);

INSERT INTO image_properties_backup
SELECT id, image_id, key, value, created_at, updated_at, deleted_at, deleted
FROM image_properties;

DROP TABLE image_properties;

CREATE TABLE image_properties (
	id INTEGER NOT NULL,
	image_id INTEGER NOT NULL,
	name VARCHAR(255) NOT NULL,
	value TEXT,
	created_at DATETIME NOT NULL,
	updated_at DATETIME,
	deleted_at DATETIME,
	deleted BOOLEAN NOT NULL,
	PRIMARY KEY (id),
	CHECK (deleted IN (0, 1)),
	UNIQUE (image_id, name),
	FOREIGN KEY(image_id) REFERENCES images (id)
);
CREATE INDEX ix_image_properties_name ON image_properties (name);
CREATE INDEX ix_image_properties_deleted ON image_properties (deleted);

INSERT INTO image_properties (id, image_id, name, value, created_at, updated_at, deleted_at, deleted)
SELECT id, image_id, name, value, created_at, updated_at, deleted_at, deleted
FROM image_properties_backup;

DROP TABLE image_properties_backup;