forked from slack-ruby/slack-ruby-bot-server
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added PostgreSQL support, closes slack-ruby#7.
- Loading branch information
Showing
57 changed files
with
667 additions
and
163 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 |
---|---|---|
@@ -1,15 +1,16 @@ | ||
require 'celluloid/current' | ||
require 'kaminari/grape' | ||
require 'mongoid-scroll' | ||
|
||
require 'grape-swagger' | ||
require 'slack-ruby-bot' | ||
require 'slack-ruby-bot-server/server' | ||
require 'slack-ruby-bot-server/config' | ||
|
||
require 'slack-ruby-bot-server/ext' | ||
require 'slack-ruby-bot-server/version' | ||
require 'slack-ruby-bot-server/info' | ||
require 'slack-ruby-bot-server/models' | ||
|
||
require "slack-ruby-bot-server/config/database_adapters/#{SlackRubyBotServer::Config.database_adapter}.rb" | ||
|
||
require 'slack-ruby-bot-server/api' | ||
require 'slack-ruby-bot-server/app' | ||
require 'slack-ruby-bot-server/server' | ||
require 'slack-ruby-bot-server/config' | ||
require 'slack-ruby-bot-server/service' |
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
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
27 changes: 27 additions & 0 deletions
27
lib/slack-ruby-bot-server/config/database_adapters/activerecord.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,27 @@ | ||
require 'slack-ruby-bot-server/models/team/activerecord.rb' | ||
|
||
module SlackRubyBotServer | ||
module DatabaseAdapter | ||
def self.check! | ||
ActiveRecord::Base.connection_pool.with_connection(&:active?) | ||
raise 'Unexpected error.' unless ActiveRecord::Base.connected? | ||
rescue StandardError => e | ||
warn "Error connecting to PostgreSQL: #{e.message}" | ||
raise e | ||
end | ||
|
||
def self.init! | ||
return if ActiveRecord::Base.connection.tables.include?('teams') | ||
ActiveRecord::Base.connection.create_table :teams do |t| | ||
t.string :team_id | ||
t.string :name | ||
t.string :domain | ||
t.string :token | ||
t.boolean :active, default: true | ||
t.timestamps | ||
end | ||
end | ||
end | ||
end | ||
|
||
::Boolean = Virtus::Attribute::Boolean |
24 changes: 24 additions & 0 deletions
24
lib/slack-ruby-bot-server/config/database_adapters/mongoid.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,24 @@ | ||
require 'slack-ruby-bot-server/models/team/mongoid.rb' | ||
require 'kaminari/grape' | ||
require 'mongoid-scroll' | ||
|
||
module SlackRubyBotServer | ||
module DatabaseAdapter | ||
def self.check! | ||
rc = Mongoid.default_client.command(ping: 1) | ||
return if rc && rc.ok? | ||
raise rc.documents.first['error'] || 'Unexpected error.' | ||
rescue StandardError => e | ||
warn "Error connecting to MongoDB: #{e.message}" | ||
raise e | ||
end | ||
|
||
def self.init! | ||
# create indexes | ||
::Mongoid::Tasks::Database.create_indexes | ||
# silence loggers | ||
Mongoid.logger.level = Logger::INFO | ||
Mongo::Logger.logger.level = Logger::INFO | ||
end | ||
end | ||
end |
Oops, something went wrong.