-- +goose Up
-- +goose StatementBegin

-- Converte ip de inet para TEXT (suporta "manual:userId" além de IPs reais)
-- e adiciona coluna origem para rastrear se foi auto/manual/pwa
ALTER TABLE registros_ponto
    ALTER COLUMN ip TYPE TEXT USING ip::text,
    ALTER COLUMN ip SET DEFAULT '',
    ADD COLUMN IF NOT EXISTS origem TEXT NOT NULL DEFAULT 'auto'
        CHECK (origem IN ('auto','manual','pwa','integracao'));

-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin
ALTER TABLE registros_ponto
    DROP COLUMN IF EXISTS origem,
    ALTER COLUMN ip TYPE INET USING ip::inet;
-- +goose StatementEnd
