Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
gfx committed Oct 29, 2018
1 parent cc8d4a5 commit 0e2506f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.util.SparseArray;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
* <p>
* Version based, step-by-step migration engine with {@link Database#getVersion()},
Expand Down Expand Up @@ -103,10 +104,12 @@ public void start(@NonNull Database db, @NonNull List<? extends MigrationSchema>

if (dbVersion == 0) {
db.setVersion(version);
trace("set version from 0 to %d", version);
return;
}

if (dbVersion == version) {
trace("nothing tdo (version=%d)", version);
return;
}

Expand Down Expand Up @@ -196,6 +199,7 @@ public void saveStep(@NonNull Database db, int version, @Nullable String sql) {
values.put(kSql, sql);
db.insertOrThrow(MIGRATION_STEPS_TABLE, null, values);
db.setVersion(version);
trace("set version to %d, creating a migration log for %s", version, sql);
}

public void execStep(@NonNull Database db, int version, @Nullable String sql) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@

@RunWith(AndroidJUnit4.class)
public class Issue436_ManualStepMigrationNotInvoked {
static {
System.setProperty("robolectric.logging", "stderr");
}

Context getContext() {
return ApplicationProvider.getApplicationContext();
Expand All @@ -48,14 +51,15 @@ Database createDatabase() {

@Test
public void invokedWithoutSteps() {
int initialVersion = 2;
int secondVersion = 5;
int initialVersion = 5;
int secondVersion = 7;

Database db = createDatabase();
new ManualStepMigration(getContext(), initialVersion, true)
.start(db, new ArrayList<SchemaData>());
assertThat(db.getVersion(), is(initialVersion));


ManualStepMigration m = new ManualStepMigration(getContext(), secondVersion, true);
m.start(db, new ArrayList<SchemaData>());
assertThat(db.getVersion(), is(secondVersion));
Expand All @@ -65,8 +69,8 @@ public void invokedWithoutSteps() {

@Test
public void invokedWithSteps() {
int initialVersion = 2;
int secondVersion = 5;
int initialVersion = 1;
int secondVersion = 3;

Database db = createDatabase();
new ManualStepMigration(getContext(), initialVersion, true)
Expand Down

0 comments on commit 0e2506f

Please sign in to comment.