mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Implement database access (with migrations)
This commit is contained in:
0
core/assets/main/migrations/001.sql
Normal file
0
core/assets/main/migrations/001.sql
Normal file
0
core/assets/main/migrations/002.sql
Normal file
0
core/assets/main/migrations/002.sql
Normal file
0
core/assets/main/migrations/003.sql
Normal file
0
core/assets/main/migrations/003.sql
Normal file
0
core/assets/main/migrations/004.sql
Normal file
0
core/assets/main/migrations/004.sql
Normal file
0
core/assets/main/migrations/005.sql
Normal file
0
core/assets/main/migrations/005.sql
Normal file
0
core/assets/main/migrations/006.sql
Normal file
0
core/assets/main/migrations/006.sql
Normal file
0
core/assets/main/migrations/007.sql
Normal file
0
core/assets/main/migrations/007.sql
Normal file
0
core/assets/main/migrations/008.sql
Normal file
0
core/assets/main/migrations/008.sql
Normal file
5
core/assets/main/migrations/009.sql
Normal file
5
core/assets/main/migrations/009.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
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 )
|
||||
3
core/assets/main/migrations/010.sql
Normal file
3
core/assets/main/migrations/010.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
delete from Score
|
||||
delete from Streak
|
||||
delete from Checkmarks
|
||||
1
core/assets/main/migrations/011.sql
Normal file
1
core/assets/main/migrations/011.sql
Normal file
@@ -0,0 +1 @@
|
||||
alter table Habits add column reminder_days integer not null default 127
|
||||
3
core/assets/main/migrations/012.sql
Normal file
3
core/assets/main/migrations/012.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
delete from Score
|
||||
delete from Streak
|
||||
delete from Checkmarks
|
||||
4
core/assets/main/migrations/013.sql
Normal file
4
core/assets/main/migrations/013.sql
Normal file
@@ -0,0 +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)
|
||||
14
core/assets/main/migrations/014.sql
Normal file
14
core/assets/main/migrations/014.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
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
|
||||
3
core/assets/main/migrations/015.sql
Normal file
3
core/assets/main/migrations/015.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
delete from Score
|
||||
delete from Streak
|
||||
delete from Checkmarks
|
||||
2
core/assets/main/migrations/016.sql
Normal file
2
core/assets/main/migrations/016.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
alter table Habits add column type integer not null default 0
|
||||
alter table Repetitions add column value integer not null default 2
|
||||
5
core/assets/main/migrations/017.sql
Normal file
5
core/assets/main/migrations/017.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
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
|
||||
3
core/assets/main/migrations/018.sql
Normal file
3
core/assets/main/migrations/018.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
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 ""
|
||||
1
core/assets/main/migrations/019.sql
Normal file
1
core/assets/main/migrations/019.sql
Normal file
@@ -0,0 +1 @@
|
||||
create table Events ( id integer primary key autoincrement, timestamp integer, message text, server_id integer )
|
||||
3
core/assets/main/migrations/020.sql
Normal file
3
core/assets/main/migrations/020.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
drop table checkmarks
|
||||
drop table streak
|
||||
drop table score
|
||||
12
core/assets/main/migrations/021.sql
Normal file
12
core/assets/main/migrations/021.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
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
|
||||
11
core/assets/main/migrations/022.sql
Normal file
11
core/assets/main/migrations/022.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
delete from repetitions where habit not in (select id from habits)
|
||||
delete from repetitions where timestamp is null
|
||||
delete from repetitions where habit is null
|
||||
delete from repetitions where rowid not in ( select min(rowid) from repetitions group by habit, timestamp )
|
||||
alter table Repetitions rename to RepetitionsBak
|
||||
create table Repetitions ( id integer primary key autoincrement, habit integer not null references habits(id), timestamp integer not null, value integer not null)
|
||||
drop index if exists idx_repetitions_habit_timestamp
|
||||
create unique index idx_repetitions_habit_timestamp on Repetitions( habit, timestamp)
|
||||
insert into Repetitions select * from RepetitionsBak
|
||||
drop table RepetitionsBak
|
||||
pragma foreign_keys=ON
|
||||
Reference in New Issue
Block a user