@Test public void onUpgradeFromV18() { final int oldVersion = 18; final int newVersion = DatabaseHelper.DATABASE_VERSION; final TableDefaultsCustomizer customizer = mock(TableDefaultsCustomizer.class); mPaymentMethodsTable.onUpgrade(mSQLiteDatabase, oldVersion, newVersion, customizer); verify(mSQLiteDatabase, atLeastOnce()).execSQL(mSqlCaptor.capture()); verify(customizer, never()).insertPaymentMethodDefaults(mPaymentMethodsTable); final List<String> allValues = mSqlCaptor.getAllValues(); assertEquals(2, allValues.size()); assertEquals(allValues.get(0), "ALTER TABLE " + mPaymentMethodsTable.getTableName() + " ADD entity_uuid TEXT"); }
@Override public synchronized void onUpgrade(@NonNull SQLiteDatabase db, int oldVersion, int newVersion, @NonNull TableDefaultsCustomizer customizer) { super.onUpgrade(db, oldVersion, newVersion, customizer); if (oldVersion <= 11) { final String sql = "CREATE TABLE " + getTableName() + " (" + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_METHOD + " TEXT" + ");"; Logger.debug(this, sql); db.execSQL(sql); customizer.insertPaymentMethodDefaults(this); } if (oldVersion <= 14) { onUpgradeToAddSyncInformation(db, oldVersion, newVersion); } if (oldVersion <= 15) { final String addCustomOrderColumn = String.format("ALTER TABLE %s ADD COLUMN %s INTEGER DEFAULT 0", getTableName(), AbstractColumnTable.COLUMN_CUSTOM_ORDER_ID); Logger.debug(this, addCustomOrderColumn); db.execSQL(addCustomOrderColumn); } if (oldVersion <= 16) { if (!hasCustomOrderIdColumn(db)) { final String addCustomOrderColumn = String.format("ALTER TABLE %s ADD COLUMN %s INTEGER DEFAULT 0", getTableName(), AbstractColumnTable.COLUMN_CUSTOM_ORDER_ID); final String updateDefaultCustomOrder = String.format("UPDATE %s SET %s = ROWID", getTableName(), AbstractColumnTable.COLUMN_CUSTOM_ORDER_ID); Logger.debug(this, addCustomOrderColumn); Logger.debug(this, updateDefaultCustomOrder); db.execSQL(addCustomOrderColumn); db.execSQL(updateDefaultCustomOrder); } } if (oldVersion <= 18) { onUpgradeToAddUUID(db, oldVersion); } if (oldVersion <= 21) { final String alterPaymentMethods = "ALTER TABLE " + getTableName() + " ADD COLUMN " + COLUMN_REIMBURSABLE + " BOOLEAN DEFAULT 0"; Logger.debug(this, alterPaymentMethods); db.execSQL(alterPaymentMethods); } }
PaymentMethodsTable extends AbstractSqlTable<PaymentMethod> { @Override public synchronized void onUpgrade(@NonNull SQLiteDatabase db, int oldVersion, int newVersion, @NonNull TableDefaultsCustomizer customizer) { super.onUpgrade(db, oldVersion, newVersion, customizer); if (oldVersion <= 11) { final String sql = "CREATE TABLE " + getTableName() + " (" + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_METHOD + " TEXT" + ");"; Logger.debug(this, sql); db.execSQL(sql); customizer.insertPaymentMethodDefaults(this); } if (oldVersion <= 14) { onUpgradeToAddSyncInformation(db, oldVersion, newVersion); } if (oldVersion <= 15) { final String addCustomOrderColumn = String.format("ALTER TABLE %s ADD COLUMN %s INTEGER DEFAULT 0", getTableName(), AbstractColumnTable.COLUMN_CUSTOM_ORDER_ID); Logger.debug(this, addCustomOrderColumn); db.execSQL(addCustomOrderColumn); } if (oldVersion <= 16) { if (!hasCustomOrderIdColumn(db)) { final String addCustomOrderColumn = String.format("ALTER TABLE %s ADD COLUMN %s INTEGER DEFAULT 0", getTableName(), AbstractColumnTable.COLUMN_CUSTOM_ORDER_ID); final String updateDefaultCustomOrder = String.format("UPDATE %s SET %s = ROWID", getTableName(), AbstractColumnTable.COLUMN_CUSTOM_ORDER_ID); Logger.debug(this, addCustomOrderColumn); Logger.debug(this, updateDefaultCustomOrder); db.execSQL(addCustomOrderColumn); db.execSQL(updateDefaultCustomOrder); } } if (oldVersion <= 18) { onUpgradeToAddUUID(db, oldVersion); } if (oldVersion <= 21) { final String alterPaymentMethods = "ALTER TABLE " + getTableName() + " ADD COLUMN " + COLUMN_REIMBURSABLE + " BOOLEAN DEFAULT 0"; Logger.debug(this, alterPaymentMethods); db.execSQL(alterPaymentMethods); } } }
PaymentMethodsTable extends AbstractSqlTable<PaymentMethod> { @Override public synchronized void onUpgrade(@NonNull SQLiteDatabase db, int oldVersion, int newVersion, @NonNull TableDefaultsCustomizer customizer) { super.onUpgrade(db, oldVersion, newVersion, customizer); if (oldVersion <= 11) { final String sql = "CREATE TABLE " + getTableName() + " (" + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_METHOD + " TEXT" + ");"; Logger.debug(this, sql); db.execSQL(sql); customizer.insertPaymentMethodDefaults(this); } if (oldVersion <= 14) { onUpgradeToAddSyncInformation(db, oldVersion, newVersion); } if (oldVersion <= 15) { final String addCustomOrderColumn = String.format("ALTER TABLE %s ADD COLUMN %s INTEGER DEFAULT 0", getTableName(), AbstractColumnTable.COLUMN_CUSTOM_ORDER_ID); Logger.debug(this, addCustomOrderColumn); db.execSQL(addCustomOrderColumn); } if (oldVersion <= 16) { if (!hasCustomOrderIdColumn(db)) { final String addCustomOrderColumn = String.format("ALTER TABLE %s ADD COLUMN %s INTEGER DEFAULT 0", getTableName(), AbstractColumnTable.COLUMN_CUSTOM_ORDER_ID); final String updateDefaultCustomOrder = String.format("UPDATE %s SET %s = ROWID", getTableName(), AbstractColumnTable.COLUMN_CUSTOM_ORDER_ID); Logger.debug(this, addCustomOrderColumn); Logger.debug(this, updateDefaultCustomOrder); db.execSQL(addCustomOrderColumn); db.execSQL(updateDefaultCustomOrder); } } if (oldVersion <= 18) { onUpgradeToAddUUID(db, oldVersion); } if (oldVersion <= 21) { final String alterPaymentMethods = "ALTER TABLE " + getTableName() + " ADD COLUMN " + COLUMN_REIMBURSABLE + " BOOLEAN DEFAULT 0"; Logger.debug(this, alterPaymentMethods); db.execSQL(alterPaymentMethods); } } PaymentMethodsTable(@NonNull SQLiteOpenHelper sqLiteOpenHelper,
                               @NonNull OrderingPreferencesManager orderingPreferencesManager); }
