2 * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
18 * @author Maciej Karpiuk (m.karpiuk2@samsung.com)
20 * @brief DB migration script from schema version 2 to schema version 3.
25 DROP INDEX perm_index_idx;
28 -- create new structure
29 CREATE TABLE SCHEMA_INFO(name TEXT PRIMARY KEY NOT NULL,
31 ALTER TABLE NAME_TABLE RENAME TO NAMES;
32 -- need to create OBJECT table from scratch,
33 -- as SQLite does not support "ALTER COLUMN"
34 -- (REFERENCES NAME_TABLE --> NAMES)
35 CREATE TABLE OBJECTS(exportable INTEGER NOT NULL,
36 dataType INTEGER NOT NULL,
37 algorithmType INTEGER NOT NULL,
38 encryptionScheme INTEGER NOT NULL,
40 dataSize INTEGER NOT NULL,
44 FOREIGN KEY(idx) REFERENCES NAMES(idx) ON DELETE CASCADE,
45 PRIMARY KEY(idx, dataType));
46 ALTER TABLE KEY_TABLE RENAME TO KEYS;
47 CREATE TABLE PERMISSIONS(permissionLabel TEXT NOT NULL,
48 permissionMask INTEGER NOT NULL,
50 FOREIGN KEY(idx) REFERENCES NAMES(idx) ON DELETE CASCADE,
51 PRIMARY KEY(permissionLabel, idx));
52 CREATE INDEX perm_index_idx ON PERMISSIONS(idx);
53 CREATE VIEW [join_name_object_tables] AS
54 SELECT N.name, N.label, O.* FROM NAMES AS N
55 JOIN OBJECTS AS O ON O.idx=N.idx;
56 CREATE VIEW [join_name_permission_tables] AS
57 SELECT N.name, N.label, P.permissionMask, P.permissionLabel FROM NAMES AS N
58 JOIN PERMISSIONS AS P ON P.idx=N.idx;
59 CREATE VIEW [join_all_tables] AS
60 SELECT N.*, P.permissionLabel, P.permissionMask, O.dataType FROM NAMES AS N
61 JOIN OBJECTS AS O ON O.idx=N.idx
62 JOIN PERMISSIONS AS P ON P.idx=N.idx;
66 INSERT INTO OBJECTS SELECT * FROM OBJECT_TABLE;
67 INSERT INTO PERMISSIONS(permissionLabel, permissionMask, idx) SELECT label, 1, idx FROM PERMISSION_TABLE WHERE accessFlags='R';
68 INSERT INTO PERMISSIONS(permissionLabel, permissionMask, idx) SELECT label, 3, idx FROM PERMISSION_TABLE WHERE accessFlags='RD';
69 INSERT INTO PERMISSIONS(permissionLabel, permissionMask, idx) SELECT label, 3, idx FROM NAMES;
73 DROP TABLE OBJECT_TABLE;
74 DROP TABLE PERMISSION_TABLE;