Skip to content
This repository has been archived by the owner on May 10, 2018. It is now read-only.

Save tags and branches properly #320

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ end

group :development, :test do
gem 'micro_migrations', git: 'https://gist.github.com/2087829.git'
gem 'foreigner', require: nil
gem 'data_migrations', '~> 0.0.1'
end

Expand Down
5 changes: 5 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

require 'rspec/core/rake_task'
require 'bundler/setup'
require 'foreigner'
require 'micro_migrations'
require 'travis'

task :environment do
Foreigner.load
end

desc 'Run specs'
RSpec::Core::RakeTask.new do |t|
t.pattern = './spec/**/*_spec.rb'
Expand Down
16 changes: 16 additions & 0 deletions db/migrate/20131227155535_create_branches.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class CreateBranches < ActiveRecord::Migration
def change
create_table :branches do |t|
t.string :name, null: false
t.references :repository, null: false
t.references :last_build
t.foreign_key :repositories
t.foreign_key :builds, column: :last_build_id

t.timestamps
end

add_index :branches, :repository_id
add_index :branches, [:name, :repository_id], unique: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are both of these indices necessary, or is only the last one needed? I've seen Postgres use only one or some of the columns in a multi-column index before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PG in general can use multi column indexes for single column queries, but it will be less performant - the first field in multi column index will be the fastest to check. Maybe it's a premature optimization, but queries by name and by repository_id will be done every time new build is added, so I assume that having 2 indexes will help and rather not hurt.

end
end
16 changes: 16 additions & 0 deletions db/migrate/20131227160256_create_builds_branches.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class CreateBuildsBranches < ActiveRecord::Migration
def change
create_table :builds_branches do |t|
t.references :build, null: false
t.references :branch, null: false
t.foreign_key :builds, dependent: :delete
t.foreign_key :branches, dependent: :delete

t.timestamps
end

add_index :builds_branches, :build_id
add_index :builds_branches, :branch_id
add_index :builds_branches, [:build_id, :branch_id], unique: true
end
end
16 changes: 16 additions & 0 deletions db/migrate/20131230093907_create_tags.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class CreateTags < ActiveRecord::Migration
def change
create_table :tags do |t|
t.string :name, null: false
t.references :last_build
t.references :repository, null: false
t.foreign_key :repositories
t.foreign_key :builds, column: :last_build_id

t.timestamps
end

add_index :tags, :repository_id
add_index :tags, [:name, :repository_id], unique: true
end
end
16 changes: 16 additions & 0 deletions db/migrate/20131230094201_create_builds_tags.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class CreateBuildsTags < ActiveRecord::Migration
def change
create_table :builds_tags do |t|
t.references :build, null: false
t.references :tag, null: false
t.foreign_key :builds, dependent: :delete
t.foreign_key :tags, dependent: :delete

t.timestamps
end

add_index :builds_tags, :build_id
add_index :builds_tags, :tag_id
add_index :builds_tags, [:build_id, :tag_id], unique: true
end
end
17 changes: 17 additions & 0 deletions db/migrate/20140116125536_create_commits_tags.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class CreateCommitsTags < ActiveRecord::Migration
def change
create_table :commits_tags do |t|
t.references :commit
t.references :tag
t.references :request

t.foreign_key :commits, dependent: :delete
t.foreign_key :tags, dependent: :delete
t.foreign_key :requests, dependent: :delete

t.timestamps
end

add_index :commits_tags, [:commit_id, :tag_id], unique: true
end
end
17 changes: 17 additions & 0 deletions db/migrate/20140116125602_create_commits_branches.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class CreateCommitsBranches < ActiveRecord::Migration
def change
create_table :commits_branches do |t|
t.references :commit
t.references :branch
t.references :request

t.foreign_key :commits, dependent: :delete
t.foreign_key :branches, dependent: :delete
t.foreign_key :requests, dependent: :delete

t.timestamps
end

add_index :commits_branches, [:commit_id, :branch_id], unique: true
end
end
Loading