" FOREIGN KEY(app_id,app_control)\n" \
" REFERENCES package_app_app_control(app_id,app_control) ON DELETE CASCADE);" | sqlite3 $dbpath
+ echo -e "CREATE TABLE IF NOT EXISTS package_app_data_control_privilege (\n" \
+ " providerid TEXT,\n" \
+ " privilege TEXT NOT NULL,\n" \
+ " type TEXT NOT NULL,\n" \
+ " PRIMARY KEY(providerid, privilege, type)\n" \
+ " FOREIGN KEY(providerid, type)\n" \
+ " REFERENCES package_app_data_control(providerid, type) ON DELETE CASCADE);" | sqlite3 $dbpath
+
+ echo -e "ALTER TABLE package_app_data_control RENAME TO package_app_data_control_backup;" | sqlite3 $dbpath
+ echo -e "CREATE TABLE package_app_data_control (\n" \
+ " app_id TEXT NOT NULL,\n" \
+ " providerid TEXT NOT NULL,\n" \
+ " access TEXT NOT NULL,\n" \
+ " type TEXT NOT NULL,\n" \
+ " trusted TEXT NOT NULL,\n" \
+ " PRIMARY KEY(providerid, type)\n" \
+ " FOREIGN KEY(app_id)\n" \
+ " REFERENCES package_app_info(app_id) ON DELETE CASCADE);" | sqlite3 $dbpath
+
+ #seperate migration of app data control table by access type for backward compatibility.
+ echo -e "INSERT INTO package_app_data_control(app_id, providerid, access, type, trusted) " \
+ " SELECT app_id, providerid, access, type, 'false' FROM package_app_data_control_backup WHERE access='readwrite' COLLATE NOCASE;" | sqlite3 $dbpath
+ echo -e "INSERT INTO package_app_data_control(app_id, providerid, access, type, trusted) " \
+ " SELECT app_id, providerid, access, type, 'false' FROM package_app_data_control_backup WHERE access='writeonly' COLLATE NOCASE;" | sqlite3 $dbpath
+ echo -e "INSERT INTO package_app_data_control(app_id, providerid, access, type, trusted) " \
+ " SELECT app_id, providerid, access, type, 'false' FROM package_app_data_control_backup WHERE access!='readwrite' COLLATE NOCASE AND access!='writeonly' COLLATE NOCASE;" | sqlite3 $dbpath
+ echo -e "DROP TABLE package_app_data_control_backup;" | sqlite3 $dbpath
+
echo "DROP TABLE IF EXISTS package_app_icon_section_info;" | sqlite3 $dbpath
echo "DROP TABLE IF EXISTS package_app_image_info;" | sqlite3 $dbpath
echo "DROP TABLE IF EXISTS package_app_app_permission;" | sqlite3 $dbpath
migrate_user_db
migrate_cert_db
+pkg_upgrade -rof