Extract generic migration logic into datastores/sql/migrate package

Move database-agnostic migration logic (file discovery, version tracking,
bootstrap detection) into a shared migrate package behind a Dialect
interface, leaving postgres as a thin wrapper.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-20 20:10:11 -05:00
parent d403e18d25
commit aceea44c90
3 changed files with 216 additions and 179 deletions

View File

@@ -0,0 +1,15 @@
package postgres
import "fmt"
// Dialect implements migrate.Dialect for PostgreSQL.
type Dialect struct{}
// Placeholder returns PostgreSQL's positional bind parameter ($1, $2, …).
func (Dialect) Placeholder(n int) string { return fmt.Sprintf("$%d", n) }
// TableExistsQuery returns a query that checks whether a table exists in
// PostgreSQL using information_schema.
func (Dialect) TableExistsQuery() string {
return "SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_name = $1)"
}