# Path: kittystore/storm/schema/utils.py
# def get_db_type(store):
#     database = store.get_database()
#     return database.__class__.__module__.split(".")[-1]


from .utils import get_db_type
# -*- coding: utf-8 -*-

from __future__ import absolute_import



SQL = {
    "sqlite": [
        'ALTER TABLE "email" ADD COLUMN "timezone" INTEGER NOT NULL DEFAULT 0;',
        ],
    "postgres": [
        'ALTER TABLE "email" ADD COLUMN "timezone" INTEGER;',
        'UPDATE "email" SET "timezone" = EXTRACT(TIMEZONE_MINUTE FROM date)',
        'UPDATE "email" SET date = date AT TIME ZONE \'UTC\';',
        'ALTER TABLE "email" ALTER COLUMN "date" TYPE TIMESTAMP WITHOUT TIME ZONE;',
        'ALTER TABLE "email" ALTER COLUMN "timezone" SET NOT NULL;',
        'ALTER TABLE "thread" ALTER COLUMN "date_active" TYPE TIMESTAMP WITHOUT TIME ZONE;',
        ],
    "mysql": [],
    }


def apply(store):
    """Add the thread table"""

# Path: kittystore/storm/schema/utils.py
# def get_db_type(store):
#     database = store.get_database()
#     return database.__class__.__module__.split(".")[-1]


# Path: kittystore/storm/schema/patch_3.py
from .utils import get_db_type

# -*- coding: utf-8 -*-

from __future__ import absolute_import



SQL = {
    "sqlite": [
        'ALTER TABLE "email" ADD COLUMN "timezone" INTEGER NOT NULL DEFAULT 0;',
        ],
    "postgres": [
        'ALTER TABLE "email" ADD COLUMN "timezone" INTEGER;',
        'UPDATE "email" SET "timezone" = EXTRACT(TIMEZONE_MINUTE FROM date)',
        'UPDATE "email" SET date = date AT TIME ZONE \'UTC\';',
        'ALTER TABLE "email" ALTER COLUMN "date" TYPE TIMESTAMP WITHOUT TIME ZONE;',
        'ALTER TABLE "email" ALTER COLUMN "timezone" SET NOT NULL;',
        'ALTER TABLE "thread" ALTER COLUMN "date_active" TYPE TIMESTAMP WITHOUT TIME ZONE;',
        ],
    "mysql": [],
    }


def apply(store):
    """Add the thread table"""

    dbtype = get_db_type(store)