Add unique constraint to zone origin

#475
This commit is contained in:
Artur Beljajev 2017-04-24 18:20:46 +03:00
parent 91fab05bfb
commit b9d4cc0c5c
3 changed files with 26 additions and 1 deletions

View file

@ -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

View file

@ -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

View file

@ -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');