amatsuda / database_rewinder

minimalist's tiny and ultra-fast database cleaner
MIT License
807 stars 91 forks source link

Support table_name with database name #23

Closed ppworks closed 9 years ago

ppworks commented 9 years ago

When the table name of an ActiveRecord class is set explicitly, and if the table name contains the database name, database_rewinder fails to clear that table.

This PR fix the issue.

If I created user model like this.

class User < ActiveRecord::Base
  self.table_name = 'my_database.user'
end

INSERT SQL is following.

INSERT INTO `my_database`.`user` (`created_at`, `updated_at`) VALUES ('2015-01-22 05:57:42', '2015-01-22 05:57:42')

INSERT SQL regular expression matches 'my_database'

So, I changes INSERT SQL regular expression like this.

amatsuda commented 9 years ago

@ppworks Thank you! Just for curious, which RDBMS are you using?

ppworks commented 9 years ago

I'm using MySQL.

ppworks commented 9 years ago

Thanks for merging! When will it be bumped version on rubygems?

amatsuda commented 9 years ago

Wait, I merged this because it's not a bad change, but asked this question because I'm still not sure if this regexp is perfect. One actual example that I'm aware now is MS SQLServer. SQLServer accepts more than one dots in an object notation https://msdn.microsoft.com/en-us/library/ms177563.aspx Please give me some more time to think.

ppworks commented 9 years ago

Oh! I didn't know that... Ok, I'll make other pull request!