Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.25.5

require (
github.com/Masterminds/squirrel v1.5.4
github.com/goravel/framework v1.16.1-0.20251204091854-4dcf6db5af43
github.com/goravel/framework v1.16.1-0.20251210102050-e17cc7a766bd
github.com/spf13/cast v1.10.0
github.com/stretchr/testify v1.11.1
gorm.io/driver/postgres v1.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQ
github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl7wAo=
github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0=
github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w=
github.com/goravel/framework v1.16.1-0.20251204091854-4dcf6db5af43 h1:00SPBQnjk1n2hSDtQO8KrJBYfPkHOXrR0wR5wY2ZssU=
github.com/goravel/framework v1.16.1-0.20251204091854-4dcf6db5af43/go.mod h1:JBTmsY7yAM2i4j6iiPqBrK7H7YJYV/CYQdnOBwmsXoQ=
github.com/goravel/framework v1.16.1-0.20251210102050-e17cc7a766bd h1:/K1urDWnJgLi4Cy5oyZN0N5CjcBcmiOGK8nyhmhVxoE=
github.com/goravel/framework v1.16.1-0.20251210102050-e17cc7a766bd/go.mod h1:N4Q6ljvGDF4Kh9A4Bjajv5okcrfO94BHlPJglP+oUY8=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
Expand Down
80 changes: 39 additions & 41 deletions setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

func main() {
setup := packages.Setup(os.Args)
config := `map[string]any{
"host": config.Env("DB_HOST", "127.0.0.1"),
"port": config.Env("DB_PORT", 5432),
Expand All @@ -29,56 +30,53 @@ func main() {

appConfigPath := path.Config("app.go")
databaseConfigPath := path.Config("database.go")
modulePath := packages.GetModulePath()
moduleImport := setup.Paths().Module().Import()
postgresServiceProvider := "&postgres.ServiceProvider{}"
driverContract := "github.com/goravel/framework/contracts/database/driver"
postgresFacades := "github.com/goravel/postgres/facades"
databaseConnectionsConfig := match.Config("database.connections")
databaseConfig := match.Config("database")

packages.Setup(os.Args).
Install(
// Add postgres service provider to app.go if not using bootstrap setup
modify.When(func(_ map[string]any) bool {
return !env.IsBootstrapSetup()
}, modify.GoFile(appConfigPath).
Find(match.Imports()).Modify(modify.AddImport(modulePath)).
Find(match.Providers()).Modify(modify.Register(postgresServiceProvider))),
setup.Install(
// Add postgres service provider to app.go if not using bootstrap setup
modify.When(func(_ map[string]any) bool {
return !env.IsBootstrapSetup()
}, modify.GoFile(appConfigPath).
Find(match.Imports()).Modify(modify.AddImport(moduleImport)).
Find(match.Providers()).Modify(modify.Register(postgresServiceProvider))),

// Add postgres service provider to providers.go if using bootstrap setup
modify.When(func(_ map[string]any) bool {
return env.IsBootstrapSetup()
}, modify.AddProviderApply(modulePath, postgresServiceProvider)),
// Add postgres service provider to providers.go if using bootstrap setup
modify.When(func(_ map[string]any) bool {
return env.IsBootstrapSetup()
}, modify.AddProviderApply(moduleImport, postgresServiceProvider)),

// Add postgres connection to database.go
modify.GoFile(databaseConfigPath).Find(match.Imports()).Modify(
modify.AddImport(driverContract),
modify.AddImport(postgresFacades, "postgresfacades"),
).
Find(databaseConnectionsConfig).Modify(modify.AddConfig("postgres", config)).
Find(databaseConfig).Modify(modify.AddConfig("default", `"postgres"`)),
// Add postgres connection to database.go
modify.GoFile(databaseConfigPath).Find(match.Imports()).Modify(
modify.AddImport(driverContract),
modify.AddImport(postgresFacades, "postgresfacades"),
).
Uninstall(
// Remove postgres connection from database.go
modify.GoFile(databaseConfigPath).
Find(databaseConfig).Modify(modify.AddConfig("default", `""`)).
Find(databaseConnectionsConfig).Modify(modify.RemoveConfig("postgres")).
Find(match.Imports()).Modify(
modify.RemoveImport(driverContract),
modify.RemoveImport(postgresFacades, "postgresfacades"),
),
Find(databaseConnectionsConfig).Modify(modify.AddConfig("postgres", config)).
Find(databaseConfig).Modify(modify.AddConfig("default", `"postgres"`)),
).Uninstall(
// Remove postgres connection from database.go
modify.GoFile(databaseConfigPath).
Find(databaseConfig).Modify(modify.AddConfig("default", `""`)).
Find(databaseConnectionsConfig).Modify(modify.RemoveConfig("postgres")).
Find(match.Imports()).Modify(
modify.RemoveImport(driverContract),
modify.RemoveImport(postgresFacades, "postgresfacades"),
),

// Remove postgres service provider from app.go if not using bootstrap setup
modify.When(func(_ map[string]any) bool {
return !env.IsBootstrapSetup()
}, modify.GoFile(appConfigPath).
Find(match.Providers()).Modify(modify.Unregister(postgresServiceProvider)).
Find(match.Imports()).Modify(modify.RemoveImport(modulePath))),
// Remove postgres service provider from app.go if not using bootstrap setup
modify.When(func(_ map[string]any) bool {
return !env.IsBootstrapSetup()
}, modify.GoFile(appConfigPath).
Find(match.Providers()).Modify(modify.Unregister(postgresServiceProvider)).
Find(match.Imports()).Modify(modify.RemoveImport(moduleImport))),

// Remove postgres service provider from providers.go if using bootstrap setup
modify.When(func(_ map[string]any) bool {
return env.IsBootstrapSetup()
}, modify.RemoveProviderApply(modulePath, postgresServiceProvider)),
).
Execute()
// Remove postgres service provider from providers.go if using bootstrap setup
modify.When(func(_ map[string]any) bool {
return env.IsBootstrapSetup()
}, modify.RemoveProviderApply(moduleImport, postgresServiceProvider)),
).Execute()
}