Cleanup database migration script
This commit is contained in:
parent
6552b1248f
commit
6bdf37e91a
|
|
@ -5,23 +5,20 @@ create table if not exists people (
|
|||
created_by uuid NOT NULL,
|
||||
updated_at timestamp without time zone NOT NULL DEFAULT now(),
|
||||
updated_by uuid NOT NULL,
|
||||
email text NOT NULL,
|
||||
email text NOT NULL unique,
|
||||
name text NOT NULL,
|
||||
family_name text NOT NULL,
|
||||
given_name text NOT NULL
|
||||
given_name text NOT NULL,
|
||||
CONSTRAINT people_pkey PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
ALTER TABLE
|
||||
people
|
||||
ADD
|
||||
CONSTRAINT people_pkey PRIMARY KEY (id);
|
||||
|
||||
ALTER TABLE if exists users
|
||||
ADD COLUMN person_id uuid REFERENCES people (id) ON DELETE SET NULL;
|
||||
ADD COLUMN IF NOT EXISTS person_id uuid REFERENCES people (id) ON DELETE SET NULL;
|
||||
|
||||
-- Copy accounts(users) to profiles(people)
|
||||
insert into people (created_by, updated_by, email, name, family_name, given_name)
|
||||
select created_by, updated_by, email, name, family_name, given_name from users;
|
||||
select created_by, updated_by, email, name, family_name, given_name from users
|
||||
on conflict do nothing;
|
||||
|
||||
-- Link accounts to profiles
|
||||
update users u set person_id = p.id from people p where p.email = u.email;
|
||||
|
|
|
|||
Loading…
Reference in New Issue