Skip to content

Commit

Permalink
add constraints to avoid duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
tdwelly committed Dec 3, 2024
1 parent 83dcaf1 commit 27931e0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
14 changes: 10 additions & 4 deletions schema/sdss5db/targetdb/load_table/targeting_generation/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ CREATE TABLE IF NOT EXISTS sandbox.targeting_generation (
label TEXT,
first_release TEXT
);
TRUNCATE sandbox.targeting_generation;

ALTER TABLE sandbox.targeting_generation DROP CONSTRAINT IF EXISTS targeting_generation_pk_key;
ALTER TABLE sandbox.targeting_generation ADD CONSTRAINT targeting_generation_pk_key UNIQUE (pk);

INSERT INTO sandbox.targeting_generation (pk, label, first_release)
SELECT * FROM targeting_generation_temp ON CONFLICT DO NOTHING;
Expand All @@ -274,8 +276,9 @@ CREATE TABLE IF NOT EXISTS sandbox.targeting_generation_to_carton (
rs_stage TEXT,
rs_active BOOLEAN
);

TRUNCATE sandbox.targeting_generation_to_carton;
ALTER TABLE sandbox.targeting_generation_to_carton DROP CONSTRAINT IF EXISTS targeting_generation_to_carton_pk_key;
ALTER TABLE sandbox.targeting_generation_to_carton ADD CONSTRAINT targeting_generation_to_carton_pk_key UNIQUE (generation_pk,carton_pk);
# TRUNCATE sandbox.targeting_generation_to_carton;

INSERT INTO sandbox.targeting_generation_to_carton (generation_pk, carton_pk, rs_stage, rs_active)
SELECT * FROM targeting_generation_to_carton_temp ON CONFLICT DO NOTHING;
Expand All @@ -293,7 +296,10 @@ CREATE TABLE IF NOT EXISTS sandbox.targeting_generation_to_version (
generation_pk INTEGER,
version_pk INTEGER
);
TRUNCATE sandbox.targeting_generation_to_version;

ALTER TABLE sandbox.targeting_generation_to_version DROP CONSTRAINT IF EXISTS targeting_generation_to_version_uniq_key;
ALTER TABLE sandbox.targeting_generation_to_version ADD CONSTRAINT targeting_generation_to_version_uniq_key UNIQUE (generation_pk,version_pk);
# TRUNCATE sandbox.targeting_generation_to_version;

INSERT INTO sandbox.targeting_generation_to_version (generation_pk, version_pk)
SELECT * FROM targeting_generation_to_version_temp ON CONFLICT DO NOTHING;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ TRUNCATE targeting_generation_temp;

\copy targeting_generation_temp FROM 'targeting_generation.csv' WITH CSV HEADER;

ALTER TABLE targetdb.targeting_generation DROP CONSTRAINT IF EXISTS targeting_generation_uniq_key;
ALTER TABLE targetdb.targeting_generation ADD CONSTRAINT targeting_generation_uniq_key UNIQUE (pk);

INSERT INTO targetdb.targeting_generation (pk, label, first_release)
SELECT * FROM targeting_generation_temp ON CONFLICT DO NOTHING;

Expand All @@ -22,6 +25,9 @@ TRUNCATE targeting_generation_to_carton_temp;

\copy targeting_generation_to_carton_temp FROM 'targeting_generation_to_carton.csv' WITH CSV HEADER;

ALTER TABLE targetdb.targeting_generation_to_carton DROP CONSTRAINT IF EXISTS targeting_generation_to_carton_uniq_key;
ALTER TABLE targetdb.targeting_generation_to_carton ADD CONSTRAINT targeting_generation_to_carton_uniq_key UNIQUE (generation_pk,carton_pk);

INSERT INTO targetdb.targeting_generation_to_carton (generation_pk, carton_pk, rs_stage, rs_active)
SELECT * FROM targeting_generation_to_carton_temp ON CONFLICT DO NOTHING;

Expand All @@ -34,5 +40,8 @@ TRUNCATE targeting_generation_to_version_temp;

\copy targeting_generation_to_version_temp FROM 'targeting_generation_to_version.csv' WITH CSV HEADER;

ALTER TABLE targetdb.targeting_generation_to_version DROP CONSTRAINT IF EXISTS targeting_generation_to_version_uniq_key;
ALTER TABLE targetdb.targeting_generation_to_version ADD CONSTRAINT targeting_generation_to_version_uniq_key UNIQUE (generation_pk,version_pk);

INSERT INTO targetdb.targeting_generation_to_version (generation_pk, version_pk)
SELECT * FROM targeting_generation_to_version_temp ON CONFLICT DO NOTHING;

0 comments on commit 27931e0

Please sign in to comment.