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 createTasksTable(db *pgxpool.Pool, ctx context.Context) error { createTableSQL := ` CREATE TABLE IF NOT EXISTS tasks ( id BIGSERIAL PRIMARY KEY, text TEXT NOT NULL, completed BOOLEAN NOT NULL DEFAULT FALSE, created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMPTZ ); ` _, err := db.Exec(ctx, createTableSQL) if err != nil { return fmt.Errorf("error creating tasks table: %w", err) } return nil } func main() { logrus.SetFormatter(&logrus.TextFormatter{ FullTimestamp: true, TimestampFormat: time.StampMilli, }) 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 := createTasksTable(db, ctx); err != nil { logrus.Fatalf("Unexpected error: %v", err) } else { logrus.Info("Database setup completed succesfully") } defer db.Close() }