-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure _revision_expired is always > _revision_created #121
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8965e1c
Ensure _revision_expired is always > _revision_created
strk 2d1f12e
Add test for exception on update of a revision-disordered table
strk e737df9
Give expired_after_created a controlled name
strk ae0ff36
Add expired_after_created check to pre-existing tables, if any
strk 0b07910
Merge branch 'master' into expired_after_created
l0b0 d69997c
Merge branch 'master' into expired_after_created
l0b0 b1e4d04
Merge branch 'master' into expired_after_created
l0b0 2d2609d
Merge branch 'master' into expired_after_created
l0b0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,7 @@ BEGIN | |
'CREATE TABLE ' || v_revision_table || '(' || | ||
'_revision_created INTEGER NOT NULL,' || | ||
'_revision_expired INTEGER,' || | ||
'CONSTRAINT expired_after_created CHECK ( _revision_created < _revision_expired ), ' || | ||
'LIKE ' || v_table_oid::text || | ||
');'; | ||
BEGIN | ||
|
@@ -245,3 +246,64 @@ $$ LANGUAGE plpgsql; | |
DROP EVENT TRIGGER IF EXISTS _ver_abort_drop_of_versioned_table; | ||
CREATE EVENT TRIGGER _ver_abort_drop_of_versioned_table | ||
ON sql_drop EXECUTE PROCEDURE _ver_abort_drop_of_versioned_table(); | ||
|
||
-- | ||
-- Fix existing revision table definitions if coming from a version prior to 1.8.0 | ||
-- | ||
-- WARNING: this needs to be sourced _before_ the script defining | ||
-- ver_version() function | ||
-- { | ||
DO $$ | ||
DECLARE | ||
old_version TEXT; | ||
rec RECORD; | ||
sql TEXT; | ||
BEGIN | ||
BEGIN | ||
-- version can be in the form '1.3.3 more-info-here' | ||
old_version := regexp_replace( | ||
regexp_replace(@[email protected]_version(), ' .*', ''), | ||
'[^0-9.].*', '' | ||
); | ||
EXCEPTION WHEN undefined_function THEN | ||
RAISE DEBUG 'ver_version not available, ' | ||
'we are either doing a new install ' | ||
'or coming from version before 1.3'; | ||
END; | ||
|
||
RAISE WARNING 'OLD VERSION IS %', old_version; | ||
|
||
-- We only need to update table definitions when coming | ||
-- from versions 1.7 or earlier. | ||
-- NOTE: coming from 1.8.0dev won't update triggers | ||
IF ( string_to_array(old_version, '.')::int[] >= ARRAY[1,8,0] ) | ||
THEN | ||
RETURN; | ||
END IF; | ||
|
||
-- We only need to update table definitions when any table | ||
-- is known as versioned. NOTE: we do this before using | ||
-- functions that may not even be present in the database | ||
-- (as it happens on first install) | ||
-- | ||
IF ( NOT EXISTS ( SELECT * FROM @[email protected]_tables ) ) | ||
THEN | ||
RETURN; | ||
END IF; | ||
|
||
RAISE NOTICE 'Updating definition of revision tables'; | ||
FOR rec IN | ||
SELECT | ||
@[email protected]_get_version_table_full(schema_name, table_name) | ||
AS rt | ||
FROM @[email protected]_get_versioned_tables() | ||
LOOP | ||
sql := format('ALTER TABLE %s ADD CONSTRAINT expired_after_created ' | ||
'CHECK ( _revision_created < _revision_expired)', | ||
rec.rt); | ||
RAISE DEBUG 'Executing %', sql; | ||
EXECUTE sql; | ||
END LOOP; | ||
END | ||
$$ LANGUAGE 'plpgsql'; | ||
--} |
This file contains 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need an
OR _revision_expired IS NULL
check?