make package
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"git.petrovv.com/go-migrate/lib"
|
||||
"git.petrovv.com/go-migrate"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
@@ -44,13 +44,13 @@ func generateMigrations(schemaDir string) {
|
||||
defer db.Close()
|
||||
ctx := context.Background()
|
||||
|
||||
migrations, err := lib.GetMigrations(ctx, db, schemaDir)
|
||||
migrations, err := migrate.GetMigrations(ctx, db, schemaDir)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if len(migrations) == 0 {
|
||||
fmt.Println("✓ Database schema is up to date")
|
||||
fmt.Println("Database schema is up to date")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -66,13 +66,13 @@ func applyMigrations(schemaDir string) {
|
||||
defer db.Close()
|
||||
ctx := context.Background()
|
||||
|
||||
migrations, err := lib.GetMigrations(ctx, db, schemaDir)
|
||||
migrations, err := migrate.GetMigrations(ctx, db, schemaDir)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if len(migrations) == 0 {
|
||||
fmt.Println("✓ Database schema is up to date")
|
||||
fmt.Println("Database schema is up to date")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ func applyMigrations(schemaDir string) {
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("✓ All migrations applied successfully")
|
||||
fmt.Println("All migrations applied successfully")
|
||||
}
|
||||
|
||||
func getDBConnection() *pgxpool.Pool {
|
||||
@@ -1,4 +1,4 @@
|
||||
package lib
|
||||
package migrate
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -981,10 +981,13 @@ func parseForeignKey(def string) *ForeignKey {
|
||||
return fk
|
||||
}
|
||||
|
||||
// LoadDesiredSchema loads schema definitions from SQL files in the given directory
|
||||
func LoadDesiredSchema(dir string) (*Schema, error) {
|
||||
return loadDesiredSchema(dir)
|
||||
}
|
||||
|
||||
// GetMigrations compares the current database schema with the desired schema
|
||||
// and returns a list of SQL migration statements
|
||||
func GetMigrations(ctx context.Context, db *pgxpool.Pool, schemaDir string) ([]string, error) {
|
||||
// Load current database schema
|
||||
currentSchema, err := GetCurrentSchema(ctx, db)
|
||||
Reference in New Issue
Block a user