-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5aefa3
commit e84b9dd
Showing
3 changed files
with
292 additions
and
112 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture() | ||
def sesh_with_basics(schema_name, sesh_in_prepared_schema_left): | ||
sesh = sesh_in_prepared_schema_left | ||
sesh.execute(f"SET search_path TO {schema_name}, public") | ||
yield sesh_in_prepared_schema_left | ||
|
||
|
||
@pytest.fixture() | ||
def sesh_with_test_tables(sesh_with_basics): | ||
sesh = sesh_with_basics | ||
sesh.execute( | ||
""" | ||
CREATE TABLE a ( | ||
-- Main attributes | ||
a_id SERIAL PRIMARY KEY, | ||
x INTEGER, | ||
-- History-related attributes | ||
mod_time timestamp WITHOUT TIME ZONE NOT NULL DEFAULT NOW(), | ||
mod_user character varying(64) COLLATE pg_catalog."default" NOT NULL DEFAULT CURRENT_USER | ||
); | ||
CREATE TRIGGER t100_primary_control_hx_cols | ||
BEFORE INSERT OR DELETE OR UPDATE | ||
ON a | ||
FOR EACH ROW | ||
EXECUTE FUNCTION hxtk_primary_control_hx_cols(); | ||
CREATE TRIGGER t100_primary_ops_to_hx | ||
AFTER INSERT OR DELETE OR UPDATE | ||
ON a | ||
FOR EACH ROW | ||
EXECUTE FUNCTION hxtk_primary_ops_to_hx(); | ||
CREATE TABLE b ( | ||
-- Main attributes | ||
b_id SERIAL PRIMARY KEY, | ||
a_id INTEGER REFERENCES a (a_id), | ||
y INTEGER, | ||
-- History-related attributes | ||
mod_time timestamp WITHOUT TIME ZONE NOT NULL DEFAULT NOW(), | ||
mod_user character varying(64) COLLATE pg_catalog."default" NOT NULL DEFAULT CURRENT_USER | ||
); | ||
CREATE TRIGGER t100_primary_control_hx_cols | ||
BEFORE INSERT OR DELETE OR UPDATE | ||
ON b | ||
FOR EACH ROW | ||
EXECUTE FUNCTION hxtk_primary_control_hx_cols(); | ||
CREATE TRIGGER t100_primary_ops_to_hx | ||
AFTER INSERT OR DELETE OR UPDATE | ||
ON b | ||
FOR EACH ROW | ||
EXECUTE FUNCTION hxtk_primary_ops_to_hx(); | ||
CREATE TABLE c ( | ||
-- Main attributes | ||
c_id SERIAL PRIMARY KEY, | ||
a_id INTEGER REFERENCES a (a_id), | ||
b_id INTEGER REFERENCES b (b_id), | ||
z INTEGER, | ||
-- History-related attributes | ||
mod_time timestamp WITHOUT TIME ZONE NOT NULL DEFAULT NOW(), | ||
mod_user character varying(64) COLLATE pg_catalog."default" NOT NULL DEFAULT CURRENT_USER | ||
); | ||
CREATE TRIGGER t100_primary_control_hx_cols | ||
BEFORE INSERT OR DELETE OR UPDATE | ||
ON c | ||
FOR EACH ROW | ||
EXECUTE FUNCTION hxtk_primary_control_hx_cols(); | ||
CREATE TRIGGER t100_primary_ops_to_hx | ||
AFTER INSERT OR DELETE OR UPDATE | ||
ON c | ||
FOR EACH ROW | ||
EXECUTE FUNCTION hxtk_primary_ops_to_hx(); | ||
-- History tables | ||
CREATE TABLE a_hx ( | ||
a_id INTEGER, | ||
x INTEGER, | ||
mod_time timestamp WITHOUT TIME ZONE NOT NULL DEFAULT NOW(), | ||
mod_user character varying(64) COLLATE pg_catalog."default" NOT NULL DEFAULT CURRENT_USER, | ||
-- History columns | ||
deleted BOOLEAN NOT NULL DEFAULT FALSE, | ||
a_hx_id INTEGER PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY | ||
-- Foreign key columns (none in this table) | ||
); | ||
CREATE TABLE b_hx ( | ||
-- Must parallel primary table cols: $1.* (NEW.*/OLD.*) | ||
b_id INTEGER, | ||
a_id INTEGER, | ||
y INTEGER, | ||
mod_time timestamp WITHOUT TIME ZONE NOT NULL DEFAULT NOW(), | ||
mod_user character varying(64) COLLATE pg_catalog."default" NOT NULL DEFAULT CURRENT_USER, | ||
-- History columns | ||
deleted BOOLEAN NOT NULL DEFAULT FALSE, | ||
b_hx_id INTEGER PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, | ||
-- Foreign key columns. | ||
a_hx_id INTEGER REFERENCES a_hx (a_hx_id) -- inserted by trigger fn | ||
); | ||
CREATE TRIGGER t100_add_foreign_hx_keys | ||
BEFORE INSERT | ||
ON b_hx | ||
FOR EACH ROW | ||
EXECUTE FUNCTION hxtk_add_foreign_hx_keys('{{a, a_id}}'); | ||
CREATE TABLE c_hx ( | ||
-- Must parallel primary table cols: $1.* (NEW.*/OLD.*) | ||
c_id INTEGER, | ||
a_id INTEGER, | ||
b_id INTEGER, | ||
z INTEGER, | ||
mod_time timestamp WITHOUT TIME ZONE NOT NULL DEFAULT NOW(), | ||
mod_user character varying(64) COLLATE pg_catalog."default" NOT NULL DEFAULT CURRENT_USER, | ||
-- History columns | ||
deleted BOOLEAN NOT NULL DEFAULT FALSE, | ||
c_hx_id INTEGER PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, | ||
-- Foreign key columns. | ||
a_hx_id INTEGER REFERENCES a_hx (a_hx_id), -- inserted by trigger fn | ||
b_hx_id INTEGER REFERENCES b_hx (b_hx_id) -- inserted by trigger fn | ||
); | ||
CREATE TRIGGER t100_add_foreign_hx_keys | ||
BEFORE INSERT | ||
ON c_hx | ||
FOR EACH ROW | ||
EXECUTE FUNCTION hxtk_add_foreign_hx_keys('{{a, a_id}, {b, b_id}}'); | ||
""" | ||
) | ||
yield sesh |
Oops, something went wrong.