1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 package com.android.messaging.datamodel; 17 18 import android.database.sqlite.SQLiteDatabase; 19 20 import com.android.messaging.util.Assert; 21 import com.android.messaging.util.LogUtil; 22 23 public class DatabaseUpgradeHelper { 24 private static final String TAG = LogUtil.BUGLE_DATABASE_TAG; 25 doOnUpgrade(final SQLiteDatabase db, final int oldVersion, final int newVersion)26 public void doOnUpgrade(final SQLiteDatabase db, final int oldVersion, final int newVersion) { 27 Assert.isTrue(newVersion >= oldVersion); 28 if (oldVersion == newVersion) { 29 return; 30 } 31 32 LogUtil.i(TAG, "Database upgrade started from version " + oldVersion + " to " + newVersion); 33 34 // Add future upgrade code here 35 } 36 onDowngrade(final SQLiteDatabase db, final int oldVersion, final int newVersion)37 public void onDowngrade(final SQLiteDatabase db, final int oldVersion, final int newVersion) { 38 DatabaseHelper.rebuildTables(db); 39 LogUtil.e(TAG, "Database downgrade requested for version " + 40 oldVersion + " version " + newVersion + ", forcing db rebuild!"); 41 } 42 } 43