-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create database infrastructure and related routes
- Loading branch information
Showing
27 changed files
with
443 additions
and
111 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
config/*.yml | ||
coverage/ | ||
config/secrets.yml | ||
coverage/ | ||
*.db |
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,8 @@ | ||
require 'hirb' | ||
|
||
Hirb.enable | ||
|
||
old_print = Pry.config.print | ||
Pry.config.print = proc do |*args| | ||
Hirb::View.view_or_page_output(args[1]) || old_print.call(*args) | ||
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
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,6 @@ | ||
--- | ||
development: | ||
db_filename: infrastructure/db/dev.db | ||
|
||
test: | ||
db_filename: infrastructure/db/test.db |
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,39 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'roda' | ||
require 'econfig' | ||
|
||
module CodePraise | ||
# Configuration for the API | ||
class Api < Roda | ||
plugin :environments | ||
|
||
extend Econfig::Shortcut | ||
Econfig.env = environment.to_s | ||
Econfig.root = '.' | ||
|
||
configure :development do | ||
# Allows running reload! in pry to restart entire app | ||
def self.reload! | ||
exec 'pry -r ./spec/test_load_all' | ||
end | ||
end | ||
|
||
configure :development, :test do | ||
ENV['DATABASE_URL'] = 'sqlite://' + config.db_filename | ||
end | ||
|
||
configure :production do | ||
# Use Heroku's DATABASE_URL environment variable | ||
end | ||
|
||
configure do | ||
require 'sequel' | ||
DB = Sequel.connect(ENV['DATABASE_URL']) | ||
|
||
def self.DB | ||
DB | ||
end | ||
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,3 @@ | ||
# frozen_string_literal: false | ||
|
||
require_relative 'environment.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 |
---|---|---|
@@ -1,2 +1,6 @@ | ||
--- | ||
gh_token: <personal access token for github api> | ||
development: | ||
gh_token: <personal token for Github API> | ||
|
||
test: | ||
gh_token: <personal token for Github API> |
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 |
---|---|---|
@@ -1,15 +1,18 @@ | ||
# frozen_string_literal: false | ||
|
||
require_relative 'contributor.rb' | ||
require_relative 'collaborator.rb' | ||
|
||
module CodePraise | ||
module Entity | ||
# Domain entity object for any git repos | ||
class Repo < Dry::Struct | ||
attribute :id, Types::Int.optional | ||
attribute :origin_id, Types::Strict::Int | ||
attribute :name, Types::Strict::String | ||
attribute :size, Types::Strict::Int | ||
attribute :owner, Contributor | ||
attribute :git_url, Types::Strict::String | ||
attribute :contributors, Types::Strict::Array.member(Contributor) | ||
attribute :owner, Collaborator | ||
attribute :contributors, Types::Strict::Array.member(Collaborator) | ||
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 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'sequel' | ||
|
||
Sequel.migration do | ||
change do | ||
create_table(:repos) do | ||
primary_key :id | ||
Integer :origin_id, unique: true | ||
foreign_key :owner_id, :collaborators | ||
|
||
String :name | ||
String :git_url | ||
Integer :size | ||
|
||
DateTime :created_at | ||
DateTime :updated_at | ||
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,17 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'sequel' | ||
|
||
Sequel.migration do | ||
change do | ||
create_table(:collaborators) do | ||
primary_key :id | ||
Integer :origin_id, unique: true | ||
String :username, unique: true, null: false | ||
String :email | ||
|
||
DateTime :created_at | ||
DateTime :updated_at | ||
end | ||
end | ||
end |
14 changes: 14 additions & 0 deletions
14
infrastructure/db/migrations/003_repos_contributors_join_create.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,14 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'sequel' | ||
|
||
Sequel.migration do | ||
change do | ||
create_table(:repos_contributors) do | ||
foreign_key :repo_id, :repos | ||
foreign_key :collaborator_id, :collaborators | ||
primary_key [:repo_id, :collaborator_id] | ||
index [:repo_id, :collaborator_id] | ||
end | ||
end | ||
end |
Oops, something went wrong.