PaymentMethodsTable extends AbstractSqlTable<PaymentMethod> { @Override public synchronized void onUpgrade(@NonNull SQLiteDatabase db, int oldVersion, int newVersion, @NonNull TableDefaultsCustomizer customizer) { super.onUpgrade(db, oldVersion, newVersion, customizer); if (oldVersion <= 11) { final String sql = "CREATE TABLE " + getTableName() + " (" + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_METHOD + " TEXT" + ");"; Logger.debug(this, sql); db.execSQL(sql); customizer.insertPaymentMethodDefaults(this); } if (oldVersion <= 14) { onUpgradeToAddSyncInformation(db, oldVersion, newVersion); } if (oldVersion <= 15) { final String addCustomOrderColumn = String.format("ALTER TABLE %s ADD COLUMN %s INTEGER DEFAULT 0", getTableName(), AbstractColumnTable.COLUMN_CUSTOM_ORDER_ID); Logger.debug(this, addCustomOrderColumn); db.execSQL(addCustomOrderColumn); } if (oldVersion <= 16) { if (!hasCustomOrderIdColumn(db)) { final String addCustomOrderColumn = String.format("ALTER TABLE %s ADD COLUMN %s INTEGER DEFAULT 0", getTableName(), AbstractColumnTable.COLUMN_CUSTOM_ORDER_ID); final String updateDefaultCustomOrder = String.format("UPDATE %s SET %s = ROWID", getTableName(), AbstractColumnTable.COLUMN_CUSTOM_ORDER_ID); Logger.debug(this, addCustomOrderColumn); Logger.debug(this, updateDefaultCustomOrder); db.execSQL(addCustomOrderColumn); db.execSQL(updateDefaultCustomOrder); } } if (oldVersion <= 18) { onUpgradeToAddUUID(db, oldVersion); } if (oldVersion <= 21) { final String alterPaymentMethods = "ALTER TABLE " + getTableName() + " ADD COLUMN " + COLUMN_REIMBURSABLE + " BOOLEAN DEFAULT 0"; Logger.debug(this, alterPaymentMethods); db.execSQL(alterPaymentMethods); } } PaymentMethodsTable(@NonNull SQLiteOpenHelper sqLiteOpenHelper,
                               @NonNull OrderingPreferencesManager orderingPreferencesManager); @Override synchronized void onCreate(@NonNull SQLiteDatabase db, @NonNull TableDefaultsCustomizer customizer); @Override synchronized void onUpgrade(@NonNull SQLiteDatabase db, int oldVersion, int newVersion, @NonNull TableDefaultsCustomizer customizer); }
