DO $$
BEGIN
    IF NOT EXISTS (
        SELECT 1
        FROM vclib.t_entities
        WHERE baseentity = (
            SELECT entityid
            FROM vclib.t_entities
            WHERE entname = 'NEWS_BOX' AND "schema" = 'VCLib'
        )
    ) THEN
        ALTER TABLE vclib.t_news_box DROP CONSTRAINT IF EXISTS fk_t_entities_t_news_box_type_;
        ALTER TABLE vclib.t_news_box DROP COLUMN IF EXISTS type_;
    END IF;
END $$;