Skip to content
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

AutoMigrate for Postgres dialect #926

Merged
merged 55 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
95c4a8e
feat: add support type for net/netip.addr and net/netip.prefix (#1028)
Aoang Oct 17, 2024
e04de83
test: allow passing go test flags to test.sh
bevzzz Oct 21, 2023
8857bab
feat: detect renamed tables
bevzzz Oct 21, 2023
5060e47
feat: implement fmt.Stringer queries
bevzzz Oct 31, 2023
6dfdf95
test: cleanup test databases to avoid side-effects
bevzzz Oct 31, 2023
c03938f
feat(automigrate): detect renamed tables
bevzzz Oct 31, 2023
27a5a2b
chore: re-organize packages
bevzzz Nov 1, 2023
a8788bf
feat: use *bun.DB in MigratorDialect
bevzzz Nov 1, 2023
75a6f2b
chore: re-organize packages
bevzzz Nov 1, 2023
408859f
feat: detect Create/Drop table
bevzzz Nov 3, 2023
a918dc4
feat: detect modified relations
bevzzz Nov 5, 2023
4c1dfdb
feat: migrate FKs
bevzzz Nov 9, 2023
a822fc5
feat: improve FK handling
bevzzz Nov 11, 2023
886d0a5
feat: detect renamed columns
bevzzz Nov 17, 2023
1322895
chore: resolve dependencies
bevzzz Dec 9, 2023
94cecaf
refactor: remove AlterTableQuery bloat and fix test errors
bevzzz Aug 3, 2024
3cfd8c6
feat: change column type
bevzzz Aug 3, 2024
c3253a5
fix: ignore case for type equivalence
bevzzz Oct 20, 2024
a525038
test: use cmpColumns helper in cmpTables
bevzzz Oct 20, 2024
dd83779
feat: add and drop IDENTITY
bevzzz Oct 20, 2024
3fdd5b8
feat: add and drop columns
bevzzz Oct 21, 2024
ebe1d5d
refactor: remove superficial sqlschema.Operation interface
bevzzz Oct 21, 2024
fed6012
fix: rename column only if the name does not exist in 'target'
bevzzz Oct 22, 2024
3c4d5d2
feat: support UNIQUE constraints
bevzzz Oct 22, 2024
5f6d494
chore: appease linter, initialize struct with named fields
bevzzz Oct 27, 2024
9b810de
fix: update schema.Field names
bevzzz Oct 27, 2024
d08fa40
fix: implement DefaultSchema for Oracle dialect
bevzzz Oct 27, 2024
b1ae32e
fix: cleanup after testUniqueRenamedTable
bevzzz Oct 27, 2024
694f873
fix: append IDENTITY to ADD COLUMN statement if needed
bevzzz Oct 27, 2024
a734629
feat: support modifying primary keys
bevzzz Oct 27, 2024
1ef10c5
test: run for all dialects
bevzzz Oct 28, 2024
4ce21a4
refactor: make MakeQueryBytes available to other library packages
bevzzz Nov 3, 2024
245e968
refactor: append SQL in dialects but delegate execution to migrator
bevzzz Nov 3, 2024
1bf7cfd
feat: create sql migrations and apply them
bevzzz Nov 3, 2024
7289f23
chore: add missing newline
bevzzz Nov 4, 2024
538bda1
refactor: replace noop Operation with a more fitting placeholder
bevzzz Nov 4, 2024
47a6865
refactor: simplify sqlschema package semantics
bevzzz Nov 4, 2024
8fe0261
refactor(sqlschema): introduce Schema, Table, and Column interfaces
bevzzz Nov 7, 2024
42fdced
chore: drop foreign key renames
bevzzz Nov 8, 2024
da0d8e3
ci: delete unused function, appease lintr
bevzzz Nov 8, 2024
c3320f6
feat: create transactional migration files
bevzzz Nov 8, 2024
b3a9697
chore: add in-code documentation
bevzzz Nov 8, 2024
2e5b2fa
rename ColumnDefinition to BaseColumn and tweak interface
vmihailenco Nov 9, 2024
acd2560
rename TableDefinition to BaseTable
vmihailenco Nov 9, 2024
8af7563
fix most tests
vmihailenco Nov 9, 2024
53eabcf
rename Schema to Database
vmihailenco Nov 9, 2024
a08c009
add orderedmap
vmihailenco Nov 10, 2024
9abdfca
remove go 1.22
vmihailenco Nov 10, 2024
30dc4db
add tz
vmihailenco Nov 10, 2024
6b0ddc1
refactor: move FQN to sqlschema package
bevzzz Nov 10, 2024
31ed582
fix: remove schema name from t.Name during bun-schema inspection
bevzzz Nov 10, 2024
4e96659
refactor: drop multi-schema support
bevzzz Nov 11, 2024
48811e0
refactor: retire sqlschema.FQN
bevzzz Nov 11, 2024
1799a0f
test: activate commented-out tests
bevzzz Nov 12, 2024
ac8d221
feat: include target schema name in migration name
bevzzz Nov 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
go-version: [1.22.x, 1.23.x]
go-version: [1.23.x]

services:
postgres:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test:
echo "go test in $${dir}"; \
(cd "$${dir}" && \
go test && \
env GOOS=linux GOARCH=386 go test && \
env GOOS=linux GOARCH=386 TZ= go test && \
go vet); \
done

Expand Down
3 changes: 1 addition & 2 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,5 @@ func (tx Tx) NewDropColumn() *DropColumnQuery {
//------------------------------------------------------------------------------

func (db *DB) makeQueryBytes() []byte {
// TODO: make this configurable?
return make([]byte, 0, 4096)
return internal.MakeQueryBytes()
}
6 changes: 4 additions & 2 deletions dbfixture/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/uptrace/bun/dbfixture

go 1.22
go 1.23

toolchain go1.23.2

replace github.com/uptrace/bun => ../

Expand All @@ -16,5 +18,5 @@ require (
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/sys v0.27.0 // indirect
)
4 changes: 2 additions & 2 deletions dbfixture/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IU
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
4 changes: 4 additions & 0 deletions dialect/mssqldialect/dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ func (d *Dialect) AppendSequence(b []byte, _ *schema.Table, _ *schema.Field) []b
return append(b, " IDENTITY"...)
}

func (d *Dialect) DefaultSchema() string {
return "dbo"
}

func sqlType(field *schema.Field) string {
switch field.DiscoveredSQLType {
case sqltype.Timestamp:
Expand Down
8 changes: 4 additions & 4 deletions dialect/mssqldialect/go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module github.com/uptrace/bun/dialect/mssqldialect

go 1.22.0
go 1.23

toolchain go1.22.6
toolchain go1.23.2

replace github.com/uptrace/bun => ../..

require (
github.com/uptrace/bun v1.2.5
golang.org/x/mod v0.21.0
golang.org/x/mod v0.22.0
)

require (
Expand All @@ -17,5 +17,5 @@ require (
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/sys v0.27.0 // indirect
)
8 changes: 4 additions & 4 deletions dialect/mssqldialect/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IU
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
4 changes: 4 additions & 0 deletions dialect/mysqldialect/dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ func (d *Dialect) AppendSequence(b []byte, _ *schema.Table, _ *schema.Field) []b
return append(b, " AUTO_INCREMENT"...)
}

func (d *Dialect) DefaultSchema() string {
return "mydb"
}

func sqlType(field *schema.Field) string {
if field.DiscoveredSQLType == sqltype.Timestamp {
return datetimeType
Expand Down
8 changes: 4 additions & 4 deletions dialect/mysqldialect/go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module github.com/uptrace/bun/dialect/mysqldialect

go 1.22.0
go 1.23

toolchain go1.22.6
toolchain go1.23.2

replace github.com/uptrace/bun => ../..

require (
github.com/uptrace/bun v1.2.5
golang.org/x/mod v0.21.0
golang.org/x/mod v0.22.0
)

require (
Expand All @@ -17,5 +17,5 @@ require (
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/sys v0.27.0 // indirect
)
8 changes: 4 additions & 4 deletions dialect/mysqldialect/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IU
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
4 changes: 4 additions & 0 deletions dialect/oracledialect/dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ func (d *Dialect) DefaultVarcharLen() int {
return 255
}

func (d *Dialect) DefaultSchema() string {
return "app"
}

func (d *Dialect) AppendSequence(b []byte, table *schema.Table, field *schema.Field) []byte {
return append(b, " GENERATED BY DEFAULT AS IDENTITY"...)
}
Expand Down
Loading
Loading