55 Commits
Author SHA1 Message Date
e40cf943ca ci: update golangci-lint to v2 (#1341)
* ci: update golangci-lint to v2

update method:
```
golangci-lint migrate
golangci-lint run --fix
```

and fix the last ones manually

* Apply suggestion from @Copilot

* fix tests

---------

Co-authored-by: Hanzo Dev <[email protected]>
2025-12-14 15:14:46 -08:00
leonklingeleandGitHub 426470006b chore: remove dependency on "hashicorp/go-multierror" (#1322)
* feat: remove dependency on "hashicorp/go-multierror"

It seems the project has been unmainted for quite some time already,
see for example https://github.com/hashicorp/go-multierror/issues/97
and https://github.com/hashicorp/go-multierror/issues/98.
This also removes an uneccessary dependency which slims down the go.mod.

Go as of version 1.20 supports appending errors by specifying
multiple "%w" formatters in the "fmt.Errorf"[^0] function.

[^0]: https://pkg.go.dev/fmt#Errorf

* feat: use errors.Join to combine multiple errors

As an update to the previous commit 59f084ea3be2e7ec9d912c1a311402b1e4c40df6,
use "errors.Join"[^0] instead of multiple "%w" formatters for "fmt.Errorf".

[^0]: https://pkg.go.dev/errors#Join

* chore: bring back unused util.go file as removing it is a breaking change
2025-11-29 11:37:42 -08:00
Roman SharkovandGitHub 34fa67d9f6 Merge pull request #1303 from romshark/master
refactor: Remove go.uber.org/atomic in favor of std sync/atomic
2025-08-20 16:35:25 -07:00
Oleksandr Redko fca627ee8e Remove redundant build tags 2025-04-17 23:57:28 +03:00
Vladimir Galunshchikov 0f106462cb fix: postgresql search_path can be empty (#696) 2023-04-06 23:48:03 +02:00
Abhinav Nair baec8ed6b6 Replace deprecated ioutil pkg with os & io
As of Go 1.16, the same functionality is now provided by package io or
package os, and those implementations should be preferred in new code.

So replacing all usage of ioutil pkg with io & os.
2022-06-26 16:57:29 +08:00
Andreas Kluth e08ebbab82 Add WithConnection to Postgres similar to MySQL. 2021-11-29 15:50:04 +01:00
Dale Hui 1294fa4cfa Update build constraints
Issue caught by linter

https://pkg.go.dev/go/build#hdr-Build_Constraints
https://pkg.go.dev/cmd/go#hdr-Build_constraints
https://go.googlesource.com/proposal/+/master/design/draft-gobuild.md
2021-09-10 21:04:11 -07:00
bef0635743 used uber atomic bool instead standard in lock/unlock db (#580)
* used uber atomic bool instead standard in lock/unlock db

* fixing local lock optimization implementation

* fixing mysql local lock optimization implementation

* fixing cockroachdb local lock optimization implementation

* CAS wrapper to automatically restore

* added test for cas with restore

* added atomic lock to sqlite & mongo

* added atomic lock to sqlite & mongo

* fix/refactor test cas restore function

* disable lock for mongo

* mongo local lock before acquiring the db lock

Co-authored-by: a.prinkov <[email protected]>
2021-06-23 14:40:50 -07:00
Stéphane Klein b10f5e9868 postgres,pgx: fix SchemaName parameter is ignored ##547 2021-04-25 07:34:19 +02:00
Stéphane KleinandGitHub 267936eff9 Postgres - add x-migrations-table-quoted url query option (#95) (#533)
* Postgres and pgx - Add x-migrations-table-quoted url query option to postgres and pgx drivers (#95)

By default, gomigrate quote migrations table name, if `x-migrations-table-quoted` is enabled, then you must to quote migrations table name manually, for instance `"gomigrate"."schema_migrations"`

* Work In Progress
2021-04-19 14:57:50 -07:00
testtest959andGitHub 06029ba265 Postgres: Add a check to determine if table already exists to elide CREATE query (#526)
* Squash commits

* Format

* Minor refactoring

* Address PR feedback; Add mustRun

* Fix a test assert
2021-03-18 21:03:57 -07:00
Dale Hui 15f7a994b2 Use strconv.ParseBool() to parse the x-multi-statement option in the postgres driver 2021-02-03 22:59:24 -08:00
Anatoly Rugalev f19abe070c Addressed review comments 2021-02-02 11:24:33 +01:00
Anatoly Rugalev 32963ee38f Support multi-statement execution for PostgreSQL 2021-01-18 12:16:37 +03:00
Igor Zibarev 2a7a3a7c7a Check iterator error on Drop where applicable 2020-10-10 23:53:20 +03:00
Dale Hui bdeb9a83fe Correctly mark migrations as dirty when the first down migration fails
Fixes: https://github.com/golang-migrate/migrate/issues/330

Other changes:
  - Cleanup code by using the database.NilVersion constant instead of the magic number -1
2020-04-06 00:07:15 -07:00
a7f74d4466 add statement timeout query param for postgres (#327)
* add statement timeout query param for postgres

* Update database/postgres/postgres.go

Co-Authored-By: Roopak Venkatakrishnan <[email protected]>

* add enable flag

* remove deafult catch errors

* reformat

* only use background context for 0 timeout

* refactor

* refactor

Co-authored-by: Pranay Suresh <[email protected]>
Co-authored-by: Roopak Venkatakrishnan <[email protected]>
2020-01-21 11:22:41 -08:00
Dale Hui a25d1fcaa9 Actually use schema and db names specified in postgres db config
Addresses: https://github.com/golang-migrate/migrate/issues/262
2019-10-13 23:24:10 -07:00
Calvin Tuong d1ec7ba5aa Update postgres driver Lock comment to reflect actual behavior 2019-09-24 13:57:01 -07:00
Kirill MuratovandDale Hui 8afa5fa221 Enabled maligned, staticcheck and errcheck linters (#206)
* Enabled maligned check

* Enabled staticcheck

* Fixes for golint

* Enabled errcheck linter

* Added fixes for error check

* Added errcheck for tests

* Fixed test

* Increased golangci-lint deadline for travis

* Increased golangci-lint deadline for travis

* Decreased golangci-lint deadline for travis

* Revert for backward compatibility

* Using log.Println() instead of fmt.Println()

* Handling os.RemoveAll() errors

* Using t.Error(error) instead of t.Errorf("%v", err)

* Using t.Fatal(error) instead of t.Fatalf("%v", err)

* Using fmt.Sprint(sum) instead of t.Srintf("%v", sum)

* Refactoring

* Revert for backward compatibility

* Revert

* go mod tidy

* Added error logging

* Added error logging

* Added error handling

* Added error handling

* Added error logging

* Fix error logging

* Added error handling

* Fix

* Added logging for migr.Buffer()

* Fixes

* Firebird test disabled

* Fixed nolint comment

* Updated firebird docker image version

* Disabled test for firebird 2.5

* Fixed // nolint
2019-04-26 15:47:16 -07:00
Kirill MuratovandDale Hui fea2fd1741 Added Firebird support (#191)
* Added Firebird support

* Fixed typo

* Refactoring

* Schema migrations table name don't have to be upper case

* Fixed readme

* Added Firebird 2.5 support

* Removed SchemaName

* Refactoring
2019-03-21 01:51:49 -07:00
Lukas JoergensenandDale Hui 1cc735c192 postgres: Move lock out of ensureVersionTable, for consistency with other SQL operations (#173)
* Consistently lock in ensureVersionTable and do not call ensureVersionTable from Drop across all database implementations

* Add test for dropping postgres databases

* Fix failing database tests

* Fix CockroachDb test, lock table should be created before versionTable

* Add Initialize() to Driver interface, and add integration tests for Drop() between database implementations and migrate

* Remove Initialize, document breaking behaviour of Drop

* Revert introduction of Initialize method

* Removed Initialize in Stub as well

* Remove call to non-existent Initialize and make sure to close re-initialized database connections

* Revert changes to TestDrop in database/testing

* Split Test and TestMigrate into different test entrypoints

* Remove unused import in migrate_testing

* Remove erroneous code to fix tests

* Add stub source imports to database tests

* Add Stub source to migrate tests

* Use example migrations for tests

* Add file driver to database tests

* Align database directory layout

* Add file source driver to Cassandra

* Review changes

* Minor syntactic change for cleaner diff
2019-02-26 15:56:57 -08:00
Jesse Szwedko 6c1f149746 Replace " quoting with pq.QuoteIdentifier for postgres driver 2019-02-18 11:44:38 +01:00
Jesse Szwedko 00d8f2956a Quote postgres table identifiers when DROPing
Handles table identifiers that are invalid without quotes (such as
uppercase letters).
2019-02-18 11:29:10 +01:00
Tomás Senart 4028eca4f5 fixup! More explicit conditionals 2019-01-15 11:28:49 +01:00
Tomás Senart 317883e4db postgres: Revert back to use CREATE IF NOT EXISTS 2019-01-15 11:28:49 +01:00
Tomás Senart 12e427b0ee postgres: Use multierror.Error in ensureVersionTable 2019-01-15 11:28:49 +01:00
Tomás Senart 90ce263ff7 postgres: Query table existance in ensureVersionTable
This commit reverts back to querying the existance of the table instead
of using CREATE IF NOT EXISTS because we want to support versions of
Postgres older than 9.1 which is when this feature was introduced.
2019-01-15 11:28:48 +01:00
Tomás Senart ebb0da0f4c postgres: Preserve Unlock error when outer err isn't nil 2019-01-15 11:28:48 +01:00
Tomás Senart b1407e80cb postgres: Make ensureVersionTable atomic
Fixes https://github.com/golang-migrate/migrate/issues/55
2019-01-15 11:28:48 +01:00
Dale Hui 466e58b7ea Unlock in postgres db driver should also use the schema name 2018-11-14 02:18:57 -08:00
Evgeniy Bastrykov ddcb997369 Add support for multi-schema migrations in Postgres
There is lock conflict on parallel migrations in different postgres
schemas. To avoid this conflicts function GenerateAdvisoryLockId added
variadic params to change lock id with schema name. Schema name taked
with postgres CURRENT_SCHEMA function. Null byte used as separator
between database and schema name, because any other symbol may be used
in both of it.

Closes #118
2018-11-05 12:56:38 +04:00
Dale Hui e2a6017efd Use v4 for Go module support 2018-10-10 16:16:23 -07:00
Dale Hui 2b1b184f7f Revert "Remove support for Go modules"
This reverts commit 781565f251.
2018-10-10 16:15:33 -07:00
Dale Hui 781565f251 Remove support for Go modules 2018-10-10 13:34:03 -07:00
Mike Fitzgerald 4784fcf4be Fix postgres drop 2018-10-04 01:22:39 -04:00
Dale Hui 898723524b Fix module support by opting in to modules 2018-09-14 01:14:42 -07:00
Kay-Zee ee94000044 Add sql.DB to Postgres and Mysql structs to allow closing in Close() 2018-09-06 17:16:02 -07:00
Damir Vandic 7b062e3a90 Support postgres non-ascii error parsing 2018-07-09 11:39:29 +02:00
Damir Vandic 3d8ce20d47 Add postgres lib/pq error parsing 2018-07-07 12:17:38 +02:00
Teddy Schmitz 2e05b039ea postgres driver should wait for lock 2018-06-01 09:11:24 +08:00
Dale Hui 55129a24e7 Rename Postgres.db to Postgres.conn 2018-02-20 15:40:20 -08:00
Dale Hui 11f4059c1c Merge remote-tracking branch 'origin/master' into postgres-lock-fix 2018-02-20 15:32:34 -08:00
Dale Hui 75bf87f76c Update imports to reference fork.
Thanks `make rewrite-import-paths`!
2018-01-19 10:56:55 -08:00
Teddy Schmitz 6ee0a34b96 Use db.Conn to fix postgres lock/unlock 2017-10-27 10:56:10 +08:00
kshvakov 7677fe30e8 postgres: fix SetVersion. All requests were executed in different connections so commit/rollback doesn't work correctly 2017-06-23 11:13:54 +03:00
Arkadiusz Bokowy ecad904fda Support for alternative postgres URI scheme
According to the PostgreSQL documentation (section 32.1.1.2), postgres
library supports two URI schemes: postgresql:// and postgres://

Reference:
https://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-CONNSTRING
2017-04-04 08:29:33 +02:00
Matthias Kadenbach 54bd45727f add mysql driver, add ENV to docker containers 2017-02-28 15:10:56 -08:00
Matthias Kadenbach c30f8d6db2 bring back dirty state from v2 2017-02-19 15:15:00 -08:00