diff --git a/db/migrate/20180126104536_change_contacts_code_to_not_null.rb b/db/migrate/20180126104536_change_contacts_code_to_not_null.rb new file mode 100644 index 000000000..fc1c653e2 --- /dev/null +++ b/db/migrate/20180126104536_change_contacts_code_to_not_null.rb @@ -0,0 +1,5 @@ +class ChangeContactsCodeToNotNull < ActiveRecord::Migration + def change + change_column_null :contacts, :code, false + end +end diff --git a/db/migrate/20180126104903_add_unique_constraint_to_contacts_code.rb b/db/migrate/20180126104903_add_unique_constraint_to_contacts_code.rb new file mode 100644 index 000000000..2e7e7e12b --- /dev/null +++ b/db/migrate/20180126104903_add_unique_constraint_to_contacts_code.rb @@ -0,0 +1,13 @@ +class AddUniqueConstraintToContactsCode < ActiveRecord::Migration + def up + execute <<-SQL + ALTER TABLE contacts ADD CONSTRAINT unique_contact_code UNIQUE (code) + SQL + end + + def down + execute <<-SQL + ALTER TABLE contacts DROP CONSTRAINT unique_contact_code + SQL + end +end diff --git a/db/structure.sql b/db/structure.sql index 2bf928769..8b13aa4a4 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -644,7 +644,7 @@ ALTER SEQUENCE contact_statuses_id_seq OWNED BY contact_statuses.id; CREATE TABLE contacts ( id integer NOT NULL, - code character varying, + code character varying NOT NULL, phone character varying, email character varying, fax character varying, @@ -3627,6 +3627,14 @@ ALTER TABLE ONLY settings ADD CONSTRAINT settings_pkey PRIMARY KEY (id); +-- +-- Name: unique_contact_code; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY contacts + ADD CONSTRAINT unique_contact_code UNIQUE (code); + + -- -- Name: unique_zone_origin; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- @@ -5068,3 +5076,7 @@ INSERT INTO schema_migrations (version) VALUES ('20180123170112'); INSERT INTO schema_migrations (version) VALUES ('20180125092422'); +INSERT INTO schema_migrations (version) VALUES ('20180126104536'); + +INSERT INTO schema_migrations (version) VALUES ('20180126104903'); +