BEGIN;

-- 已启用限制的店铺属于有效配置事实，存在时禁止删列回滚。
DO $$
BEGIN
    IF to_regclass('tb_shop') IS NULL
       OR NOT EXISTS (
           SELECT 1
           FROM pg_attribute
           WHERE attrelid = to_regclass('tb_shop')
             AND attname = 'client_login_disabled'
             AND NOT attisdropped
       ) THEN
        RETURN;
    END IF;

    LOCK TABLE tb_shop IN ACCESS EXCLUSIVE MODE;
    IF EXISTS (SELECT 1 FROM tb_shop WHERE client_login_disabled = true LIMIT 1) THEN
        RAISE EXCEPTION 'tb_shop 已存在C端登录限制配置，禁止删列回滚，请保留字段并向前修复';
    END IF;

    ALTER TABLE tb_shop DROP COLUMN client_login_disabled;
END
$$;

COMMIT;
