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 1 to schema version 2.
25 ALTER TABLE PERMISSION_TABLE RENAME TO OLD_PERMISSION_TABLE;
26 DROP INDEX perm_index_idx;
29 -- create new structure
30 CREATE TABLE NAME_TABLE(name TEXT NOT NULL,
32 idx INTEGER PRIMARY KEY AUTOINCREMENT,
34 CREATE INDEX name_index_idx ON NAME_TABLE(idx);
35 CREATE TABLE OBJECT_TABLE(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 NAME_TABLE(idx) ON DELETE CASCADE,
45 PRIMARY KEY(idx, dataType));
46 CREATE TABLE PERMISSION_TABLE(label TEXT NOT NULL,
47 accessFlags TEXT NOT NULL,
49 FOREIGN KEY(idx) REFERENCES NAME_TABLE(idx) ON DELETE CASCADE,
50 PRIMARY KEY(label, idx));
51 CREATE INDEX perm_index_idx ON PERMISSION_TABLE(idx);
55 INSERT INTO NAME_TABLE(name, label, idx) SELECT name, label, idx FROM CKM_TABLE;
56 INSERT INTO OBJECT_TABLE(exportable, dataType, algorithmType, encryptionScheme,
57 iv, dataSize, data, tag, idx)
58 SELECT exportable, dataType, algorithmType, encryptionScheme, iv,
59 dataSize, data, tag, idx FROM CKM_TABLE;
60 INSERT INTO PERMISSION_TABLE(label, accessFlags, idx) SELECT label, accessFlags, idx FROM OLD_PERMISSION_TABLE;
64 DROP TABLE OLD_PERMISSION_TABLE;