Skip to content

Fix: Use fully qualified table names for DLSync metadata tables#57

Merged
sfc-gh-yhailu merged 2 commits intoSnowflake-Labs:mainfrom
NemSimpraga:fix/fully-qualified-metadata-tables
Feb 5, 2026
Merged

Fix: Use fully qualified table names for DLSync metadata tables#57
sfc-gh-yhailu merged 2 commits intoSnowflake-Labs:mainfrom
NemSimpraga:fix/fully-qualified-metadata-tables

Conversation

@NemSimpraga
Copy link
Contributor

@NemSimpraga NemSimpraga commented Feb 4, 2026

Problem

When DLSync manages account-level objects (databases or schemas), it breaks with errors like:

  • Table 'DL_SYNC_SCRIPT_HISTORY' does not exist or not authorized
  • Similar errors for DL_SYNC_SCRIPT_EVENT and DL_SYNC_CHANGE_SYNC tables

Root Cause

When Snowflake executes CREATE DATABASE or CREATE SCHEMA commands, it automatically changes the session context to the newly created database/schema. Since DLSync uses non-fully-qualified table names for its metadata tables, subsequent queries fail because they look for the tables in the new context instead of the original DLSync schema.

Solution

This PR updates all references to DLSync metadata tables to use fully qualified names in the format database.schema.table_name.

Changes Made

  1. Added helper methods to generate fully qualified table names:

    • getFullyQualifiedTableName(String tableName)
    • getFullyQualifiedChangeSyncTable()
    • getFullyQualifiedScriptHistoryTable()
    • getFullyQualifiedScriptEventTable()
    • getFullyQualifiedDependencyLineageTable()
  2. Updated all SQL queries in ScriptRepo.java to use these helper methods, ensuring all references to metadata tables are fully qualified regardless of the current session context.

Testing

Tested with a custom Docker image deploying account-level objects (databases and schemas). The fix successfully prevents the session context issue and DLSync operations complete without errors.

Impact

This fix ensures DLSync can manage account-level objects without breaking, making it fully compatible with all object types it claims to support.

Fixes the issue reported in the repository discussions.

References #56

@snyk-io
Copy link
Contributor

snyk-io bot commented Feb 4, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Copy link
Collaborator

@sfc-gh-yhailu sfc-gh-yhailu left a comment

Choose a reason for hiding this comment

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

Hi @NemSimpraga this is great. I have added some comments. Instead of creating and using the getFullyQualified for each table, Can we use the method getFullyQualifiedTableName() instead ?
To help for the release automation, And can you also update the following:

  1. update the version in gradle.properties file to releaseVersion=3.0.1
  2. add your change log to CHANGELOG.md file.
    other than that it looks good to me.

- Remove redundant wrapper methods, use getFullyQualifiedTableName() directly
- Update version to 3.0.1 in gradle.properties
- Add changelog entry for the fix
@NemSimpraga NemSimpraga force-pushed the fix/fully-qualified-metadata-tables branch from e9f1bbb to 2effb7f Compare February 5, 2026 12:53
@sfc-gh-yhailu sfc-gh-yhailu self-requested a review February 5, 2026 20:11
Copy link
Collaborator

@sfc-gh-yhailu sfc-gh-yhailu left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@sfc-gh-yhailu sfc-gh-yhailu merged commit e2f9d20 into Snowflake-Labs:main Feb 5, 2026
3 checks 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.

2 participants