Перенеси реализацию мессенджера из ЛР 6
Application / e2e (pull_request) Blocked by required conditions
Application / unit (pull_request) Blocked by required conditions
Skeleton contracts / contracts (pull_request) Blocked by required conditions

Источник — проверенное рабочее дерево ЛР 6 поверх 18878d6, включая изменения после повторного ревью. SHA-256 списка исходных файлов: e45a3d85b41feff1da78dce3f20fd1f4af1c5ee629e6ed703218bc8e21ad58fe.
This commit is contained in:
2026-11-30 10:54:41 +03:00
parent 20afc2c790
commit 8054913ef9
204 changed files with 23709 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
// Command migrate applies the embedded schema migrations once and exits, so
// the API replicas never race each other over the schema.
package main
import (
"context"
"fmt"
"log/slog"
"os"
"os/signal"
"syscall"
"messenger/internal/platform/config"
"messenger/internal/platform/postgres"
)
// poolSize covers the goose session lock and the migration itself.
const poolSize = 2
func main() {
cfg, err := config.LoadMigrate(os.LookupEnv)
if err != nil {
fmt.Fprintln(os.Stderr, "configuration error:", err)
os.Exit(2)
}
log := cfg.NewLogger()
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
defer stop()
if err := run(ctx, log, cfg); err != nil {
log.Error("migration failed", "error", err.Error())
os.Exit(1)
}
}
func run(ctx context.Context, log *slog.Logger, cfg config.Migrate) error {
pool, err := postgres.NewPool(ctx, cfg.DatabaseURL, poolSize)
if err != nil {
return err
}
defer pool.Close()
applied, err := postgres.Migrate(ctx, pool)
if err != nil {
return err
}
log.Info("migrations applied", "applied_migrations", applied)
return nil
}