do $$
begin
    if not exists (
        select 1
        from pg_attrdef def
        join pg_class t on def.adrelid = t.oid
        join pg_namespace n on n.oid = t.relnamespace
        join pg_attribute a on a.attrelid = t.oid and a.attnum = def.adnum
        where t.relname = 't_schet_act_item'
          and n.nspname = 'ies'
          and a.attname = 'bymek'
    ) then
        alter table ies.t_schet_act_item
        alter column bymek set default false;
    end if;

    if exists (
        select 1
        from information_schema.columns
        where table_schema = 'ies'
          and table_name = 't_schet_act_item'
          and column_name = 'bymek'
          and is_nullable = 'YES'
    ) then
        update ies.t_schet_act_item
        set bymek = false
        where bymek is null;

        alter table ies.t_schet_act_item
        alter column bymek set not null;
    end if;
end $$;