diff --git a/schema/sdss5db/targetdb/load_table/targeting_generation/README.txt b/schema/sdss5db/targetdb/load_table/targeting_generation/README.txt index 95486893..c5fd8740 100644 --- a/schema/sdss5db/targetdb/load_table/targeting_generation/README.txt +++ b/schema/sdss5db/targetdb/load_table/targeting_generation/README.txt @@ -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; @@ -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; @@ -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; diff --git a/schema/sdss5db/targetdb/load_table/targeting_generation/load_targeting_generation.sql b/schema/sdss5db/targetdb/load_table/targeting_generation/load_targeting_generation.sql index bcd720a7..1caf696a 100644 --- a/schema/sdss5db/targetdb/load_table/targeting_generation/load_targeting_generation.sql +++ b/schema/sdss5db/targetdb/load_table/targeting_generation/load_targeting_generation.sql @@ -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; @@ -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; @@ -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;