TRUNCATE recruit_extract;

ALTER TABLE recruit_extract
    ALTER COLUMN id TYPE uuid USING id::uuid;
ALTER TABLE recruit_extract
    ALTER COLUMN format TYPE int4 USING format::int4;
ALTER TABLE recruit_extract
    ALTER COLUMN status TYPE varchar(30);
ALTER TABLE recruit_extract
    ALTER COLUMN id_ern TYPE varchar(50);
ALTER TABLE recruit_extract
    ADD COLUMN IF NOT EXISTS method varchar(20);
ALTER TABLE recruit_extract
    DROP COLUMN IF EXISTS series;
ALTER TABLE recruit_extract
    DROP COLUMN IF EXISTS number;
ALTER TABLE recruit_extract
    ALTER COLUMN recruit_id TYPE uuid USING recruit_id::uuid;
ALTER TABLE recruit_extract
    ADD COLUMN IF NOT EXISTS recruit_info jsonb;
ALTER TABLE recruit_extract
    DROP COLUMN IF EXISTS user_id;
ALTER TABLE recruit_extract
    DROP COLUMN IF EXISTS full_name;
ALTER TABLE recruit_extract
    DROP COLUMN IF EXISTS name_vk;
ALTER TABLE recruit_extract
    ADD COLUMN IF NOT EXISTS signer_info jsonb;
ALTER TABLE recruit_extract
    DROP COLUMN IF EXISTS file_name;
ALTER TABLE recruit_extract
    DROP COLUMN IF EXISTS s3url;
ALTER TABLE recruit_extract
    ADD COLUMN IF NOT EXISTS file_info jsonb;

CREATE INDEX IF NOT EXISTS recruit_extract_id_ern_idx ON recruit_extract (id_ern);
CREATE INDEX IF NOT EXISTS recruit_extract_date_idx ON recruit_extract (date);
CREATE INDEX IF NOT EXISTS recruit_extract_format_idx ON recruit_extract (format);
CREATE INDEX IF NOT EXISTS recruit_extract_method_idx ON recruit_extract (method);
CREATE INDEX IF NOT EXISTS recruit_extract_status_idx ON recruit_extract (status);
