Move database migrations to uhabits-core

This commit is contained in:
2017-06-20 21:43:47 -04:00
parent ecb5352134
commit 6dd7e49112
19 changed files with 36 additions and 100 deletions

View File

@@ -1,3 +0,0 @@
delete from Score;
delete from Streak;
delete from Checkmarks;

View File

@@ -1 +0,0 @@
alter table Habits add column reminder_days integer not null default 127;

View File

@@ -1,3 +0,0 @@
delete from Score;
delete from Streak;
delete from Checkmarks;

View File

@@ -1,4 +0,0 @@
create index idx_score_habit_timestamp on Score(habit, timestamp);
create index idx_checkmark_habit_timestamp on Checkmarks(habit, timestamp);
create index idx_repetitions_habit_timestamp on Repetitions(habit, timestamp);
create index idx_streak_habit_end on Streak(habit, end);

View File

@@ -1,14 +0,0 @@
update habits set color=0 where color=-2937041;
update habits set color=1 where color=-1684967;
update habits set color=2 where color=-415707;
update habits set color=3 where color=-5262293;
update habits set color=4 where color=-13070788;
update habits set color=5 where color=-16742021;
update habits set color=6 where color=-16732991;
update habits set color=7 where color=-16540699;
update habits set color=8 where color=-10603087;
update habits set color=9 where color=-7461718;
update habits set color=10 where color=-2614432;
update habits set color=11 where color=-13619152;
update habits set color=12 where color=-5592406;
update habits set color=0 where color<0 or color>12;

View File

@@ -1,3 +0,0 @@
delete from Score;
delete from Streak;
delete from Checkmarks;

View File

@@ -1,2 +0,0 @@
alter table Habits add column type integer not null default 0;
alter table Repetitions add column value integer not null default 2;

View File

@@ -1,11 +0,0 @@
drop table Score;
create table Score (
id integer primary key autoincrement,
habit integer references habits(id),
score real,
timestamp integer);
create index idx_score_habit_timestamp on Score(habit, timestamp);
delete from streak;
delete from checkmarks;

View File

@@ -1,3 +0,0 @@
alter table Habits add column target_type integer not null default 0;
alter table Habits add column target_value real not null default 0;
alter table Habits add column unit text not null default "";

View File

@@ -1,6 +0,0 @@
create table Events (
id integer primary key autoincrement,
timestamp integer,
message text,
server_id integer
);

View File

@@ -1,3 +0,0 @@
drop table checkmarks;
drop table streak;
drop table score;

View File

@@ -1,12 +0,0 @@
update habits set color=19 where color=12;
update habits set color=17 where color=11;
update habits set color=15 where color=10;
update habits set color=14 where color=9;
update habits set color=13 where color=8;
update habits set color=10 where color=7;
update habits set color=9 where color=6;
update habits set color=8 where color=5;
update habits set color=7 where color=4;
update habits set color=5 where color=3;
update habits set color=4 where color=2;
update habits set color=0 where color<0 or color>19;

View File

@@ -1,41 +0,0 @@
create table Habits (
id integer primary key autoincrement,
archived integer,
color integer,
description text,
freq_den integer,
freq_num integer,
highlight integer,
name text,
position integer,
reminder_hour integer,
reminder_min integer
);
create table Checkmarks (
id integer primary key autoincrement,
habit integer references habits(id),
timestamp integer,
value integer
);
create table Repetitions (
id integer primary key autoincrement,
habit integer references habits(id),
timestamp integer
);
create table Streak (
id integer primary key autoincrement,
end integer,
habit integer references habits(id),
length integer,
start integer
);
create table Score (
id integer primary key autoincrement,
habit integer references habits(id),
score integer,
timestamp integer
);

View File

@@ -27,11 +27,8 @@ import android.database.sqlite.*;
import org.isoron.androidbase.*;
import org.isoron.uhabits.core.db.*;
import java.io.*;
public class BaseSQLiteOpenHelper extends SQLiteOpenHelper
implements MigrationHelper.FileOpener
{
private final Context context;
@@ -50,7 +47,7 @@ public class BaseSQLiteOpenHelper extends SQLiteOpenHelper
public void onCreate(SQLiteDatabase db)
{
MigrationHelper helper =
new MigrationHelper(this, new AndroidSQLiteDatabase(db));
new MigrationHelper(new AndroidSQLiteDatabase(db));
helper.executeMigrations(-1, version);
}
@@ -58,7 +55,7 @@ public class BaseSQLiteOpenHelper extends SQLiteOpenHelper
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
MigrationHelper helper =
new MigrationHelper(this, new AndroidSQLiteDatabase(db));
new MigrationHelper(new AndroidSQLiteDatabase(db));
helper.executeMigrations(oldVersion, newVersion);
}
@@ -67,17 +64,4 @@ public class BaseSQLiteOpenHelper extends SQLiteOpenHelper
{
throw new UnsupportedDatabaseVersionException();
}
@Override
public InputStream open(String filename)
{
try
{
return context.getAssets().open(filename);
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
}