Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE apple_mapping_dev0210x
- (
- id BIGSERIAL PRIMARY KEY NOT NULL,
- entity_uuid UUID,
- entity_type INTEGER,
- external_id VARCHAR(128),
- is_deleted BOOLEAN,
- created_at TIMESTAMP,
- updated_at TIMESTAMP
- );
- INSERT INTO apple_mapping_dev0210x (
- id,
- entity_uuid,
- entity_type,
- external_id,
- is_deleted,
- created_at,
- updated_at
- )(
- SELECT
- id,
- entity_uuid,
- entity_type,
- external_id,
- true,
- now(),
- now()
- FROM apple_mapping
- );
- -- THE easiest way to ensure the ALTER statements below work
- DROP TABLE apple_mapping_dev0210;
- ALTER TABLE apple_mapping_dev0210x RENAME TO apple_mapping_dev0210;
- ALTER SEQUENCE apple_mapping_dev0210x_id_seq
- RENAME TO apple_mapping_dev0210_id_seq;
- SELECT setval('apple_mapping_dev0210_id_seq' :: REGCLASS,
- (SELECT max(id) FROM apple_mapping) :: BIGINT);
- ALTER TABLE apple_mapping_dev0210 ALTER COLUMN id
- SET DEFAULT nextval('apple_mapping_dev0210_id_seq' :: REGCLASS);
- -- do this at the end of the processing
- -- when all the stuff gets ready
- CREATE UNIQUE INDEX apple_mapping_dev0210_external_id_entity_type_idx ON apple_mapping_dev0210 (entity_type, external_id);
- CREATE INDEX apple_mapping_dev0210_stuff0_idx ON apple_mapping_dev0210 (entity_uuid, is_deleted);
- CREATE INDEX apple_mapping_dev0210_entity_uuid_idx ON apple_mapping_dev0210 (entity_uuid);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement