41 lines
830 B
Go
41 lines
830 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"git.ksdemosapps.com/kylesoda/pgx-learning/internal/config"
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func dropTables(db *pgxpool.Pool, ctx context.Context) error {
|
|
dropTableSQL := `DROP TABLE IF EXISTS tasks`
|
|
|
|
_, err := db.Exec(ctx, dropTableSQL)
|
|
if err != nil {
|
|
return fmt.Errorf("error droping tasks table: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func main() {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
|
defer cancel()
|
|
|
|
db, err := pgxpool.New(ctx, config.Db.Url)
|
|
if err != nil {
|
|
logrus.Fatalf("Unable to create connection pool: %v", err)
|
|
}
|
|
|
|
if err := dropTables(db, ctx); err != nil {
|
|
logrus.Fatalf("Unexpected error: %v", err)
|
|
} else {
|
|
logrus.Info("Database reset completed succesfully")
|
|
}
|
|
|
|
defer db.Close()
|
|
}
|