#!/usr/local/bin/python2.7
# -*- coding: UTF-8 -*-
"""
Update from version 3 to version 4 of Yokadi DB

@author: Sébastien Renard <Sebastien.Renard@digitalfox.org>
@license: GPLv3
"""
import sys
from os.path import dirname, join

from sqlobject import connectionForURI, sqlhub, SQLObject, ForeignKey, StringCol


""" This is the v4 table """
class Recurrence(SQLObject):
    rule = StringCol(default="", notNone=True)

""" This is a fake table (we only need table name) """
class Task(SQLObject):
    pass

def createRecurrenceTable():
    Recurrence.createTable()

def alterTaskTable():
    Task.sqlmeta.addColumn(ForeignKey("Recurrence", default=None))

def removeDefaultProject():
    sqlhub.processConnection.query("delete from config where name='DEFAULT_PROJECT'")

def main():
    sqlhub.processConnection = connectionForURI('sqlite:' + sys.argv[1])
    createRecurrenceTable()
    alterTaskTable()
    removeDefaultProject()

if __name__ == "__main__":
    main()
# vi: ts=4 sw=4 et
