-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #963 from powerhome/elevate-repository-as-first-cl…
…ass-domain-concept Elevate repository as first class domain concept
- Loading branch information
Showing
20 changed files
with
320 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Shipit | ||
class Repository < ApplicationRecord | ||
OWNER_MAX_SIZE = 39 | ||
private_constant :OWNER_MAX_SIZE | ||
|
||
NAME_MAX_SIZE = 100 | ||
private_constant :NAME_MAX_SIZE | ||
|
||
validates :name, uniqueness: {scope: %i(owner), case_sensitive: false, | ||
message: 'cannot be used more than once'} | ||
validates :owner, :name, presence: true, ascii_only: true | ||
validates :owner, format: {with: /\A[a-z0-9_\-\.]+\z/}, length: {maximum: OWNER_MAX_SIZE} | ||
validates :name, format: {with: /\A[a-z0-9_\-\.]+\z/}, length: {maximum: NAME_MAX_SIZE} | ||
|
||
has_many :stacks, dependent: :destroy | ||
|
||
def self.from_github_repo_name(github_repo_name) | ||
repo_owner, repo_name = github_repo_name.downcase.split('/') | ||
find_by(owner: repo_owner, name: repo_name) | ||
end | ||
|
||
def name=(n) | ||
super(n&.downcase) | ||
end | ||
|
||
def owner=(o) | ||
super(o&.downcase) | ||
end | ||
|
||
def http_url | ||
Shipit.github.url("#{owner}/#{name}") | ||
end | ||
|
||
def git_url | ||
"https://#{Shipit.github.domain}/#{owner}/#{name}.git" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class CreateShipitRepositories < ActiveRecord::Migration[6.0] | ||
def change | ||
create_table :repositories do |t| | ||
t.string :owner, limit: 100, null: false | ||
t.string :name, limit: 39, null: false | ||
|
||
t.timestamps | ||
end | ||
|
||
add_index :repositories, ["owner", "name"], name: "repository_unicity", unique: true | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
db/migrate/20191209231307_add_repository_reference_to_stacks.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class AddRepositoryReferenceToStacks < ActiveRecord::Migration[6.0] | ||
def up | ||
change_table(:stacks) do |t| | ||
t.references :repository | ||
end | ||
end | ||
|
||
def down | ||
change_column :stacks, :repo_name, :string, null: false | ||
change_column :stacks, :repo_owner, :string, null: false | ||
change_table(:stacks) do |t| | ||
t.remove_references :repository | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class BackfillRepositoryData < ActiveRecord::Migration[6.0] | ||
def up | ||
repositories = Shipit::Stack.distinct.select(:repo_owner, :repo_name).pluck(:repo_owner, :repo_name) | ||
repositories.each do |repo_owner, repo_name| | ||
repository = Shipit::Repository.create_or_find_by( | ||
owner: repo_owner, | ||
name: repo_name, | ||
) | ||
|
||
stacks = Shipit::Stack.where(repo_owner: repository.owner, repo_name: repository.name) | ||
stacks.update(repository: repository) | ||
end | ||
end | ||
|
||
def down | ||
Shipit::Repository.find_each do |repository| | ||
repository.stacks.update_all(repo_owner: repository.owner, repo_name: repository.name) | ||
end | ||
end | ||
end |
20 changes: 20 additions & 0 deletions
20
db/migrate/20191216163010_remove_repository_information_from_stacks.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class RemoveRepositoryInformationFromStacks < ActiveRecord::Migration[6.0] | ||
def up | ||
change_column :stacks, :repository_id, :integer, null: false | ||
change_table(:stacks) do |t| | ||
t.remove_index ["repo_owner", "repo_name", "environment"] | ||
t.remove :repo_owner | ||
t.remove :repo_name | ||
t.index ["repository_id", "environment"], name: "stack_unicity", unique: true | ||
end | ||
end | ||
|
||
def down | ||
change_table(:stacks) do |t| | ||
t.column :repo_name, :string, limit: 100 | ||
t.column :repo_owner, :string, limit: 39 | ||
t.remove_index ["repository_id", "environment"] | ||
t.index ["repo_owner", "repo_name", "environment"], name: "stack_unicity", unique: true | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.