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;
27 DROP INDEX ckm_index_label;
30 -- create new structure
31 CREATE TABLE NAME_TABLE(name TEXT NOT NULL,
33 idx INTEGER PRIMARY KEY AUTOINCREMENT,
35 CREATE INDEX name_index_idx ON NAME_TABLE(idx);
36 CREATE TABLE OBJECT_TABLE(exportable INTEGER NOT NULL,
37 dataType INTEGER NOT NULL,
38 algorithmType INTEGER NOT NULL,
39 encryptionScheme INTEGER NOT NULL,
41 dataSize INTEGER NOT NULL,
45 FOREIGN KEY(idx) REFERENCES NAME_TABLE(idx) ON DELETE CASCADE,
46 PRIMARY KEY(idx, dataType));
47 CREATE TABLE PERMISSION_TABLE(label TEXT NOT NULL,
48 accessFlags TEXT NOT NULL,
50 FOREIGN KEY(idx) REFERENCES NAME_TABLE(idx) ON DELETE CASCADE,
51 PRIMARY KEY(label, idx));
52 CREATE INDEX perm_index_idx ON PERMISSION_TABLE(idx);
56 INSERT INTO NAME_TABLE(name, label, idx) SELECT name, label, idx FROM CKM_TABLE;
57 INSERT INTO OBJECT_TABLE(exportable, dataType, algorithmType, encryptionScheme,
58 iv, dataSize, data, tag, idx)
59 SELECT exportable, dataType, algorithmType, encryptionScheme, iv,
60 dataSize, data, tag, idx FROM CKM_TABLE;
61 INSERT INTO PERMISSION_TABLE(label, accessFlags, idx) SELECT label, accessFlags, idx FROM OLD_PERMISSION_TABLE;
65 DROP TABLE OLD_PERMISSION_TABLE;