Last active
May 11, 2025 08:13
-
-
Save ivan/d13fa94c94487335973a2b96795b9bcf to your computer and use it in GitHub Desktop.
Recreating all of your PostgreSQL periods history tables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- for each table | |
psql --quiet --no-psqlrc --echo-errors -c "COPY rgp.accessions_history TO STDOUT" > accessions.tsv | |
SELECT periods.drop_system_versioning('rgp.accessions'); | |
DROP TABLE rgp.accessions_history; | |
-- once | |
DROP EXTENSION periods CASCADE; | |
CREATE EXTENSION periods; | |
-- for each table | |
SELECT periods.add_system_time_period('rgp.accessions', 'row_start', 'row_end'); | |
SELECT periods.add_system_versioning('rgp.accessions'); -- create the _history table... | |
SELECT periods.drop_system_versioning('rgp.accessions'); -- allow us to GRANT in the next line | |
GRANT INSERT ON TABLE rgp.accessions_history TO CURRENT_USER; -- allow \copy to work | |
\copy rgp.accessions_history FROM 'accessions.tsv'; | |
SELECT periods.add_system_versioning('rgp.accessions'); |
Linked from xocolatl/periods#22
Update: no need to dump and recreate the data in the _history
tables; just periods.drop_system_versioning
on all the versioned tables, drop the extension, create the extension, then periods.add_system_time_period
and periods.add_system_versioning
on the tables which should be versioned.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
YMMV, don't do anything from here without backups.