Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent name collision for teams #83

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

leechou
Copy link

@leechou leechou commented Nov 17, 2018

Prevents name collision for teams so that the gem can be used with other projects.

  • Prevents collision for class Team. References to teams are now SlackRubyBotServer::Team
  • Allow configuration of ActiveRecord table name. SlackRubyBotServer::Config.teams[:name]='my_table'

Minor bug fixes:

  • Fixed spec for ActiveRecord
  • Fixed console script

@leechou leechou force-pushed the prevent-name-collision-for-Teams branch 6 times, most recently from 71ac969 to 63e08aa Compare November 17, 2018 00:29
@leechou leechou force-pushed the prevent-name-collision-for-Teams branch from 63e08aa to 388c520 Compare November 17, 2018 00:32
Copy link
Collaborator

@dblock dblock left a comment

Choose a reason for hiding this comment

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

I like this and would like this to move forward. Thanks.

  • I think the configuration option should be called store_teams_in (or better name?) and have downstream effect on both Mongoid and ActiveRecord. In MongoDB there are no "tables", but "collections".
  • This is not backwards compatible and will break anyone with a Team class, I believe. I have half a dozen bots that extend the Team. Give it a try on anything like http://github.com/dblock/slack-strava and you'll see what I mean. At the very least we need UPGRADING to explain what one should do. But I think the right long term solution is that rather than namespacing the team class we want to turn it into a module that can be included in both Mongoid and AR scenarios. In which case we don't actually need to specify the table name, this would be the responsibility of the class using the module.

What do you think?

CHANGELOG.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
@leechou
Copy link
Author

leechou commented Nov 19, 2018

I feel like importing another module will add unnecessary complexity, and easy fix for those that subclass Teams is just to add Team = SlackRubyBot::Team and keep everything as-is.

As for the name of the variable to store the table name, I prefer SlackRubyBotServer::Config.teams_table = 'my_table' since it correspond to the thought of "for SlackRubyBotServer, configure the teams table to be 'my_table'"

Using something like store_teams_in would be more like objective-C style wording, like -(void)showAlertMsg:(NSString *)message withTitle:(NSString *)title; which would correspond to "show alert message 'my message' with title 'my title'"

I don't mind either way, it just makes more sense to me to have the variable as the noun of what it is, like teams_table or activerecord_teams_table

@dblock
Copy link
Collaborator

dblock commented Nov 19, 2018

I don't mind either way, it just makes more sense to me to have the variable as the noun of what it is, like teams_table or activerecord_teams_table

Except that there're no "tables" in MongoDB, so it only makes sense for AR. In MongoDB these are called "collections".

@leechou
Copy link
Author

leechou commented Nov 19, 2018

So which would you prefer?

  1. Change var name to teams_table for AR, and teams_collection for mongoid.
  2. Change var name to teams_storage_name
  3. Other name?

Did you want the mongoid patch before accepting this PR?

@dblock
Copy link
Collaborator

dblock commented Nov 19, 2018

  1. Change var name to teams_table for AR, and teams_collection for mongoid.
  2. Change var name to teams_storage_name
  3. Other name?

I think the cleanest and most forward-looking solution is a store_in that works for all storage, a hash where you can do:

.store_in = { name: 'foobar', other_options: ... }

This way future we can extend this in the future. What do you think?

Did you want the mongoid patch before accepting this PR?

I'd like Mongoid to work as part of this PR as well, but would accept without it.

@leechou
Copy link
Author

leechou commented Nov 20, 2018

so, .store_in = {teams: 'my_table_or_collection_name'} ?

@dblock
Copy link
Collaborator

dblock commented Nov 20, 2018

so, .store_in = {teams: 'my_table_or_collection_name'} ?

What if we just dropped store_in and did:

teams: { name: 'my_table' }

This way it's extensible for the future, for example

teams: { name: 'whatever', class_name: 'Whatever'  }

@leechou
Copy link
Author

leechou commented Nov 20, 2018

Did you mean something like this?
SlackRubyBotServer::Config.teams = {name: 'my_table', class_name: 'MyClass'}

I'm fine with it this way, since it'll read off as "configure the teams to have name 'my_table'". Only potential issue with this is consistency, since this is the only place where it's configured like this.

Let me know about the final call and I'll make the updates.

@dblock
Copy link
Collaborator

dblock commented Nov 20, 2018

that LGTM

@dblock
Copy link
Collaborator

dblock commented Nov 21, 2018

This needs a major version bump.

If you have time, consider doing the MongoDB support for renaming the collection as part of this.

Try writing/upgrading a trivial bot. I personally only have MongoDB ones.

UPGRADING.md Outdated
@@ -1,6 +1,10 @@
Upgrading Slack-Ruby-Bot-Server
===============================

### Upgrading to >= 0.8.3

To avoid name collisions, `Team` has been renamed `SlackRubyBot::Team`, if you modify the class `Team` add `Team = SlackRubyBot::Team` before the code.
Copy link
Collaborator

@dblock dblock Nov 21, 2018

Choose a reason for hiding this comment

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

This should say SlackRubyBotServer not SlackRubyBot, right?

Also, I could be wrong, but I think this might not work for MongoDB because it might change the name of the collection to something like slack_ruby_bot_server_team, that needs to be tested, so I suggest you actually do the change for mongodb as part of this PR, too.

Copy link
Author

Choose a reason for hiding this comment

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

ya, my bad. I'll get that changed.

Sure, I can test out MongoDB, but it might take a while though.

@leechou
Copy link
Author

leechou commented Nov 26, 2018

Just noticed that more changes needs to be done for this feature, since the db:migrate doesn't pull in the setting of tablename for ActiveRecord. Will continue to work on this.

@dblock
Copy link
Collaborator

dblock commented Nov 26, 2018

Just noticed that more changes needs to be done for this feature, since the db:migrate doesn't pull in the setting of tablename for ActiveRecord. Will continue to work on this.

I still think turning Team into an include-able module could be a good idea. It would avoid these problems, migrations, etc. Just thinking out loud.

@dblock
Copy link
Collaborator

dblock commented Apr 22, 2019

Related #102, in which the user tried to inherit from ApplicationRecord instead of ActiveRecord::Base. Could be fixed by this too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants