From b9d4cc0c5c9178e7da5d464179e8f4c1cff756ed Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 24 Apr 2017 18:20:46 +0300 Subject: [PATCH] Add unique constraint to zone origin #475 --- ...0170424115801_add_unique_index_to_zone_origin.rb | 13 +++++++++++++ db/schema-read-only.rb | 4 +++- db/structure.sql | 10 ++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20170424115801_add_unique_index_to_zone_origin.rb diff --git a/db/migrate/20170424115801_add_unique_index_to_zone_origin.rb b/db/migrate/20170424115801_add_unique_index_to_zone_origin.rb new file mode 100644 index 000000000..bd9f68dec --- /dev/null +++ b/db/migrate/20170424115801_add_unique_index_to_zone_origin.rb @@ -0,0 +1,13 @@ +class AddUniqueIndexToZoneOrigin < ActiveRecord::Migration + def up + execute <<-SQL + ALTER TABLE zones ADD CONSTRAINT unique_zone_origin UNIQUE (origin) + SQL + end + + def down + execute <<-SQL + ALTER TABLE zones DROP CONSTRAINT unique_zone_origin + SQL + end +end diff --git a/db/schema-read-only.rb b/db/schema-read-only.rb index 5fa683be4..0dd0e5a13 100644 --- a/db/schema-read-only.rb +++ b/db/schema-read-only.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170422142116) do +ActiveRecord::Schema.define(version: 20170424115801) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -1143,4 +1143,6 @@ ActiveRecord::Schema.define(version: 20170422142116) do t.text "a4_records" end + add_index "zones", ["origin"], name: "unique_zone_origin", unique: true, using: :btree + end diff --git a/db/structure.sql b/db/structure.sql index c59d01b1c..d7cdbf36b 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -3952,6 +3952,14 @@ ALTER TABLE ONLY settings ADD CONSTRAINT settings_pkey PRIMARY KEY (id); +-- +-- Name: unique_zone_origin; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY zones + ADD CONSTRAINT unique_zone_origin UNIQUE (origin); + + -- -- Name: users_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- @@ -5221,3 +5229,5 @@ INSERT INTO schema_migrations (version) VALUES ('20170422130054'); INSERT INTO schema_migrations (version) VALUES ('20170422142116'); +INSERT INTO schema_migrations (version) VALUES ('20170424115801'); +