CREATE TABLE ticket_part_1 () INHERITS (ticket);
ALTER TABLE ticket_part_1 ADD CONSTRAINT partition_check CHECK (purchase_timestamp < 2022-09-14 21:51:18.872183+03);
INSERT INTO ticket_part_1 (ticket_id, session_id, seat_id, purchase_timestamp)
SELECT *
FROM ticket
WHERE purchase_timestamp < '2022-09-14 21:51:18.872183+03';
DELETE FROM ONLY ticket WHERE purchase_timestamp < '2022-09-14 21:51:18.872183+03';
ALTER TABLE order_to_ticket DROP CONSTRAINT ticket_fk;
CREATE TABLE ticket_part_1 () INHERITS (ticket);
ALTER TABLE ticket_part_1 ADD CONSTRAINT partition_check CHECK (purchase_timestamp < '2022-09-14 21:51:18.872183+03');
INSERT INTO ticket_part_1 (ticket_id, session_id, seat_id, purchase_timestamp)
SELECT *
FROM ticket
WHERE purchase_timestamp < '2022-09-14 21:51:18.872183+03';
DELETE FROM ONLY ticket WHERE purchase_timestamp < '2022-09-14 21:51:18.872183+03';
ALTER TABLE ONLY order_to_ticket
ADD CONSTRAINT ticket_fk FOREIGN KEY (ticket_id) REFERENCES ticket(ticket_id) NOT VALID;
ALTER TABLE ticket RENAME TO ticket_part_default;
CREATE TABLE ticket (LIKE ticket_part_default);
ALTER TABLE ticket_part_default INHERIT ticket;
...