Skip to content

Conversation

@seuros
Copy link
Member

@seuros seuros commented Oct 17, 2025

Add support for PostgreSQL schema-qualified table names (e.g., 'test_schema.schema_types') to properly generate hierarchy table names with schema prefix.

@seuros seuros requested a review from Copilot October 17, 2025 14:20
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for PostgreSQL schema-qualified table names in closure_tree, enabling the library to properly handle tables defined with schema prefixes (e.g., 'test_schema.schema_types'). The implementation ensures that hierarchy tables are created with the correct schema prefix.

  • Implements schema-aware hierarchy table name generation
  • Adds test infrastructure with schema-qualified test tables
  • Validates schema-qualified table behavior with comprehensive tests

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
lib/closure_tree/support.rb Updates hierarchy_table_name logic to parse and preserve schema prefixes when generating hierarchy table names
test/dummy/db/schema.rb Adds test_schema with schema_types and schema_type_hierarchies tables for testing schema-qualified names
test/dummy/app/models/schema_type.rb Creates SchemaType model using schema-qualified table name 'test_schema.schema_types'
test/closure_tree/schema_type_test.rb Adds comprehensive test coverage for schema-qualified table operations including lineage, reparenting, and tree traversal

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


# Handle PostgreSQL schema-qualified table names (e.g., "my_schema.table_name")
if base_table.include?('.')
schema, table = base_table.split('.', 2)
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

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

The split with limit 2 may not handle edge cases correctly. If the table name itself contains a period (beyond the schema separator), this would incorrectly parse the schema and table parts. Consider using rsplit or splitting only on the first period to ensure the schema is correctly separated from the table name.

Suggested change
schema, table = base_table.split('.', 2)
schema, _, table = base_table.rpartition('.')

Copilot uses AI. Check for mistakes.
Comment on lines +123 to +127
create_table 'test_schema.schema_type_hierarchies', id: false, force: true do |t|
t.references 'ancestor', null: false
t.references 'descendant', null: false
t.integer 'generations', null: false
end
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

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

The schema_type_hierarchies table is manually created, but the PR's purpose is to auto-generate hierarchy tables with schema prefixes. If the library should automatically create this table, consider removing this manual definition to ensure the feature works as intended and to avoid duplication between manual and auto-generated tables.

Suggested change
create_table 'test_schema.schema_type_hierarchies', id: false, force: true do |t|
t.references 'ancestor', null: false
t.references 'descendant', null: false
t.integer 'generations', null: false
end

Copilot uses AI. Check for mistakes.
Add support for PostgreSQL schema-qualified table names (e.g.,
'test_schema.schema_types') to properly generate hierarchy table
names with schema prefix.
@seuros seuros force-pushed the feat/postgresql-schema-support branch from 4f7d877 to 253653a Compare October 17, 2025 14:27
@seuros seuros merged commit 5f9006c into master Oct 17, 2025
1 check passed
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.

1 participant