Remove old database migrations; add missing ones

pull/312/head
Alinson S. Xavier 8 years ago
parent 0a5d565030
commit 71fe6137be

@ -76,4 +76,10 @@ public class BaseSQLiteOpenHelper extends SQLiteOpenHelper
throw new RuntimeException(e);
}
}
@Override
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
throw new UnsupportedDatabaseVersionException();
}
}

@ -0,0 +1,26 @@
/*
* Copyright (C) 2017 Álinson Santos Xavier <isoron@gmail.com>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package org.isoron.androidbase.storage;
public class UnsupportedDatabaseVersionException extends RuntimeException
{
}

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

@ -1,4 +1,4 @@
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);
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);

@ -1,5 +1,11 @@
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;
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;

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

@ -1,2 +0,0 @@
alter table habits add column reminder_hour integer;
alter table habits add column reminder_min integer;

@ -1 +0,0 @@
alter table habits add column highlight integer not null default 0;

@ -1 +0,0 @@
alter table habits add column archived integer not null default 0;

@ -0,0 +1,41 @@
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
);

@ -0,0 +1,54 @@
/*
* Copyright (C) 2017 Álinson Santos Xavier <isoron@gmail.com>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package org.isoron.uhabits;
import android.content.*;
import android.database.sqlite.*;
import org.isoron.androidbase.storage.*;
public class HabitsDatabaseOpener extends BaseSQLiteOpenHelper
{
private final int version;
public HabitsDatabaseOpener(Context context,
String databaseFilename,
int version)
{
super(context, databaseFilename, version);
this.version = version;
}
@Override
public void onCreate(SQLiteDatabase db)
{
onUpgrade(db, 8, version);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
if(oldVersion < 8) throw new UnsupportedDatabaseVersionException();
super.onUpgrade(db, oldVersion, newVersion);
}
}

@ -23,7 +23,6 @@ import android.content.*;
import android.database.sqlite.*;
import android.support.annotation.*;
import org.isoron.androidbase.storage.*;
import org.isoron.androidbase.utils.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.core.utils.*;
@ -35,7 +34,7 @@ import java.text.*;
public abstract class DatabaseUtils
{
@Nullable
private static BaseSQLiteOpenHelper helper = null;
private static HabitsDatabaseOpener opener = null;
public static void executeAsTransaction(Callback callback)
{
@ -83,7 +82,7 @@ public abstract class DatabaseUtils
{
try
{
helper = new BaseSQLiteOpenHelper(context, getDatabaseFilename(),
opener = new HabitsDatabaseOpener(context, getDatabaseFilename(),
BuildConfig.databaseVersion);
}
catch (RuntimeException e)
@ -113,13 +112,13 @@ public abstract class DatabaseUtils
@NonNull
public static SQLiteDatabase openDatabase()
{
if(helper == null) throw new IllegalStateException();
return helper.getWritableDatabase();
if(opener == null) throw new IllegalStateException();
return opener.getWritableDatabase();
}
public static void dispose()
{
helper = null;
opener = null;
}
public interface Callback

Loading…
Cancel
Save