Skip to content

Commit 0da7fda

Browse files
committed
Allow customization of ActiveRecord table name
1 parent b082ba9 commit 0da7fda

File tree

6 files changed

+9
-5
lines changed

6 files changed

+9
-5
lines changed

lib/slack-ruby-bot-server/config.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module Config
55
attr_accessor :server_class
66
attr_accessor :ping
77
attr_accessor :database_adapter
8+
attr_accessor :teams_table
89

910
def reset!
1011
self.ping = nil
@@ -16,6 +17,7 @@ def reset!
1617
else
1718
raise 'One of "mongoid" or "activerecord" is required.'
1819
end
20+
self.teams_table = :teams
1921
end
2022

2123
def activerecord?

lib/slack-ruby-bot-server/config/database_adapters/activerecord.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ def self.check!
1111
end
1212

1313
def self.init!
14-
return if ActiveRecord::Base.connection.tables.include?('teams')
15-
ActiveRecord::Base.connection.create_table :teams do |t|
14+
return if ActiveRecord::Base.connection.tables.include?(SlackRubyBotServer::Config.teams_table)
15+
ActiveRecord::Base.connection.create_table SlackRubyBotServer::Config.teams_table do |t|
1616
t.string :team_id
1717
t.string :name
1818
t.string :domain

lib/slack-ruby-bot-server/models/team/activerecord.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
module SlackRubyBotServer
44
class Team < ActiveRecord::Base
5+
self.table_name = SlackRubyBotServer::Config.teams_table
6+
57
include Methods
68

79
def self.purge!

sample_apps/sample_app_activerecord/db/migrate/20170307164946_create_teams_table.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class CreateTeamsTable < ActiveRecord::Migration[5.0]
22
def change
3-
create_table :teams, force: true do |t|
3+
create_table SlackRubyBotServer::Config.teams_table, force: true do |t|
44
t.string :team_id
55
t.string :name
66
t.boolean :active, default: true

sample_apps/sample_app_activerecord/db/schema.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension 'plpgsql'
1616

17-
create_table 'teams', force: :cascade do |t|
17+
create_table SlackRubyBotServer::Config.teams_table, force: :cascade do |t|
1818
t.string 'team_id'
1919
t.string 'name'
2020
t.boolean 'active', default: true

spec/database_adapters/activerecord/schema.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
ActiveRecord::Schema.define do
44
self.verbose = false
55

6-
create_table :teams, force: true do |t|
6+
create_table SlackRubyBotServer::Config.teams_table, force: true do |t|
77
t.string :team_id
88
t.string :name
99
t.boolean :active, default: true

0 commit comments

Comments
 (0)