CREATE TABLE IF NOT EXISTS instance_settings (
    id INTEGER PRIMARY KEY CHECK(id = 1),
    setup_completed_at TEXT,
    signups_enabled INTEGER NOT NULL DEFAULT 0 CHECK(signups_enabled IN (0, 1)),
    updated_at TEXT NOT NULL
);

INSERT OR IGNORE INTO instance_settings (id, setup_completed_at, signups_enabled, updated_at)
SELECT
    1,
    CASE WHEN EXISTS(SELECT 1 FROM users) THEN datetime('now') ELSE NULL END,
    CASE WHEN EXISTS(SELECT 1 FROM users) THEN 1 ELSE 0 END,
    datetime('now');
