~ttx/glance/cactus-final-version

« back to all changes in this revision

Viewing changes to glance/registry/db/migrate_repo/versions/003_sqlite_upgrade.sql

  • Committer: Tarmac
  • Author(s): jaypipes at gmail
  • Date: 2011-03-24 23:12:29 UTC
  • mfrom: (92.2.5 bug730213)
  • Revision ID: tarmac-20110324231229-51xdg48ozlj0oo9s
Add migration testing and migration for disk_format/container_format

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
BEGIN TRANSACTION;
 
2
 
 
3
/* Move type column from base images table
 
4
 * to be records in image_properties table */
 
5
CREATE TEMPORARY TABLE tmp_type_records (id INTEGER NOT NULL, type VARCHAR(30) NOT NULL);
 
6
INSERT INTO tmp_type_records
 
7
SELECT id, type
 
8
FROM images
 
9
WHERE type IS NOT NULL;
 
10
 
 
11
REPLACE INTO image_properties
 
12
(image_id, key, value, created_at, deleted)
 
13
SELECT id, 'type', type, date('now'), 0
 
14
FROM tmp_type_records;
 
15
 
 
16
DROP TABLE tmp_type_records;
 
17
 
 
18
/* Make changes to the base images table */
 
19
CREATE TEMPORARY TABLE images_backup (
 
20
        id INTEGER NOT NULL, 
 
21
        name VARCHAR(255), 
 
22
        size INTEGER, 
 
23
        status VARCHAR(30) NOT NULL, 
 
24
        is_public BOOLEAN NOT NULL, 
 
25
        location TEXT, 
 
26
        created_at DATETIME NOT NULL, 
 
27
        updated_at DATETIME, 
 
28
        deleted_at DATETIME, 
 
29
        deleted BOOLEAN NOT NULL, 
 
30
        PRIMARY KEY (id)
 
31
);
 
32
 
 
33
INSERT INTO images_backup
 
34
SELECT id, name, size, status, is_public, location, created_at, updated_at, deleted_at, deleted
 
35
FROM images;
 
36
 
 
37
DROP TABLE images;
 
38
 
 
39
CREATE TABLE images (
 
40
        id INTEGER NOT NULL, 
 
41
        name VARCHAR(255), 
 
42
        size INTEGER, 
 
43
        status VARCHAR(30) NOT NULL, 
 
44
        is_public BOOLEAN NOT NULL, 
 
45
        location TEXT, 
 
46
        created_at DATETIME NOT NULL, 
 
47
        updated_at DATETIME, 
 
48
        deleted_at DATETIME, 
 
49
        deleted BOOLEAN NOT NULL, 
 
50
        disk_format VARCHAR(20),
 
51
        container_format VARCHAR(20),
 
52
        PRIMARY KEY (id), 
 
53
        CHECK (is_public IN (0, 1)), 
 
54
        CHECK (deleted IN (0, 1))
 
55
);
 
56
CREATE INDEX ix_images_deleted ON images (deleted);
 
57
CREATE INDEX ix_images_is_public ON images (is_public);
 
58
 
 
59
INSERT INTO images (id, name, size, status, is_public, location, created_at, updated_at, deleted_at, deleted)
 
60
SELECT id, name, size, status, is_public, location, created_at, updated_at, deleted_at, deleted
 
61
FROM images_backup;
 
62
 
 
63
DROP TABLE images_backup;
 
64
COMMIT;