make package

This commit is contained in:
2026-05-31 16:11:06 +02:00
parent 4898b6ab27
commit 7375d2d168
2 changed files with 10 additions and 7 deletions

View File

@@ -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 {

View File

@@ -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)