#1126·goose

Pass a context and database handle to CreateTable

Author: ringercCreated Sep 22, 2026Updated Sep 27, 2026

The dialect API has CreateTable(string) string - so a dialect can only template in a table name into a table creation statement and return a bare string.

This prevents dialects from querying the DB to determine what might be required to create or update the Goose metadata table for the DB.

For example, on ClickHouse, Goose should use ENGINE = ReplicatedMergeTree on table creation when connected to a database using the Replicated engine. This is presently not possible without instrusive modifications to Goose core.

I suggest that the dialect itself should be handled a context object, a db connection-factory and access to goose/dialect settings rather than a concrete connection; it should be responsible for executing the table creation in this new API, so that it can:

  • Handle DB-specific errors properly (e.g. already exists vs syntax error)
  • Handle re-tryable problems internally
  • Introspect the DB and modify the table creation based on DB features or configuration
  • Return a well-defined set of db-independent exceptions to the caller for specific problems, wrapping the db-specific exception

For example, this would allow the clickhouse dialect to

  • Detect ENGINE = Replicated DBs and create the table with ENGINE = ReplicatedMergeTree so the metadata table content replicates
  • Detect ENGINE = Shared DBs (CH cloud) and omit ENGINE from the table so the correct default is used
  • Observe DDL replication and wait until the creation is replicated to peer nodes
  • Convert existing tables to the correct engine in-place when Goose is upgraded
  • Upgrade existing Goose metadata tables to a new schema when Goose is upgraded if a user-supplied option is passed to permit this

Happy to submit a PR for this, but thought I'd ask for opinions on it first.

I'd like to implement this, then use it to upgrade the clickhouse dialect by using the correct table type for the target DB and, on upgrade, converting the metadata table to the new safer schema I wrote for https://github.com/pressly/goose/pull/1107 .

IMO dialects should always be running their own SQL directly, so they can properly control session-level settings.