Documentation
¶
Overview ¶
Integrates with migration tools recognizing the standard "migrate up" and "migrate down" annotations, simplifying asset database schema management and rollbacks in Postgres.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Migrations ¶
Migrations returns the migrations for the postgres database.
Example ¶
user := "postgres" if u, ok := os.LookupEnv("POSTGRES_USER"); ok { user = u } password := "postgres" if p, ok := os.LookupEnv("POSTGRES_PASSWORD"); ok { password = p } dbname := "postgres" if db, ok := os.LookupEnv("POSTGRES_DB"); ok { dbname = db } log.Printf("DSN: %s", fmt.Sprintf("host=localhost port=5432 user=%s password=%s dbname=%s", user, password, dbname)) dsn := fmt.Sprintf("host=localhost port=5432 user=%s password=%s dbname=%s", user, password, dbname) db, err := gorm.Open(pg.Open(dsn), &gorm.Config{}) if err != nil { panic("failed to connect database") } sqlDb, _ := db.DB() migrationsSource := migrate.EmbedFileSystemMigrationSource{ FileSystem: Migrations(), Root: "/", } _, err = migrate.Exec(sqlDb, "postgres", migrationsSource, migrate.Up) if err != nil { panic(err) } tables := []string{"entities", "entity_tags", "edges", "edge_tags"} for _, table := range tables { fmt.Println(db.Migrator().HasTable(table)) }
Output: true true true true
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.