lib/pg_trunk/core/registry.rb
# Register all tables known to Rails
# along with their indexes, check constraints and foreign keys.
# This would let us fetch those objects even though
# they were created by native methods of +ActiveRecord+ like
# `create_table` etc.
Register all tables known to Rails
along with their indexes, check constraints and foreign keys.
This would let us fetch those objects even though
they were created by native methods of +ActiveRecord+ like
`create_table` etc.
Register all tables known to Rails along with their indexes check constraints and foreign keys . This would let us fetch those objects even though they were created by native methods of + ActiveRecord + like ` create_table ` etc .
def remember_tables
        names_and_schemas = names_and_schemas_sql
        return unless names_and_schemas
        <<~SQL.squish
          WITH
            tbl AS (
              SELECT oid FROM pg_class
              WHERE #{names_and_schemas} AND relkind IN ('r', 'p')
            ),
            idx AS (
              SELECT r.oid
              FROM pg_class r
              JOIN pg_index i ON r.oid = i.indexrelid
              JOIN tbl ON i.indrelid = tbl.oid
            ),
            con AS (
              SELECT c.oid AS oid
              FROM pg_constraint c
              JOIN tbl ON c.conrelid = tbl.oid
              WHERE c.contype IN ('c', 'f')
            ),
            obj (oid, classid) AS (
              SELECT oid, 'pg_class'::regclass FROM tbl
              UNION
              SELECT oid, 'pg_class'::regclass FROM idx
              UNION
              SELECT oid, 'pg_constraint'::regclass FROM con
            )
          INSERT INTO #{table_name} (oid, classid)
          SELECT oid, classid FROM obj
          ON CONFLICT DO NOTHING;
        SQL
      end
def remember_tables names_and_schemas = names_and_schemas_sql return unless names_and_schemas <<~SQL . squish 
          WITH
            tbl AS (
              SELECT oid FROM pg_class
              WHERE  #{ names_and_schemas }  AND relkind IN ('r', 'p')
            ),
            idx AS (
              SELECT r.oid
              FROM pg_class r
              JOIN pg_index i ON r.oid = i.indexrelid
              JOIN tbl ON i.indrelid = tbl.oid
            ),
            con AS (
              SELECT c.oid AS oid
              FROM pg_constraint c
              JOIN tbl ON c.conrelid = tbl.oid
              WHERE c.contype IN ('c', 'f')
            ),
            obj (oid, classid) AS (
              SELECT oid, 'pg_class'::regclass FROM tbl
              UNION
              SELECT oid, 'pg_class'::regclass FROM idx
              UNION
              SELECT oid, 'pg_constraint'::regclass FROM con
            )
          INSERT INTO  #{ table_name }  (oid, classid)
          SELECT oid, classid FROM obj
          ON CONFLICT DO NOTHING;
         SQL end
Register all tables known to Rails
along with their indexes, check constraints and foreign keys.
Register all tables known to Rails along with their indexes check constraints and foreign keys .