Closed cavi21 closed 2 years ago
Seems that the name of the generated files could be something related to fx, but for the generated code seems that should be handle by logidze, right?
Right. We need to add, for example, a #full_table_name
helper method which takes into account Active Record configuration and use it instead of the #table_name
in the templates:
def full_table_name
config = ActiveRecord::Base
"#{config.table_name_prefix}#{table_name}#{config.table_name_suffix}"
end
Hi @palkan thanks for looking into this! If you're ok I can open a PR with what you propose, or not sure if you have another idea in mind? Anything let me know
Yeah, feel free to open a PR 👍
Ruby Version: 2.7.2
Rails Version: 6.1.4.4
PostgreSQL Version: 10.1
Logidze Version: 1.2.0
What did you do?
In the project we have the
table_name_prefix
define in theapplication.rb
so every table of the models are prefixed:We are also using
fx (0.6.2)
in order to have everything we need in theschema.rb
. So with this setup thelogidze:install
andlogidze:model
are not generating the the expected outputs.What did you expect to happen?
On on both generators (
logidze:install
andlogidze:model
) we expected that the functions and triggers names generated include theproject-prefix-
on there filenames, for instance:And on
logidze:model
also the trigger we expected to include the prefix (and the suffix) on the code generated, for example:and on the migration file should also need to be applied, for example:
What actually happened?
The functions and triggers did not honored the prefix, neither on the file names generated (in functions and triggers) or the
sql
code generated.What we found so far
In regards to the generated file names, is related to how
fx
implemented thecreate_function
method. It is though themethod_missing
defined in activerecord-6.1.4.4/lib/active_record/migration.rb:915 and so in there the methodproper_table_name( )
is called, and in such when you have in the migration:The file that looks for is
functions/project-prefix-logidze_capture_exception_v01.sql
and the same happes with the triggers so if in the migration there is:The file that looks is
triggers/project-prefix-logidze_on_some_table_v01.sql
and notice that the second argument is fine because the sameproper_table_name( )
is called on them so the actual table name is referenced, in this caseproject-prefix-some_table
)And about the generated code seems that similar approach to the
proper_table_name()
method is needed. For what I can see Activerecord migrations apply thisprefix
andsuffix
when the migration is run and not when is generated, but because here the trigger code is generating thesql
we need to have them in mind when the generator is run.I did not open a PR, because not sure what you prefer to do with this cases. Seems that the name of the generated files could be something related to
fx
, but for the generated code seems that should be handle bylogidze
, right?Let me know what do you think! Thanks!