"""Peewee migrations -- 175_MAIN.py.

Add email fields for company, facility and construction site.
"""

from contextlib import suppress

import peewee as pw
from peewee_migrate import Migrator


with suppress(ImportError):
    import playhouse.postgres_ext as pw_pext


def migrate(migrator: Migrator, database: pw.Database, *, fake=False):
    """Write your migrations here."""

    migrator.add_fields(
        'constructionsite',

        email=pw.TextField(null=True))

    migrator.add_fields(
        'setup',

        company_email=pw.TextField(null=True))

    migrator.add_fields(
        'setup',

        facility_email=pw.TextField(null=True))


def rollback(migrator: Migrator, database: pw.Database, *, fake=False):
    """Write your rollback migrations here."""

    migrator.remove_fields('setup', 'facility_email')

    migrator.remove_fields('setup', 'company_email')

    migrator.remove_fields('constructionsite', 'email')
