-- +goose Up
-- +goose StatementBegin
CREATE TABLE IF NOT EXISTS tenants(
    id bigserial PRIMARY KEY,
    user_id bigint NOT NULL,
    code varchar(64) NOT NULL,
    uuid uuid NOT NULL,
    name varchar(128) NOT NULL DEFAULT '',
    status varchar(64) NOT NULL DEFAULT '',
    config jsonb NOT NULL DEFAULT '{}'::jsonb,
    expired_at timestamptz,
    created_at timestamptz NOT NULL DEFAULT now(),
    updated_at timestamptz NOT NULL DEFAULT now()
);

CREATE UNIQUE INDEX IF NOT EXISTS ux_tenants_code_lower ON tenants(lower(code));

CREATE UNIQUE INDEX IF NOT EXISTS ux_tenants_uuid ON tenants(uuid);

-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
DROP INDEX IF EXISTS ux_tenants_uuid;

DROP INDEX IF EXISTS ux_tenants_code_lower;

DROP TABLE IF EXISTS tenants;

-- +goose StatementEnd
