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

Fx dumps triggers created by other extension in schema. #97

Open
inkstak opened this issue Dec 8, 2022 · 2 comments
Open

Fx dumps triggers created by other extension in schema. #97

inkstak opened this issue Dec 8, 2022 · 2 comments

Comments

@inkstak
Copy link

inkstak commented Dec 8, 2022

We start using Fx on a database using PostGIS.

When performing rails db:schema:dump, fx is dumping a trigger from the topology extension:

ActiveRecord::Schema.define(version: 2022_11_29_082047) do
  enable_extension "postgis"
  enable_extension "postgis_topology"

(...)

  create_trigger :layer_integrity_checks, sql_definition: <<-SQL
      CREATE TRIGGER layer_integrity_checks BEFORE DELETE OR UPDATE ON topology.layer FOR EACH ROW EXECUTE FUNCTION topology.layertrigger()
  SQL
end

After then, any rails db:schema:load will fail.

$ rails db:schema:load
rails aborted!
ActiveRecord::StatementInvalid: PG::DuplicateObject: ERROR:  trigger "layer_integrity_checks" for relation "layer" already exists

The trigger is dumped by the statement defined in (..)/adapters/postgres/triggers.rb :

# SELECT * FROM pg_trigger WHERE pg_trigger.tgname NOT ILIKE '%constraint%';
  oid  | tgrelid | tgparentid |         tgname         | tgfoid | tgtype | tgenabled | tgisinternal | tgconstrrelid | tgconstrindid | tgconstraint | tgdeferrable | tginitdeferred | tgnargs | tgattr | tgargs | tgqual | tgoldtable | tgnewtable
-------+---------+------------+------------------------+--------+--------+-----------+--------------+---------------+---------------+--------------+--------------+----------------+---------+--------+--------+--------+------------+------------
 46987 |   46972 |          0 | layer_integrity_checks |  46971 |     27 | O         | f            |             0 |             0 |            0 | f            | f              |       0 |        | \x     |        |            |
(1 row)

I tried but couldn't find a way to link triggers to namespaces to include only "public" triggers as is done for functions.

@inkstak
Copy link
Author

inkstak commented Dec 8, 2022

For those in the same situation, my current workaround is to monkey-patch Fx::SchemaDumper::Trigger

# config/initializers/fx.rb

module Fx
  module SchemaDumper
    module Trigger
      private

      def dumpable_triggers_in_database
        @_dumpable_triggers_in_database ||= Fx.database.triggers
          .reject { |trigger| trigger.name == "layer_integrity_checks" }
      end
    end
  end
end

@teoljungberg
Copy link
Owner

I'd entertain a PR that expands the sql used to dump triggers to exclude stuff from postgis.

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

No branches or pull requests

2 participants