fix(cursor): use full schema-qualified table name in filters

This commit is contained in:
Hein
2026-03-11 14:25:44 +02:00
parent d1ae4fe64e
commit 613bf22cbd
4 changed files with 12 additions and 9 deletions

View File

@@ -32,7 +32,8 @@ func GetCursorFilter(
modelColumns []string, modelColumns []string,
options common.RequestOptions, options common.RequestOptions,
) (string, error) { ) (string, error) {
// Remove schema prefix if present // Separate schema prefix from bare table name
fullTableName := tableName
if strings.Contains(tableName, ".") { if strings.Contains(tableName, ".") {
tableName = strings.SplitN(tableName, ".", 2)[1] tableName = strings.SplitN(tableName, ".", 2)[1]
} }
@@ -115,7 +116,7 @@ func GetCursorFilter(
WHERE cursor_select.%s = %s WHERE cursor_select.%s = %s
AND (%s) AND (%s)
)`, )`,
tableName, fullTableName,
pkName, pkName,
cursorID, cursorID,
orSQL, orSQL,

View File

@@ -175,9 +175,9 @@ func TestGetCursorFilter_WithSchemaPrefix(t *testing.T) {
t.Fatalf("GetCursorFilter failed: %v", err) t.Fatalf("GetCursorFilter failed: %v", err)
} }
// Should handle schema prefix properly // Should include full schema-qualified name in FROM clause
if !strings.Contains(filter, "users") { if !strings.Contains(filter, "public.users") {
t.Errorf("Filter should reference table name users, got: %s", filter) t.Errorf("Filter FROM clause should use schema-qualified name public.users, got: %s", filter)
} }
t.Logf("Generated cursor filter with schema: %s", filter) t.Logf("Generated cursor filter with schema: %s", filter)

View File

@@ -32,6 +32,8 @@ func (opts *ExtendedRequestOptions) GetCursorFilter(
modelColumns []string, // optional: for validation modelColumns []string, // optional: for validation
expandJoins map[string]string, // optional: alias → JOIN SQL expandJoins map[string]string, // optional: alias → JOIN SQL
) (string, error) { ) (string, error) {
// Separate schema prefix from bare table name
fullTableName := tableName
if strings.Contains(tableName, ".") { if strings.Contains(tableName, ".") {
tableName = strings.SplitN(tableName, ".", 2)[1] tableName = strings.SplitN(tableName, ".", 2)[1]
} }
@@ -127,7 +129,7 @@ func (opts *ExtendedRequestOptions) GetCursorFilter(
WHERE cursor_select.%s = %s WHERE cursor_select.%s = %s
AND (%s) AND (%s)
)`, )`,
tableName, fullTableName,
joinSQL, joinSQL,
pkName, pkName,
cursorID, cursorID,

View File

@@ -187,9 +187,9 @@ func TestGetCursorFilter_WithSchemaPrefix(t *testing.T) {
t.Fatalf("GetCursorFilter failed: %v", err) t.Fatalf("GetCursorFilter failed: %v", err)
} }
// Should handle schema prefix properly // Should include full schema-qualified name in FROM clause
if !strings.Contains(filter, "users") { if !strings.Contains(filter, "public.users") {
t.Errorf("Filter should reference table name users, got: %s", filter) t.Errorf("Filter FROM clause should use schema-qualified name public.users, got: %s", filter)
} }
t.Logf("Generated cursor filter with schema: %s", filter) t.Logf("Generated cursor filter with schema: %s", filter)