Skip to content

Conversation

Sbaia
Copy link

@Sbaia Sbaia commented Aug 30, 2025

This pull request introduces a new database driver for Trino, enabling migrate to manage schema migrations on data sources connected through the Trino query engine.

Purpose

Trino is a distributed SQL query engine designed to query large data sets distributed over one or more heterogeneous data sources. By adding Trino support to migrate, we empower users to manage database schemas for a wide array of modern data platforms, such as data lakes built on Iceberg, Parquet, and S3, directly through a familiar migration workflow.

This driver is particularly valuable for data-intensive applications where schema evolution needs to be version-controlled and synchronized across different underlying systems.

Implementation Details

  1. New Trino Driver (database/trino/trino.go)

    • A new driver has been implemented that satisfies the database.Driver interface.
    • It uses the official Trino Go client (trinodb/trino-go-client) to interact with the Trino REST API.
    • It handles the creation and management of a schema_migrations table to track migration versions and state.
  2. Connection Handling

    • The driver supports a trino:// connection string, which is automatically converted to http:// or https:// based on the ssl query parameter.
    • It securely defaults to https:// for all connections unless explicitly disabled via ?ssl=false.
  3. Core Functionality

    • Open(): Establishes a connection to the Trino coordinator.
    • Run(): Executes migration scripts (SQL statements).
    • SetVersion() / Version(): Manages the migration version and dirty status in the schema_migrations table.
    • Drop(): Cleans up the schema by dropping all tables within it.
    • Lock() / Unlock(): Provides an in-memory advisory lock to prevent concurrent migration runs.
  4. Configuration

    • The driver is configurable via URL query parameters, allowing users to specify the catalog, schema, x-migrations-table, and other settings.
  5. Integration Tests (database/trino/trino_test.go)

    • A comprehensive test suite has been added, which uses a Docker container (trinodb/trino) to run tests against a live Trino instance.
    • Tests cover the full migration lifecycle, including applying migrations, version tracking, and rollbacks.

Documentation

  • A README.md has been added to the database/trino directory, providing clear instructions on how to use the driver, format the connection string, and configure the available parameters.

This new driver significantly expands the capabilities of migrate, bringing modern, large-scale data platforms into its ecosystem.

Sbaia added 7 commits August 29, 2025 00:03
This commit introduces a new file `build_trino.go` that sets up the build constraints for the Trino database. It imports the necessary Trino database driver from the `github.com/golang-migrate/migrate/v4` package, enabling migration support for Trino within the CLI.
…nagement, and add unit tests for configuration and driver registration
…e and update queries for version retrieval and insertion
…ble and enhance connection handling with scheme conversion in trino.go; add tests for scheme conversion in trino_test.go
@Copilot Copilot AI review requested due to automatic review settings August 30, 2025 14:58
Copy link

@Copilot 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 pull request adds support for Trino as a new database driver for the migrate tool, enabling schema migration management for data sources connected through the Trino distributed SQL query engine. The implementation allows users to manage database schemas for modern data platforms like data lakes built on Iceberg, Parquet, and S3.

Key changes include:

  • Implementation of a complete Trino database driver with full migration lifecycle support
  • Connection string handling with automatic scheme conversion from trino:// to HTTP/HTTPS based on SSL configuration
  • Comprehensive test suite with Docker-based integration tests and unit tests

Reviewed Changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
database/trino/trino.go Core driver implementation with migration table management, version tracking, and advisory locking
database/trino/trino_test.go Integration tests using Docker container for live Trino testing
database/trino/unit_test.go Unit tests for driver registration, configuration, and interface compliance
go.mod Dependency updates including Trino Go client and related packages
internal/cli/build_trino.go Build tag file for conditional Trino driver inclusion
database/trino/examples/migrations/ Example migration files demonstrating Trino-specific SQL patterns
database/trino/README.md Documentation for connection strings, parameters, and usage guidelines
README.md Updated main README to list Trino as supported database
Makefile Added Trino to DATABASE variable for build system

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

Comment on lines +241 to +245
SELECT table_name
FROM information_schema.tables
WHERE table_catalog = '%s'
AND table_schema = '%s'
AND table_type = 'BASE TABLE'`,
Copy link
Preview

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

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

SQL injection vulnerability: the catalog and schema names are directly interpolated into the SQL string without proper escaping or parameterization. Use parameterized queries or properly escape the values.

Copilot uses AI. Check for mistakes.

Comment on lines +168 to +169
query = fmt.Sprintf("SELECT version, dirty FROM %s.%s.%s ORDER BY sequence DESC LIMIT 1",
t.config.MigrationsCatalog, t.config.MigrationsSchema, t.config.MigrationsTable)
Copy link
Preview

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

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

SQL injection vulnerability: catalog, schema, and table names are directly interpolated into the SQL string. These values should be properly escaped or validated to prevent SQL injection attacks.

Copilot uses AI. Check for mistakes.

Comment on lines +188 to +191
migrationsTable := fmt.Sprintf("%s.%s.%s",
t.config.MigrationsCatalog, t.config.MigrationsSchema, t.config.MigrationsTable)

insertQuery := fmt.Sprintf("INSERT INTO %s (version, dirty, sequence) VALUES (?, ?, ?)", migrationsTable)
Copy link
Preview

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

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

SQL injection vulnerability: the table name is constructed using string concatenation without proper escaping. While the values themselves use parameterized queries, the table name should also be properly escaped.

Copilot uses AI. Check for mistakes.

Comment on lines +215 to +224
migrationsTable := fmt.Sprintf("%s.%s.%s",
t.config.MigrationsCatalog, t.config.MigrationsSchema, t.config.MigrationsTable)

// Use CREATE TABLE IF NOT EXISTS for safe concurrent table creation
createQuery := fmt.Sprintf(`
CREATE TABLE IF NOT EXISTS %s (
version BIGINT NOT NULL,
dirty BOOLEAN NOT NULL,
sequence BIGINT NOT NULL
)`, migrationsTable)
Copy link
Preview

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

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

SQL injection vulnerability: the table name is directly interpolated into the CREATE TABLE statement without proper escaping. This could allow SQL injection if the catalog, schema, or table names contain malicious content.

Copilot uses AI. Check for mistakes.

Comment on lines +265 to +266
dropQuery := fmt.Sprintf("DROP TABLE IF EXISTS %s.%s.%s",
t.config.MigrationsCatalog, t.config.MigrationsSchema, tableName)
Copy link
Preview

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

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

SQL injection vulnerability: catalog, schema, and table names are directly interpolated into the DROP TABLE statement without proper escaping. This is particularly dangerous as it's used in a loop to drop multiple tables.

Copilot uses AI. Check for mistakes.

@coveralls
Copy link

Coverage Status

coverage: 54.441% (+0.4%) from 54.037%
when pulling 388ada0 on Sbaia:master
into 8b9c5f7 on golang-migrate:master.

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