Skip to content

Commit

Permalink
[api] protect against multiple requests with same number
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianschroeter committed May 20, 2016
1 parent 9a3fa0a commit 51bdcc6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/api/db/migrate/20160518105300_uniq_number_index.rb
@@ -0,0 +1,11 @@
class UniqNumberIndex < ActiveRecord::Migration
def self.up
remove_index :bs_requests, :number
add_index :bs_requests, :number, unique: true
end

def self.down
remove_index :bs_requests, :number
add_index :bs_requests, :number
end
end
8 changes: 5 additions & 3 deletions src/api/db/structure.sql
Expand Up @@ -263,12 +263,12 @@ CREATE TABLE `bs_requests` (
`updated_at` datetime NOT NULL,
`accept_at` datetime DEFAULT NULL,
`priority` enum('critical','important','moderate','low') COLLATE utf8_bin DEFAULT 'moderate',
`number` int(11) DEFAULT NULL,
`number` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `index_bs_requests_on_number` (`number`),
KEY `index_bs_requests_on_creator` (`creator`),
KEY `index_bs_requests_on_state` (`state`),
KEY `index_bs_requests_on_superseded_by` (`superseded_by`),
KEY `index_bs_requests_on_number` (`number`)
KEY `index_bs_requests_on_superseded_by` (`superseded_by`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

CREATE TABLE `cache_lines` (
Expand Down Expand Up @@ -1678,6 +1678,8 @@ INSERT INTO schema_migrations (version) VALUES ('20160321104000');

INSERT INTO schema_migrations (version) VALUES ('20160321105300');

INSERT INTO schema_migrations (version) VALUES ('20160518105300');

INSERT INTO schema_migrations (version) VALUES ('21');

INSERT INTO schema_migrations (version) VALUES ('22');
Expand Down

0 comments on commit 51bdcc6

Please sign in to comment.