package integration

import (
	"os"
	"path/filepath"
	"testing"

	"github.com/break/junhong_cmp_fiber/tests/testutils"
	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

// TestMigration_NoForeignKeys 验证迁移脚本不包含外键约束
func TestMigration_NoForeignKeys(t *testing.T) {
	migrationsPath := testutils.GetMigrationsPath()

	files, err := filepath.Glob(filepath.Join(migrationsPath, "*.up.sql"))
	require.NoError(t, err)

	forbiddenKeywords := []string{
		"FOREIGN KEY",
		"REFERENCES",
		"ON DELETE CASCADE",
		"ON UPDATE CASCADE",
	}

	for _, file := range files {
		content, err := os.ReadFile(file)
		require.NoError(t, err)

		for _, keyword := range forbiddenKeywords {
			assert.NotContains(t, string(content), keyword,
				"迁移文件 %s 不应包含外键约束关键字: %s", filepath.Base(file), keyword)
		}
	}
}
