Add simple habit migration test
This commit is contained in:
parent
7ea2c1cf57
commit
a9ac2f27c2
4 changed files with 49 additions and 20 deletions
18
loop/habit_migrator.py
Normal file
18
loop/habit_migrator.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
def create_habits(db, trackers):
|
||||
print("migrating habits, yo")
|
||||
c = db.cursor()
|
||||
tracker = trackers["cigarette"]
|
||||
print(tracker)
|
||||
# for when the execute works, can be filled in its own function
|
||||
habit = (
|
||||
tracker["label"],
|
||||
0,
|
||||
0,
|
||||
tracker["id"],
|
||||
)
|
||||
c.execute(
|
||||
"""INSERT INTO
|
||||
Habits(id, name, position, type, uuid)
|
||||
VALUES (NULL, ?, ?, ?, ?)""",
|
||||
habit,
|
||||
)
|
||||
9
loop/migration.py
Normal file
9
loop/migration.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import loop.table_constructor as table_constructor
|
||||
import loop.habit_migrator as habit_migrator
|
||||
|
||||
|
||||
def migrate(trackers, events):
|
||||
db = table_constructor.prepare_database("output.db")
|
||||
if trackers is not None:
|
||||
habit_migrator.create_habits(db, trackers)
|
||||
db.commit()
|
||||
61
loop/table_constructor.py
Normal file
61
loop/table_constructor.py
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
import sqlite3
|
||||
|
||||
|
||||
def create_database(name):
|
||||
return sqlite3.connect(name)
|
||||
|
||||
|
||||
# better way to do the above
|
||||
# def create_connection(db_file):
|
||||
# """create a database connection to the SQLite database
|
||||
# specified by db_file
|
||||
# :param db_file: database file
|
||||
# :return: Connection object or None
|
||||
# """
|
||||
# conn = None
|
||||
# try:
|
||||
# conn = sqlite3.connect(db_file)
|
||||
# return conn
|
||||
# except Error as e:
|
||||
# print(e)
|
||||
# return conn
|
||||
|
||||
|
||||
def create_tables(db):
|
||||
c = db.cursor()
|
||||
c.execute(
|
||||
""" CREATE TABLE IF NOT EXISTS Habits (
|
||||
id integer PRIMARY KEY,
|
||||
archived integer,
|
||||
color integer,
|
||||
description text,
|
||||
freq_den integer,
|
||||
freq_num integer,
|
||||
highlight integer,
|
||||
name text NOT NULL,
|
||||
position integer UNIQUE,
|
||||
reminder_hour integer,
|
||||
reminder_min integer,
|
||||
reminder_days integer,
|
||||
type integer,
|
||||
target_type integer,
|
||||
target_value real,
|
||||
unit text,
|
||||
question text,
|
||||
uuid text NOT NULL
|
||||
); """
|
||||
)
|
||||
c.execute(
|
||||
""" CREATE TABLE IF NOT EXISTS Repetitions (
|
||||
id integer PRIMARY KEY,
|
||||
habit integer,
|
||||
timestamp integer,
|
||||
value integer
|
||||
); """
|
||||
)
|
||||
|
||||
|
||||
def prepare_database(name):
|
||||
db = create_database(name)
|
||||
create_tables(db)
|
||||
return db
|
||||
Loading…
Add table
Add a link
Reference in a new issue