//go:build integration

package inttest

import (
	"context"
	"testing"

	"scrabble/backend/internal/postgres"
)

// TestApplyMigrationsIdempotent re-applies the migrations against the already
// migrated database and confirms the expected tables are queryable.
func TestApplyMigrationsIdempotent(t *testing.T) {
	ctx := context.Background()
	if err := postgres.ApplyMigrations(ctx, testDB); err != nil {
		t.Fatalf("re-apply migrations: %v", err)
	}
	for _, table := range []string{"accounts", "identities", "sessions"} {
		var n int
		if err := testDB.QueryRowContext(ctx, "SELECT count(*) FROM "+table).Scan(&n); err != nil {
			t.Errorf("count %s: %v", table, err)
		}
	}
}