PaymentMethodsTable extends AbstractSqlTable<PaymentMethod> { @Override public synchronized void onUpgrade(@NonNull SQLiteDatabase db, int oldVersion, int newVersion, @NonNull TableDefaultsCustomizer customizer) { super.onUpgrade(db, oldVersion, newVersion, customizer); if (oldVersion <= 11) { final String sql = "CREATE TABLE " + getTableName() + " (" + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_METHOD + " TEXT" + ");"; Logger.debug(this, sql); db.execSQL(sql); customizer.insertPaymentMethodDefaults(this); } if (oldVersion <= 14) { onUpgradeToAddSyncInformation(db, oldVersion, newVersion); } if (oldVersion <= 15) { final String addCustomOrderColumn = String.format("ALTER TABLE %s ADD COLUMN %s INTEGER DEFAULT 0", getTableName(), AbstractColumnTable.COLUMN_CUSTOM_ORDER_ID); Logger.debug(this, addCustomOrderColumn); db.execSQL(addCustomOrderColumn); } if (oldVersion <= 16) { if (!hasCustomOrderIdColumn(db)) { final String addCustomOrderColumn = String.format("ALTER TABLE %s ADD COLUMN %s INTEGER DEFAULT 0", getTableName(), AbstractColumnTable.COLUMN_CUSTOM_ORDER_ID); final String updateDefaultCustomOrder = String.format("UPDATE %s SET %s = ROWID", getTableName(), AbstractColumnTable.COLUMN_CUSTOM_ORDER_ID); Logger.debug(this, addCustomOrderColumn); Logger.debug(this, updateDefaultCustomOrder); db.execSQL(addCustomOrderColumn); db.execSQL(updateDefaultCustomOrder); } } if (oldVersion <= 18) { onUpgradeToAddUUID(db, oldVersion); } if (oldVersion <= 21) { final String alterPaymentMethods = "ALTER TABLE " + getTableName() + " ADD COLUMN " + COLUMN_REIMBURSABLE + " BOOLEAN DEFAULT 0"; Logger.debug(this, alterPaymentMethods); db.execSQL(alterPaymentMethods); } } PaymentMethodsTable(@NonNull SQLiteOpenHelper sqLiteOpenHelper,
                               @NonNull OrderingPreferencesManager orderingPreferencesManager); @Override synchronized void onCreate(@NonNull SQLiteDatabase db, @NonNull TableDefaultsCustomizer customizer); @Override synchronized void onUpgrade(@NonNull SQLiteDatabase db, int oldVersion, int newVersion, @NonNull TableDefaultsCustomizer customizer); static final String TABLE_NAME; static final String COLUMN_METHOD; static final String COLUMN_REIMBURSABLE; }