Skip to content

Commit

Permalink
docs: update instructions for importing database driver in amigo main…
Browse files Browse the repository at this point in the history
… file
  • Loading branch information
alexisvisco committed Nov 5, 2024
1 parent 924fee5 commit 631d00b
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion docs/docs/02-quick-start/03-running-your-first-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,35 @@

Since you have initialized mig, you can now run your first migration.

Before that make sure to import the driver that amigo have added in the imports of the main file in `.amigo/main.go`.
Before that make sure to import the driver that amigo have added in the imports of the main file in `migrations/db/main.go`.

Here is an example of amigo main:

```go
package main

import (
"database/sql"
migrations "github.com/alexisvisco/gwt/migrations"
"github.com/alexisvisco/amigo/pkg/entrypoint"
"github.com/alexisvisco/amigo/pkg/utils/events"
"github.com/alexisvisco/amigo/pkg/utils/logger"
_ "github.com/jackc/pgx/v5/stdlib" // <- you can switch to any driver that support the database/sql package
"os"
)

func main() {
opts, arg := entrypoint.AmigoContextFromFlags()

db, err := sql.Open("pgx", opts.GetRealDSN()) // <- change this line too, the dsn is what you provided in the parameter or context configuration
if err != nil {
logger.Error(events.MessageEvent{Message: err.Error()})
os.Exit(1)
}

entrypoint.Main(db, arg, migrations.Migrations, opts)
}
```

By default for postgres it imports `github.com/jackc/pgx/v5/stdlib` but you can change it and it will works.

Expand Down

0 comments on commit 631d00b

Please sign in to comment.