"""Add version column to wordpress_site table.

Mirrors imav/migrations/017_add_version_field.py so that fresh installs
get the complete schema from core alone. The database.get_columns()
guard makes this idempotent on existing installs where imav/017 already
added the column.

Rollback is a no-op because imav/017 owns the actual schema undo.
"""

from peewee import CharField


def migrate(migrator, database, fake=False, **kwargs):
    if fake:
        return
    columns = [col.name for col in database.get_columns("wordpress_site")]
    if "version" not in columns:
        WordpressSite = migrator.orm["wordpress_site"]
        migrator.add_columns(
            WordpressSite, version=CharField(default="1.0.0", null=False)
        )


def rollback(migrator, database, fake=False, **kwargs):
    pass
