-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add DuckDB support with official driver and modern stdlib #1337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Originally written in https://github.com/kubecost/golang-migrate-duckdb/tree/mmd/make-importable Signed-off-by: Michael Dresser <michaelmdresser@gmail.com>
- Replace github.com/marcboeker/go-duckdb with github.com/duckdb/duckdb-go/v2 - Replace hashicorp/go-multierror with stdlib errors.Join (Go 1.20+) - Replace deprecated atomic.Bool.CAS with CompareAndSwap - Replace go.uber.org/atomic with sync/atomic
Rename migration table from gmg_schema_migrations to schema_migrations to match the convention used by other database drivers.
There was a problem hiding this 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 DuckDB database support to the golang-migrate library using the official DuckDB Go driver (v2.5.3+) and modernizes dependencies by replacing deprecated libraries with Go stdlib equivalents.
Key Changes:
- Integration of official DuckDB driver (
github.com/duckdb/duckdb-go/v2) with full migration support - Modernization: replaced deprecated
hashicorp/go-multierroranduber.org/atomicwith stdliberrors.Join()andsync/atomic - Standardization: changed migrations table from
gmg_schema_migrationstoschema_migrationsto align with other drivers
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
internal/cli/build_duckdb.go |
Build tag file to conditionally include DuckDB driver |
go.mod |
Added DuckDB v2.5.3 dependency and updated related transitive dependencies |
database/duckdb/duckdb.go |
Core DuckDB driver implementation with migration support |
database/duckdb/duckdb_test.go |
Test suite covering migration operations and configuration |
database/duckdb/examples/migrations/*.sql |
Example migration files for testing |
database/duckdb/README.md |
Documentation for DuckDB driver usage |
README.md |
Added DuckDB to list of supported databases |
Makefile |
Added duckdb to DATABASE_TEST targets |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| // ensureVersionTable checks if versions table exists and, if not, creates it. | ||
| // Note that this function locks the database, which deviates from the usual | ||
| // convention of "caller locks" in the Sqlite type. |
Copilot
AI
Nov 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment references 'Sqlite type' but this is the DuckDB driver. Update to 'DuckDB type' for accuracy.
| // convention of "caller locks" in the Sqlite type. | |
| // convention of "caller locks" in the DuckDB type. |
| @@ -0,0 +1 @@ | |||
| DROP TABLE IF EXISTS pets; No newline at end of file | |||
Copilot
AI
Nov 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The down migration drops the entire table instead of removing only the column added in the up migration. This is inconsistent with the up migration which only adds a column. Should be ALTER TABLE pets DROP COLUMN predator;
| DROP TABLE IF EXISTS pets; | |
| ALTER TABLE pets DROP COLUMN predator; |
2b30dfa to
8debcd4
Compare
Based on #1077
This PR adds DuckDB database support, based on the original work in #1077, with the following updates:
Updated DuckDB driver: Replaced
github.com/marcboeker/go-duckdbwith the officialgithub.com/duckdb/duckdb-go/v2driver (the project moved to the DuckDB organization starting with v2.5.0)Standard migrations table name: Changed from
gmg_schema_migrationstoschema_migrationsto match the convention used by other database drivers.Removed deprecated dependencies:
github.com/hashicorp/go-multierrorwith stdliberrors.Join()(Go 1.20+)go.uber.org/atomicwith stdlibsync/atomicatomic.Bool.CAS()withatomic.Bool.CompareAndSwap()Align config and tests with the sqlite3 driver
DuckDB driver features:
duckdb://path/to/file.dbschema_migrations)