(t *testing.T)
| 8 | ) |
| 9 | |
| 10 | func TestComputeDiff_CreateTable(t *testing.T) { |
| 11 | current := &sdata.DBInfo{ |
| 12 | Type: "postgres", |
| 13 | Tables: []sdata.DBTable{}, |
| 14 | } |
| 15 | |
| 16 | expected := &sdata.DBInfo{ |
| 17 | Type: "postgres", |
| 18 | Tables: []sdata.DBTable{ |
| 19 | { |
| 20 | Name: "users", |
| 21 | Columns: []sdata.DBColumn{ |
| 22 | {Name: "id", Type: "bigint", PrimaryKey: true, NotNull: true}, |
| 23 | {Name: "name", Type: "text", NotNull: true}, |
| 24 | {Name: "email", Type: "text"}, |
| 25 | }, |
| 26 | }, |
| 27 | }, |
| 28 | } |
| 29 | |
| 30 | ops := computeDiff(current, expected, DiffOptions{Destructive: false}) |
| 31 | |
| 32 | if len(ops) == 0 { |
| 33 | t.Fatal("expected at least one operation") |
| 34 | } |
| 35 | |
| 36 | // Should have a create_table operation |
| 37 | found := false |
| 38 | for _, op := range ops { |
| 39 | if op.Type == "create_table" && op.Table == "users" { |
| 40 | found = true |
| 41 | if !strings.Contains(op.SQL, "CREATE TABLE") { |
| 42 | t.Errorf("expected CREATE TABLE in SQL, got: %s", op.SQL) |
| 43 | } |
| 44 | if !strings.Contains(op.SQL, `"id"`) { |
| 45 | t.Errorf("expected id column in SQL, got: %s", op.SQL) |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | if !found { |
| 51 | t.Error("expected create_table operation for users table") |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | func TestSupportsSchemaDDLBoundary(t *testing.T) { |
| 56 | for _, dbType := range []string{"postgres", "mysql", "mariadb", "sqlite", "mssql", "oracle", "snowflake"} { |
nothing calls this directly
no test coverage detected