composite-primary-keys / composite_primary_keys

Composite Primary Keys support for Active Record
1.03k stars 350 forks source link

Changing PK in existing table #609

Closed antarr closed 1 year ago

antarr commented 1 year ago

What would the migration look like to change the primary key on an existing table. My current table uses the standard id int. I need to user voter_uid and state_abbr.

CREATE TABLE public.voter_records (
    first_name character varying NOT NULL,
    last_name character varying NOT NULL,
    middle_name character varying DEFAULT ''::character varying NOT NULL,
    status character varying DEFAULT 'Active'::character varying NOT NULL,
    precinct_id bigint NOT NULL,
    id bigint NOT NULL,
    email public.citext DEFAULT ''::public.citext NOT NULL,
    state_abbr character varying NOT NULL,
    voter_uid character varying NOT NULL,
    address public.citext,
    dob date,
    party character varying,
    phone character varying
);
cfis commented 1 year ago

Run a sql migration that adds the new primary key.