nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: kubernetes-sigs/gcp-compute-persistent-disk-csi-driver
Pull request #2098 (2025-05-21 20:21:17)

[release-1.18] Fix Gen4 Custom VM Cases
This is an automated cherry-pick of #2096

/assign sunnylovestiramisu

```release-note
Fix Gen4 Custom VM Cases
```


Patch:
diff --git a/pkg/gce-pd-csi-driver/node.go b/pkg/gce-pd-csi-driver/node.go
index 959eef2a..ccefaa83 100644
--- a/pkg/gce-pd-csi-driver/node.go
+++ b/pkg/gce-pd-csi-driver/node.go
@@ -575,7 +575,9 @@ func (ns *GCENodeServer) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRe
 
 	volumeLimits, err := ns.GetVolumeLimits(ctx)
 	if err != nil {
-		klog.Errorf("GetVolumeLimits failed: %v", err.Error())
+		klog.Errorf("GetVolumeLimits failed: %v. The error is ignored so that the driver can register", err.Error())
+		// No error should be returned from NodeGetInfo, otherwise the driver will not register
+		err = nil
 	}
 
 	resp := &csi.NodeGetInfoResponse{
@@ -762,13 +764,17 @@ func (ns *GCENodeServer) GetVolumeLimits(ctx context.Context) (int64, error) {
 	gen4MachineTypesPrefix := []string{"c4a-", "c4-", "n4-"}
 	for _, gen4Prefix := range gen4MachineTypesPrefix {
 		if strings.HasPrefix(machineType, gen4Prefix) {
-			cpuString := machineType[strings.LastIndex(machineType, "-")+1:]
-			cpus, err := strconv.ParseInt(cpuString, 10, 64)
-			if err != nil {
-				return volumeLimitSmall, fmt.Errorf("invalid cpuString %s for machine type: %v", cpuString, machineType)
+			machineTypeSlice := strings.Split(machineType, "-")
+			if len(machineTypeSlice) > 2 {
+				cpuString := machineTypeSlice[2]
+				cpus, err := strconv.ParseInt(cpuString, 10, 64)
+				if err != nil {
+					return volumeLimitBig, fmt.Errorf("invalid cpuString %s for machine type: %v", cpuString, machineType)
+				}
+				return common.MapNumber(cpus), nil
+			} else {
+				return volumeLimitBig, fmt.Errorf("unconventional machine type: %v", machineType)
 			}
-			return common.MapNumber(cpus), nil
-
 		}
 		if strings.HasPrefix(machineType, "x4-") {
 			return x4HyperdiskLimit, nil


Test patch:
diff --git a/pkg/gce-pd-csi-driver/node_test.go b/pkg/gce-pd-csi-driver/node_test.go
index 4b004f7d..a72834bb 100644
--- a/pkg/gce-pd-csi-driver/node_test.go
+++ b/pkg/gce-pd-csi-driver/node_test.go
@@ -288,15 +288,31 @@ func TestNodeGetVolumeLimits(t *testing.T) {
 			machineType:    "n4-standard-16",
 			expVolumeLimit: 31,
 		},
+		{
+			name:           "n4-micro", // This type does not exist, but testing edge cases
+			machineType:    "n4-micro",
+			expVolumeLimit: volumeLimitBig,
+			expectError:    true,
+		},
 		{
 			name:           "n4-highcpu-4",
 			machineType:    "n4-highcpu-4",
 			expVolumeLimit: 15,
 		},
+		{
+			name:           "n4-custom-8-12345-ext",
+			machineType:    "n4-custom-8-12345-ext",
+			expVolumeLimit: 23,
+		},
+		{
+			name:           "n4-custom-16-12345",
+			machineType:    "n4-custom-16-12345",
+			expVolumeLimit: 31,
+		},
 		{
 			name:           "invalid gen4 machine type",
 			machineType:    "n4-highcpu-4xyz",
-			expVolumeLimit: volumeLimitSmall,
+			expVolumeLimit: volumeLimitBig,
 			expectError:    true,
 		},
 		{
Repository: kubernetes-sigs/gcp-compute-persistent-disk-csi-driver
Pull request #2099 (2025-05-21 22:49:13)

[release-1.17] Fix Gen4 Custom VM Cases
This is an automated cherry-pick of #2096

/assign sunnylovestiramisu

```release-note
Fix Gen4 Custom VM Cases
```


Patch:
diff --git a/pkg/gce-pd-csi-driver/node.go b/pkg/gce-pd-csi-driver/node.go
index 92c83bc2..0d1ffc26 100644
--- a/pkg/gce-pd-csi-driver/node.go
+++ b/pkg/gce-pd-csi-driver/node.go
@@ -573,7 +573,9 @@ func (ns *GCENodeServer) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRe
 
 	volumeLimits, err := ns.GetVolumeLimits()
 	if err != nil {
-		klog.Errorf("GetVolumeLimits failed: %v", err.Error())
+		klog.Errorf("GetVolumeLimits failed: %v. The error is ignored so that the driver can register", err.Error())
+		// No error should be returned from NodeGetInfo, otherwise the driver will not register
+		err = nil
 	}
 
 	resp := &csi.NodeGetInfoResponse{
@@ -744,13 +746,17 @@ func (ns *GCENodeServer) GetVolumeLimits() (int64, error) {
 	gen4MachineTypesPrefix := []string{"c4a-", "c4-", "n4-"}
 	for _, gen4Prefix := range gen4MachineTypesPrefix {
 		if strings.HasPrefix(machineType, gen4Prefix) {
-			cpuString := machineType[strings.LastIndex(machineType, "-")+1:]
-			cpus, err := strconv.ParseInt(cpuString, 10, 64)
-			if err != nil {
-				return volumeLimitSmall, fmt.Errorf("invalid cpuString %s for machine type: %v", cpuString, machineType)
+			machineTypeSlice := strings.Split(machineType, "-")
+			if len(machineTypeSlice) > 2 {
+				cpuString := machineTypeSlice[2]
+				cpus, err := strconv.ParseInt(cpuString, 10, 64)
+				if err != nil {
+					return volumeLimitBig, fmt.Errorf("invalid cpuString %s for machine type: %v", cpuString, machineType)
+				}
+				return common.MapNumber(cpus), nil
+			} else {
+				return volumeLimitBig, fmt.Errorf("unconventional machine type: %v", machineType)
 			}
-			return common.MapNumber(cpus), nil
-
 		}
 		if strings.HasPrefix(machineType, "x4-") {
 			return x4HyperdiskLimit, nil


Test patch:
diff --git a/pkg/gce-pd-csi-driver/node_test.go b/pkg/gce-pd-csi-driver/node_test.go
index 8f177d47..ddfd50aa 100644
--- a/pkg/gce-pd-csi-driver/node_test.go
+++ b/pkg/gce-pd-csi-driver/node_test.go
@@ -276,15 +276,31 @@ func TestNodeGetVolumeLimits(t *testing.T) {
 			machineType:    "n4-standard-16",
 			expVolumeLimit: 31,
 		},
+		{
+			name:           "n4-micro", // This type does not exist, but testing edge cases
+			machineType:    "n4-micro",
+			expVolumeLimit: volumeLimitBig,
+			expectError:    true,
+		},
 		{
 			name:           "n4-highcpu-4",
 			machineType:    "n4-highcpu-4",
 			expVolumeLimit: 15,
 		},
+		{
+			name:           "n4-custom-8-12345-ext",
+			machineType:    "n4-custom-8-12345-ext",
+			expVolumeLimit: 23,
+		},
+		{
+			name:           "n4-custom-16-12345",
+			machineType:    "n4-custom-16-12345",
+			expVolumeLimit: 31,
+		},
 		{
 			name:           "invalid gen4 machine type",
 			machineType:    "n4-highcpu-4xyz",
-			expVolumeLimit: volumeLimitSmall,
+			expVolumeLimit: volumeLimitBig,
 			expectError:    true,
 		},
 		{
Repository: kubernetes-sigs/gcp-compute-persistent-disk-csi-driver
Pull request #2100 (2025-05-23 14:39:29)

[release-1.14] Fix Gen4 Custom VM Cases
This is an automated cherry-pick of #2096

/assign sunnylovestiramisu

```release-note
Fix Gen4 Custom VM Cases
```


Patch:
diff --git a/pkg/gce-pd-csi-driver/node.go b/pkg/gce-pd-csi-driver/node.go
index d1f270cf..b10471e3 100644
--- a/pkg/gce-pd-csi-driver/node.go
+++ b/pkg/gce-pd-csi-driver/node.go
@@ -507,7 +507,9 @@ func (ns *GCENodeServer) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRe
 
 	volumeLimits, err := ns.GetVolumeLimits()
 	if err != nil {
-		klog.Errorf("GetVolumeLimits failed: %v", err.Error())
+		klog.Errorf("GetVolumeLimits failed: %v. The error is ignored so that the driver can register", err.Error())
+		// No error should be returned from NodeGetInfo, otherwise the driver will not register
+		err = nil
 	}
 
 	resp := &csi.NodeGetInfoResponse{
@@ -678,13 +680,17 @@ func (ns *GCENodeServer) GetVolumeLimits() (int64, error) {
 	gen4MachineTypesPrefix := []string{"c4a-", "c4-", "n4-"}
 	for _, gen4Prefix := range gen4MachineTypesPrefix {
 		if strings.HasPrefix(machineType, gen4Prefix) {
-			cpuString := machineType[strings.LastIndex(machineType, "-")+1:]
-			cpus, err := strconv.ParseInt(cpuString, 10, 64)
-			if err != nil {
-				return volumeLimitSmall, fmt.Errorf("invalid cpuString %s for machine type: %v", cpuString, machineType)
+			machineTypeSlice := strings.Split(machineType, "-")
+			if len(machineTypeSlice) > 2 {
+				cpuString := machineTypeSlice[2]
+				cpus, err := strconv.ParseInt(cpuString, 10, 64)
+				if err != nil {
+					return volumeLimitBig, fmt.Errorf("invalid cpuString %s for machine type: %v", cpuString, machineType)
+				}
+				return common.MapNumber(cpus), nil
+			} else {
+				return volumeLimitBig, fmt.Errorf("unconventional machine type: %v", machineType)
 			}
-			return common.MapNumber(cpus), nil
-
 		}
 		if strings.HasPrefix(machineType, "x4-") {
 			return x4HyperdiskLimit, nil


Test patch:
diff --git a/pkg/gce-pd-csi-driver/node_test.go b/pkg/gce-pd-csi-driver/node_test.go
index 5b0574b2..7e59ea7e 100644
--- a/pkg/gce-pd-csi-driver/node_test.go
+++ b/pkg/gce-pd-csi-driver/node_test.go
@@ -256,15 +256,31 @@ func TestNodeGetVolumeLimits(t *testing.T) {
 			machineType:    "n4-standard-16",
 			expVolumeLimit: 31,
 		},
+		{
+			name:           "n4-micro", // This type does not exist, but testing edge cases
+			machineType:    "n4-micro",
+			expVolumeLimit: volumeLimitBig,
+			expectError:    true,
+		},
 		{
 			name:           "n4-highcpu-4",
 			machineType:    "n4-highcpu-4",
 			expVolumeLimit: 15,
 		},
+		{
+			name:           "n4-custom-8-12345-ext",
+			machineType:    "n4-custom-8-12345-ext",
+			expVolumeLimit: 23,
+		},
+		{
+			name:           "n4-custom-16-12345",
+			machineType:    "n4-custom-16-12345",
+			expVolumeLimit: 31,
+		},
 		{
 			name:           "invalid gen4 machine type",
 			machineType:    "n4-highcpu-4xyz",
-			expVolumeLimit: volumeLimitSmall,
+			expVolumeLimit: volumeLimitBig,
 			expectError:    true,
 		},
 		{
Repository: ariga/atlas
Pull request #2672 (2024-04-10 12:57:19)

sql/sqlite: respect column rename in migrate using temporary table


Patch:
diff --git a/sql/sqlite/migrate.go b/sql/sqlite/migrate.go
index db9ab878..fc838f0e 100644
--- a/sql/sqlite/migrate.go
+++ b/sql/sqlite/migrate.go
@@ -416,6 +416,14 @@ func (s *state) copyRows(from *schema.Table, to *schema.Table, changes []schema.
 					return false, fmt.Errorf("duplicate changes for column: %q: %T, %T", column.Name, change, c)
 				}
 				change = changes[i]
+			case *schema.RenameColumn:
+				if c.To.Name != column.Name {
+					break
+				}
+				if change != nil {
+					return false, fmt.Errorf("duplicate changes for column: %q: %T, %T", column.Name, change, c)
+				}
+				change = changes[i]
 			case *schema.DropColumn:
 				if c.C.Name == column.Name {
 					return false, fmt.Errorf("unexpected drop column: %q", column.Name)
@@ -439,6 +447,9 @@ func (s *state) copyRows(from *schema.Table, to *schema.Table, changes []schema.
 			} else {
 				fromC = append(fromC, column.Name)
 			}
+		case *schema.RenameColumn:
+			toC = append(toC, change.To.Name)
+			fromC = append(fromC, change.From.Name)
 		// Columns without changes should be transferred as-is.
 		case nil:
 			toC = append(toC, column.Name)


Test patch:
diff --git a/sql/sqlite/migrate_test.go b/sql/sqlite/migrate_test.go
index 0dc18210..9608aedf 100644
--- a/sql/sqlite/migrate_test.go
+++ b/sql/sqlite/migrate_test.go
@@ -198,6 +198,7 @@ func TestPlanChanges(t *testing.T) {
 					users := schema.NewTable("users").
 						AddColumns(
 							schema.NewIntColumn("id", "bigint"),
+							schema.NewIntColumn("name", "text"),
 							schema.NewIntColumn("nid", "bigint").
 								SetGeneratedExpr(&schema.GeneratedExpr{Expr: "1", Type: "STORED"}),
 						)
@@ -205,7 +206,12 @@ func TestPlanChanges(t *testing.T) {
 						T: users,
 						Changes: []schema.Change{
 							&schema.AddColumn{
-								C: users.Columns[1],
+								C: users.Columns[2],
+							},
+							// Rename should be respected in INSERT command.
+							&schema.RenameColumn{
+								From: schema.NewColumn("uname"),
+								To:   users.Columns[1],
 							},
 						},
 					}
@@ -215,8 +221,8 @@ func TestPlanChanges(t *testing.T) {
 				Transactional: true,
 				Changes: []*migrate.Change{
 					{Cmd: "PRAGMA foreign_keys = off"},
-					{Cmd: "CREATE TABLE `new_users` (`id` bigint NOT NULL, `nid` bigint NOT NULL AS (1) STORED)", Reverse: "DROP TABLE `new_users`"},
-					{Cmd: "INSERT INTO `new_users` (`id`) SELECT `id` FROM `users`"},
+					{Cmd: "CREATE TABLE `new_users` (`id` bigint NOT NULL, `name` text NOT NULL, `nid` bigint NOT NULL AS (1) STORED)", Reverse: "DROP TABLE `new_users`"},
+					{Cmd: "INSERT INTO `new_users` (`id`, `name`) SELECT `id`, `uname` FROM `users`"},
 					{Cmd: "DROP TABLE `users`"},
 					{Cmd: "ALTER TABLE `new_users` RENAME TO `users`"},
 					{Cmd: "PRAGMA foreign_keys = on"},
Repository: ariga/atlas
Pull request #2030 (2023-08-28 12:35:07)

sql/internal/sqlx: consistent order from topsort
Although both (t1,t2)/(t2,t1) are valid orders when t1 and t2 do not depend each other, we want topsort to return consistent order by fallback to their names


Patch:
diff --git a/sql/internal/sqlx/plan.go b/sql/internal/sqlx/plan.go
index f48aaa85..54864d53 100644
--- a/sql/internal/sqlx/plan.go
+++ b/sql/internal/sqlx/plan.go
@@ -204,8 +204,8 @@ func sortMap(changes []schema.Change) (map[string]int, error) {
 		sorted[name] = len(sorted)
 		return false
 	}
-	for node := range deps {
-		if visit(node) {
+	for _, node := range byKeys(deps) {
+		if visit(node.K) {
 			return nil, errCycle
 		}
 	}
@@ -359,3 +359,24 @@ func CheckChangesScope(opts migrate.PlanOptions, changes []schema.Change) error
 	}
 	return nil
 }
+
+// byKeys sorts a map by keys.
+func byKeys[T any](m map[string]T) []struct {
+	K string
+	V T
+} {
+	vs := make([]struct {
+		K string
+		V T
+	}, len(m))
+	for k, v := range m {
+		vs = append(vs, struct {
+			K string
+			V T
+		}{k, v})
+	}
+	sort.Slice(vs, func(i, j int) bool {
+		return vs[i].K < vs[j].K
+	})
+	return vs
+}


Test patch:
diff --git a/sql/internal/sqlx/plan_test.go b/sql/internal/sqlx/plan_test.go
index 5eea2d6e..029c19d8 100644
--- a/sql/internal/sqlx/plan_test.go
+++ b/sql/internal/sqlx/plan_test.go
@@ -5,6 +5,7 @@
 package sqlx
 
 import (
+	"fmt"
 	"testing"
 
 	"ariga.io/atlas/sql/migrate"
@@ -108,6 +109,26 @@ func TestDetachCycles(t *testing.T) {
 	require.Equal(t, []schema.Change{changes[1], changes[0]}, planned)
 }
 
+func TestConsistentOrder(t *testing.T) {
+	newT := func(n string) *schema.Table { return schema.NewTable(n).AddColumns(schema.NewIntColumn("id", "int")) }
+	t1, t2, t3 := newT("t1"), newT("t2"), newT("t3")
+	t2.AddForeignKeys(schema.NewForeignKey("t1").AddColumns(t2.Columns[0]).SetRefTable(t1).AddRefColumns(t1.Columns[0]))
+	t3.AddForeignKeys(schema.NewForeignKey("t1").AddColumns(t3.Columns[0]).SetRefTable(t1).AddRefColumns(t1.Columns[0]))
+	order := func() string {
+		planned, err := DetachCycles([]schema.Change{
+			&schema.AddTable{T: t1},
+			&schema.AddTable{T: t2},
+			&schema.AddTable{T: t3},
+		})
+		require.NoError(t, err)
+		return fmt.Sprintf("%s,%s,%s", planned[0].(*schema.AddTable).T.Name, planned[1].(*schema.AddTable).T.Name, planned[2].(*schema.AddTable).T.Name)
+	}
+	v := order()
+	for i := 0; i < 100; i++ {
+		require.Equal(t, v, order(), "inconsistent order")
+	}
+}
+
 func TestCheckChangesScope(t *testing.T) {
 	err := CheckChangesScope(migrate.PlanOptions{}, []schema.Change{
 		&schema.AddSchema{},
Repository: ariga/atlas
Pull request #2054 (2023-09-06 12:33:13)

schemahcl: print native values as is


Patch:
diff --git a/schemahcl/stdlib.go b/schemahcl/stdlib.go
index 98a12c64..8c60a130 100644
--- a/schemahcl/stdlib.go
+++ b/schemahcl/stdlib.go
@@ -323,10 +323,19 @@ var (
 			return args[0].Type(), nil
 		},
 		Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
-			if b, err := json.Marshal(args[0], args[0].Type()); err != nil {
-				fmt.Println(args[0].GoString())
-			} else {
-				fmt.Println(string(b))
+			switch args[0].Type() {
+			case cty.String:
+				fmt.Println(args[0].AsString())
+			case cty.Number:
+				fmt.Println(args[0].AsBigFloat().String())
+			case cty.Bool:
+				fmt.Println(args[0].True())
+			default:
+				if b, err := json.Marshal(args[0], args[0].Type()); err != nil {
+					fmt.Println(args[0].GoString())
+				} else {
+					fmt.Println(string(b))
+				}
 			}
 			return args[0], nil
 		},


Test patch:
diff --git a/schemahcl/stdlib_test.go b/schemahcl/stdlib_test.go
index 9fc520b9..c7933d4a 100644
--- a/schemahcl/stdlib_test.go
+++ b/schemahcl/stdlib_test.go
@@ -93,6 +93,17 @@ func TestURLQuerySetFunc(t *testing.T) {
 			if !got.RawEquals(test.Want) {
 				t.Errorf("wrong result\ngot:  %#v\nwant: %#v", got, test.Want)
 			}
+			var (
+				f = fmt.Sprintf(
+					`v = urlqueryset(%q, %q, %q)`,
+					test.URL.AsString(), test.Key.AsString(), test.Value.AsString(),
+				)
+				d struct {
+					V cty.Value `spec:"v"`
+				}
+			)
+			require.NoError(t, New().EvalBytes([]byte(f), &d, nil))
+			require.True(t, d.V.RawEquals(got))
 		})
 	}
 }
@@ -125,6 +136,8 @@ func TestMakeFileFunc(t *testing.T) {
 
 func Example_PrintFunc() {
 	for _, f := range []string{
+		`v  = print("a")`,
+		`v  = print("a&b")`,
 		`v  = print(1)`,
 		`v  = print(true)`,
 		`v  = print("hello, world")`,
@@ -141,13 +154,19 @@ func Example_PrintFunc() {
 		fmt.Printf("%#v\n\n", d.V)
 	}
 	// Output:
+	// a
+	// cty.StringVal("a")
+	//
+	// a&b
+	// cty.StringVal("a&b")
+	//
 	// 1
 	// cty.NumberIntVal(1)
 	//
 	// true
 	// cty.True
 	//
-	// "hello, world"
+	// hello, world
 	// cty.StringVal("hello, world")
 	//
 	// {"hello":"world"}
Repository: ariga/atlas
Pull request #2154 (2023-10-04 20:57:23)

sql/migrate: skip non-standard #-based comments inside parens
Next steps are two make the lexer driver-aware and move its config to the drivers


Patch:
diff --git a/sql/migrate/lex.go b/sql/migrate/lex.go
index b43674e4..a6968112 100644
--- a/sql/migrate/lex.go
+++ b/sql/migrate/lex.go
@@ -62,12 +62,12 @@ func Stmts(input string) ([]*Stmt, error) {
 }
 
 type lex struct {
-	input    string
-	pos      int      // current phase position
-	total    int      // total bytes scanned so far
-	width    int      // size of latest rune
-	delim    string   // configured delimiter
-	comments []string // collected comments
+	src, input string   // src and current input text
+	pos        int      // current phase position
+	total      int      // total bytes scanned so far
+	width      int      // size of latest rune
+	delim      string   // configured delimiter
+	comments   []string // collected comments
 }
 
 const (
@@ -77,7 +77,7 @@ const (
 )
 
 func newLex(input string) (*lex, error) {
-	l := &lex{input: input, delim: delimiter}
+	l := &lex{src: input, input: input, delim: delimiter}
 	if d, ok := directive(input, directiveDelimiter, directivePrefixSQL); ok {
 		if err := l.setDelim(d); err != nil {
 			return nil, err
@@ -143,7 +143,9 @@ Scan:
 			if err := l.skipDollarQuote(); err != nil {
 				return nil, err
 			}
-		case r == '#':
+		// Skip non-standard MySQL comments if they are inside
+		// expressions until we make the lexer driver-aware.
+		case depth == 0 && r == '#':
 			l.comment("#", "\n")
 		case r == '-' && l.next() == '-':
 			l.comment("--", "\n")
@@ -289,14 +291,15 @@ func (l *lex) setDelim(d string) error {
 func (l *lex) error(pos int, format string, args ...any) error {
 	format = "%d:%d: " + format
 	var (
-		s    = l.input[:pos]
+		p    = len(l.src) - len(l.input) + pos
+		s    = l.src[:p]
 		col  = strings.LastIndex(s, "\n")
 		line = 1 + strings.Count(s, "\n")
 	)
 	if line == 1 {
-		col = pos
+		col = p
 	} else {
-		col = pos - col - 1
+		col = p - col - 1
 	}
 	return fmt.Errorf(format, append([]any{line, col}, args...)...)
 }


Test patch:
diff --git a/sql/migrate/testdata/lex/6_skip_comment.sql b/sql/migrate/testdata/lex/6_skip_comment.sql
index 939292aa..d533424e 100644
--- a/sql/migrate/testdata/lex/6_skip_comment.sql
+++ b/sql/migrate/testdata/lex/6_skip_comment.sql
@@ -24,3 +24,10 @@ CREATE TABLE t5(
     /* comment */
     -- comment
 ) ENGINE=InnoDB;
+
+# MySQL comment.
+CREATE INDEX "i" ON "s"."t" (((c #>> '{a,b,c}'::text[])));
+
+SELECT * FROM (
+  SELECT * FROM t1 # comment
+);
diff --git a/sql/migrate/testdata/lex/6_skip_comment.sql.golden b/sql/migrate/testdata/lex/6_skip_comment.sql.golden
index 013d94c6..e9ee7629 100644
--- a/sql/migrate/testdata/lex/6_skip_comment.sql.golden
+++ b/sql/migrate/testdata/lex/6_skip_comment.sql.golden
@@ -14,4 +14,10 @@ CREATE TABLE t5(
     id int
     /* comment */
     -- comment
-) ENGINE=InnoDB;
\ No newline at end of file
+) ENGINE=InnoDB;
+-- end --
+CREATE INDEX "i" ON "s"."t" (((c #>> '{a,b,c}'::text[])));
+-- end --
+SELECT * FROM (
+  SELECT * FROM t1 # comment
+);
\ No newline at end of file
Repository: ariga/atlas
Pull request #2208 (2023-10-24 09:30:53)

sql/internal/sqlx: support exclude funcs and procs


Patch:
diff --git a/sql/internal/sqlx/exclude.go b/sql/internal/sqlx/exclude.go
index ea24e845..da4d9df3 100644
--- a/sql/internal/sqlx/exclude.go
+++ b/sql/internal/sqlx/exclude.go
@@ -131,6 +131,24 @@ func excludeS(s *schema.Schema, glob []string) error {
 		}
 		s.Views = views
 	}
+	if globF, exclude := excludeType(typeFn, glob[0]); exclude {
+		var err error
+		s.Funcs, err = filter(s.Funcs, func(f *schema.Func) (bool, error) {
+			return filepath.Match(globF, f.Name)
+		})
+		if err != nil {
+			return err
+		}
+	}
+	if globP, exclude := excludeType(typePr, glob[0]); exclude {
+		var err error
+		s.Procs, err = filter(s.Procs, func(p *schema.Proc) (bool, error) {
+			return filepath.Match(globP, p.Name)
+		})
+		if err != nil {
+			return err
+		}
+	}
 	return nil
 }
 
@@ -198,12 +216,14 @@ func excludeV(t *schema.View, pattern string) (err error) {
 }
 
 const (
-	typeV = "view"
-	typeT = "table"
-	typeC = "column"
-	typeI = "index"
-	typeF = "fk"
-	typeK = "check"
+	typeV  = "view"
+	typeT  = "table"
+	typeC  = "column"
+	typeI  = "index"
+	typeF  = "fk"
+	typeK  = "check"
+	typeFn = "function"
+	typePr = "procedure"
 )
 
 var reTypeVT = regexp.MustCompile(`\[type=([a-z|]+)+\]$`)


Test patch:
diff --git a/sql/internal/sqlx/exclude_test.go b/sql/internal/sqlx/exclude_test.go
index 99cd2f0a..0fd0c26b 100644
--- a/sql/internal/sqlx/exclude_test.go
+++ b/sql/internal/sqlx/exclude_test.go
@@ -102,6 +102,16 @@ func TestExcludeRealm_Selector(t *testing.T) {
 			).
 			AddViews(
 				schema.NewView("v1", "SELECT * FROM t1"),
+			).
+			AddFuncs(
+				&schema.Func{Name: "f1"},
+				&schema.Func{Name: "f2"},
+				&schema.Func{Name: "f3"},
+			).
+			AddProcs(
+				&schema.Proc{Name: "p1"},
+				&schema.Proc{Name: "p2"},
+				&schema.Proc{Name: "p3"},
 			),
 	)
 	r, err := ExcludeRealm(r, []string{"*.*[type=table]"})
@@ -109,6 +119,21 @@ func TestExcludeRealm_Selector(t *testing.T) {
 	require.Empty(t, r.Schemas[0].Tables)
 	require.Len(t, r.Schemas[0].Views, 1)
 
+	r, err = ExcludeRealm(r, []string{"*.f1[type=function]"})
+	require.NoError(t, err)
+	require.Len(t, r.Schemas[0].Funcs, 2)
+	require.Equal(t, []string{"f2", "f3"}, []string{r.Schemas[0].Funcs[0].Name, r.Schemas[0].Funcs[1].Name})
+
+	r, err = ExcludeRealm(r, []string{"*.p2[type=procedure]"})
+	require.NoError(t, err)
+	require.Len(t, r.Schemas[0].Procs, 2)
+	require.Equal(t, []string{"p1", "p3"}, []string{r.Schemas[0].Procs[0].Name, r.Schemas[0].Procs[1].Name})
+
+	r, err = ExcludeRealm(r, []string{"*.*[type=procedure|function]"})
+	require.NoError(t, err)
+	require.Empty(t, r.Schemas[0].Funcs)
+	require.Empty(t, r.Schemas[0].Procs)
+
 	r.Schemas[0].AddTables(
 		schema.NewTable("t1"),
 		schema.NewTable("t2"),
@@ -161,6 +186,7 @@ func TestExcludeRealm_Checks(t *testing.T) {
 	require.NoError(t, err)
 	require.Len(t, r.Schemas[0].Tables[0].Attrs, 0)
 }
+
 func TestExcludeRealm_Columns(t *testing.T) {
 	r := schema.NewRealm(
 		schema.New("s1").AddTables(