nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: crsmithdev/arrow
Pull request #719 (2019-11-21 16:13:16)

Allow factory.get() to construct from a timestamp and timezone
First attempt at this as discussed, not sure about this behaviour though. Any thoughts @jadchaar ?

```shell
(arrow) chris@ThinkPad:~/arrow$ python
Python 3.7.4 (default, Sep 19 2019, 11:01:37) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import arrow
>>> arrow.get(1367900664)
<Arrow [2013-05-07T04:24:24+00:00]>
>>> arrow.get(1367900664).replace(tzinfo="US/Pacific")
<Arrow [2013-05-07T04:24:24-07:00]>
>>> from dateutil import tz
>>> time_zone = tz.gettz('US/Pacific')
>>> arrow.get(1367900664, tzinfo=time_zone)
<Arrow [2013-05-06T21:24:24-07:00]>
```


Patch:
diff --git a/arrow/factory.py b/arrow/factory.py
index b6d78b6..bf9e1f3 100644
--- a/arrow/factory.py
+++ b/arrow/factory.py
@@ -168,9 +168,12 @@ class ArrowFactory(object):
             if arg is None:
                 return self.type.utcnow()
 
-            # try (int, float) -> utc, from timestamp.
+            # try (int, float) -> from timestamp with tz
             elif not isstr(arg) and is_timestamp(arg):
-                return self.type.utcfromtimestamp(arg)
+                if tz is None:
+                    # set to UTC by default
+                    tz = dateutil_tz.tzutc()
+                return self.type.fromtimestamp(arg, tzinfo=tz)
 
             # (Arrow) -> from the object's datetime.
             elif isinstance(arg, Arrow):


Test patch:
diff --git a/tests/factory_tests.py b/tests/factory_tests.py
index 98d9eca..d2e1dab 100644
--- a/tests/factory_tests.py
+++ b/tests/factory_tests.py
@@ -73,6 +73,16 @@ class GetTests(Chai):
         with self.assertRaises((OverflowError, ValueError)):
             self.factory.get(timestamp)
 
+    def test_one_arg_timestamp_with_tzinfo(self):
+
+        timestamp = time.time()
+        timestamp_dt = datetime.fromtimestamp(timestamp, tz=tz.tzutc()).astimezone(
+            tz.gettz("US/Pacific")
+        )
+        timezone = tz.gettz("US/Pacific")
+
+        assertDtEqual(self.factory.get(timestamp, tzinfo=timezone), timestamp_dt)
+
     def test_one_arg_arrow(self):
 
         arw = self.factory.utcnow()
Repository: ariga/atlas
Pull request #1426 (2023-01-25 15:05:01)

Merge https://github.com/ariga/atlas/pull/1418


Patch:
diff --git a/sql/internal/sqlx/exclude.go b/sql/internal/sqlx/exclude.go
index 86b778d4..d3c07547 100644
--- a/sql/internal/sqlx/exclude.go
+++ b/sql/internal/sqlx/exclude.go
@@ -140,6 +140,17 @@ func excludeT(t *schema.Table, pattern string) (err error) {
 		}
 		return filepath.Match(pattern, fk.Symbol)
 	})
+	t.Attrs, err = filter(t.Attrs, func(a schema.Attr) (bool, error) {
+		c, ok := a.(*schema.Check)
+		if !ok {
+			return false, nil
+		}
+		match, err := filepath.Match(pattern, c.Name)
+		if !match || err != nil {
+			return false, err
+		}
+		return true, nil
+	})
 	return
 }
 


Test patch:
diff --git a/sql/internal/sqlx/exclude_test.go b/sql/internal/sqlx/exclude_test.go
index 6c5082eb..825674c8 100644
--- a/sql/internal/sqlx/exclude_test.go
+++ b/sql/internal/sqlx/exclude_test.go
@@ -94,6 +94,16 @@ func TestExcludeRealm_Tables(t *testing.T) {
 	require.Empty(t, r.Schemas[2].Tables)
 }
 
+func TestExcludeRealm_Checks(t *testing.T) {
+	r := schema.NewRealm(
+		schema.New("s1").AddTables(
+			schema.NewTable("t1").AddChecks(schema.NewCheck().SetName("c1")),
+		),
+	)
+	r, err := ExcludeRealm(r, []string{"s1.t1.c1"})
+	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(
Repository: ariga/atlas
Pull request #1438 (2023-02-02 14:22:14)

sql/migrate: MemDir will now only return sql files and respect a chec…
…ksum file if present


Patch:
diff --git a/sql/migrate/dir.go b/sql/migrate/dir.go
index 787ce788..cb1d290e 100644
--- a/sql/migrate/dir.go
+++ b/sql/migrate/dir.go
@@ -218,8 +218,9 @@ type MemDir struct {
 // Open implements fs.FS.
 func (d *MemDir) Open(name string) (fs.File, error) {
 	var b []byte
-	switch name {
-	case HashFileName:
+	f, ok := d.files[name]
+	switch {
+	case !ok && name == HashFileName:
 		h, err := d.Checksum()
 		if err != nil {
 			return nil, err
@@ -227,11 +228,9 @@ func (d *MemDir) Open(name string) (fs.File, error) {
 		if b, err = h.MarshalText(); err != nil {
 			return nil, err
 		}
+	case !ok:
+		return nil, fs.ErrNotExist
 	default:
-		f, ok := d.files[name]
-		if !ok {
-			return nil, fs.ErrNotExist
-		}
 		b = f.Bytes()
 	}
 	return &memFile{
@@ -252,7 +251,9 @@ func (d *MemDir) WriteFile(name string, data []byte) error {
 func (d *MemDir) Files() ([]File, error) {
 	files := make([]File, 0, len(d.files))
 	for _, f := range d.files {
-		files = append(files, f)
+		if filepath.Ext(f.Name()) == ".sql" {
+			files = append(files, f)
+		}
 	}
 	sort.Slice(files, func(i, j int) bool {
 		return files[i].Name() < files[j].Name()


Test patch:
diff --git a/sql/migrate/dir_test.go b/sql/migrate/dir_test.go
index 7cb5de1c..dd0fcecc 100644
--- a/sql/migrate/dir_test.go
+++ b/sql/migrate/dir_test.go
@@ -214,6 +214,16 @@ func TestMemDir(t *testing.T) {
 	hs2, err := migrate.NewHashFile(files)
 	require.NoError(t, err)
 	require.Equal(t, hs1, hs2)
+
+	// If a checksum file is given, it will be used instead of generating the sum on the fly.
+	require.NoError(t, migrate.Validate(&d))
+	require.NoError(t, d.WriteFile(migrate.HashFileName, []byte("")))
+	require.ErrorIs(t, migrate.Validate(&d), migrate.ErrChecksumMismatch)
+
+	// Will not return the non-sql checksum file.
+	files, err = d.Files()
+	require.NoError(t, err)
+	require.Len(t, files, 1) // 1.sql
 }
 
 func TestLocalFile_Directive(t *testing.T) {
Repository: ariga/atlas
Pull request #1452 (2023-02-08 17:48:11)

sql/sqlite: add uint64 to sqlspec types
Fixed https://github.com/ariga/atlas/issues/1448


Patch:
diff --git a/sql/sqlite/convert.go b/sql/sqlite/convert.go
index 18720237..07394e6e 100644
--- a/sql/sqlite/convert.go
+++ b/sql/sqlite/convert.go
@@ -63,7 +63,7 @@ func ParseType(c string) (schema.Type, error) {
 		return &schema.BoolType{T: t}, nil
 	case "blob":
 		return &schema.BinaryType{T: t}, nil
-	case "int2", "int8", "int", "integer", "tinyint", "smallint", "mediumint", "bigint", "unsigned big int":
+	case "int2", "int8", "int", "uint64", "integer", "tinyint", "smallint", "mediumint", "bigint", "unsigned big int":
 		// All integer types have the same "type affinity".
 		return &schema.IntegerType{T: t}, nil
 	case "real", "double", "double precision", "float":
diff --git a/sql/sqlite/sqlspec.go b/sql/sqlite/sqlspec.go
index 79ef3dab..3968f5c7 100644
--- a/sql/sqlite/sqlspec.go
+++ b/sql/sqlite/sqlspec.go
@@ -177,6 +177,7 @@ var TypeRegistry = schemahcl.NewRegistry(
 		schemahcl.AliasTypeSpec("unsigned_big_int", "unsigned big int", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
 		schemahcl.NewTypeSpec("int2", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
 		schemahcl.NewTypeSpec("int8", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
+		schemahcl.NewTypeSpec("uint64", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
 		schemahcl.NewTypeSpec("double", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
 		schemahcl.AliasTypeSpec("double_precision", "double precision", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
 		schemahcl.NewTypeSpec("float", schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),


Test patch:
diff --git a/internal/integration/testdata/sqlite/cli-inspect.txt b/internal/integration/testdata/sqlite/cli-inspect.txt
index 7a00c4d2..9314d8c4 100644
--- a/internal/integration/testdata/sqlite/cli-inspect.txt
+++ b/internal/integration/testdata/sqlite/cli-inspect.txt
@@ -44,6 +44,10 @@ table "users" {
     null = false
     type = int
   }
+  column "ac" {
+    null = false
+    type = uint64
+  }
 }
 schema "main" {
 }
diff --git a/sql/sqlite/sqlspec_test.go b/sql/sqlite/sqlspec_test.go
index 9e021eb4..8c293189 100644
--- a/sql/sqlite/sqlspec_test.go
+++ b/sql/sqlite/sqlspec_test.go
@@ -312,6 +312,10 @@ func TestTypes(t *testing.T) {
 			typeExpr: "int8(10)",
 			expected: &schema.IntegerType{T: "int8"},
 		},
+		{
+			typeExpr: "uint64",
+			expected: &schema.IntegerType{T: "uint64"},
+		},
 		{
 			typeExpr: "real",
 			expected: &schema.FloatType{T: "real"},
Repository: ariga/atlas
Pull request #1652 (2023-05-12 12:19:36)

sql/sqltool: wrap golang-migrate dir with fs
### Extending Golang-migrate Functionality with fs.FS

According to this PR: https://github.com/ariga/atlas/pull/1642
> By wrapping Golang-migrate with fs.FS, we can extend its functionality to include local directories and directories in memory or remote directories.


Patch:
diff --git a/sql/sqltool/tool.go b/sql/sqltool/tool.go
index debb9070..1f112c42 100644
--- a/sql/sqltool/tool.go
+++ b/sql/sqltool/tool.go
@@ -71,9 +71,9 @@ var (
 )
 
 type (
-	// GolangMigrateDir wraps migrate.LocalDir and provides a migrate.Scanner implementation able to understand files
+	// GolangMigrateDir wraps fs.FS and provides a migrate.Scanner implementation able to understand files
 	// generated by the GolangMigrateFormatter for migration directory replaying.
-	GolangMigrateDir struct{ *migrate.LocalDir }
+	GolangMigrateDir struct{ fs.FS }
 	// GolangMigrateFile wraps migrate.LocalFile with custom description function.
 	GolangMigrateFile struct{ *migrate.LocalFile }
 )
@@ -108,6 +108,26 @@ func (d *GolangMigrateDir) Files() ([]migrate.File, error) {
 	return ret, nil
 }
 
+// Checksum implements Dir.Checksum. By default, it calls Files() and creates a checksum from them.
+func (d *GolangMigrateDir) Checksum() (migrate.HashFile, error) {
+	if d, ok := d.FS.(migrate.Dir); ok {
+		return d.Checksum()
+	}
+	files, err := d.Files()
+	if err != nil {
+		return nil, err
+	}
+	return migrate.NewHashFile(files)
+}
+
+// WriteFile implements Dir.WriteFile.
+func (d *GolangMigrateDir) WriteFile(name string, b []byte) error {
+	if d, ok := d.FS.(migrate.Dir); ok {
+		return d.WriteFile(name, b)
+	}
+	return errors.New("sql/sqltool: write not supported")
+}
+
 // Desc implements File.Desc.
 func (f *GolangMigrateFile) Desc() string {
 	return strings.TrimSuffix(f.LocalFile.Desc(), ".up")


Test patch:
diff --git a/sql/sqltool/tool_test.go b/sql/sqltool/tool_test.go
index da21c963..3f121eb1 100644
--- a/sql/sqltool/tool_test.go
+++ b/sql/sqltool/tool_test.go
@@ -294,6 +294,22 @@ func TestChecksum(t *testing.T) {
 				"2_second_migration.up.sql",
 			},
 		},
+		{
+			name: "golang-migrate non-local directory",
+			dir: func() migrate.Dir {
+				fs := fstest.MapFS{
+					"1_initial.down.sql":          &fstest.MapFile{Data: []byte("1_initial.down")},
+					"1_initial.up.sql":            &fstest.MapFile{Data: []byte("1_initial.up")},
+					"2_second_migration.down.sql": &fstest.MapFile{Data: []byte("2_second_migration.down")},
+					"2_second_migration.up.sql":   &fstest.MapFile{Data: []byte("2_second_migration.up")},
+				}
+				return &sqltool.GolangMigrateDir{&fs}
+			}(),
+			files: []string{
+				"1_initial.up.sql",
+				"2_second_migration.up.sql",
+			},
+		},
 		{
 			name: "goose",
 			dir: func() migrate.Dir {
Repository: ariga/atlas
Pull request #1662 (2023-05-15 13:41:50)

sql/mysql: support unmarshal the engine attribute


Patch:
diff --git a/sql/mysql/sqlspec.go b/sql/mysql/sqlspec.go
index e18de3ad..ba691950 100644
--- a/sql/mysql/sqlspec.go
+++ b/sql/mysql/sqlspec.go
@@ -118,6 +118,13 @@ func convertTable(spec *sqlspec.Table, parent *schema.Schema) (*schema.Table, er
 		}
 		t.AddAttrs(&AutoIncrement{V: v})
 	}
+	if attr, ok := spec.Attr("engine"); ok {
+		v, err := attr.String()
+		if err != nil {
+			return nil, err
+		}
+		t.AddAttrs(&Engine{V: v})
+	}
 	return t, err
 }
 


Test patch:
diff --git a/sql/mysql/sqlspec_test.go b/sql/mysql/sqlspec_test.go
index ca2a9543..3be38e67 100644
--- a/sql/mysql/sqlspec_test.go
+++ b/sql/mysql/sqlspec_test.go
@@ -597,6 +597,58 @@ schema "a8m" {
 	require.EqualValues(t, expected, string(buf))
 }
 
+func TestUnmarshalSpec_TableEngine(t *testing.T) {
+	var (
+		s schema.Schema
+		f = `table "repos" {
+  schema = schema.a8m
+  engine = InnoDB
+  column "id" {
+    null = false
+    type = bigint
+  }
+}
+table "stars" {
+  schema = schema.a8m
+  engine = "INNODB"
+  column "id" {
+    null = false
+    type = bigint
+  }
+}
+table "prs" {
+  schema = schema.a8m
+  engine = MyISAM
+  column "id" {
+    null = false
+    type = bigint
+  }
+}
+table "issues" {
+  schema = schema.a8m
+  engine = "MYISAM"
+  column "id" {
+    null = false
+    type = bigint
+  }
+}
+table "commits" {
+  schema = schema.a8m
+  engine = "MyRocks"
+  column "id" {
+    null = false
+    type = bigint
+  }
+}
+schema "a8m" {}
+`
+	)
+	require.NoError(t, EvalHCLBytes([]byte(f), &s, nil))
+	for i, e := range []string{EngineInnoDB, "INNODB", EngineMyISAM, "MYISAM", "MyRocks"} {
+		require.EqualValues(t, e, s.Tables[i].Attrs[0].(*Engine).V)
+	}
+}
+
 func TestUnmarshalSpec_IndexParts(t *testing.T) {
 	var (
 		s schema.Schema
Repository: ariga/atlas
Pull request #1690 (2023-05-29 16:57:27)

sql/sqltool: fix flyway invalid order migrations
### Context
Invalid order migration files when sorting with filename
```
V1__.sql
V1.7__.sql
```
after sort
```
V1.7__.sql
V1__.sql
```



Patch:
diff --git a/sql/sqltool/tool.go b/sql/sqltool/tool.go
index e1529070..e2692d54 100644
--- a/sql/sqltool/tool.go
+++ b/sql/sqltool/tool.go
@@ -534,8 +534,8 @@ func (ff *flywayFiles) names() []string {
 	if ff.baseline != "" {
 		names = append(names, ff.baseline)
 	}
-	sort.Strings(ff.versioned)
-	sort.Strings(ff.repeatable)
+	flywaySort(ff.versioned)
+	flywaySort(ff.repeatable)
 	names = append(names, ff.versioned...)
 	names = append(names, ff.repeatable...)
 	return names
@@ -557,6 +557,12 @@ func flywayVersion(path string) string {
 	return strings.SplitN(strings.TrimSuffix(filepath.Base(path), ".sql"), "__", 2)[0][1:]
 }
 
+func flywaySort(files []string) {
+	sort.Slice(files, func(i, j int) bool {
+		return flywayVersion(files[i]) < flywayVersion(files[j])
+	})
+}
+
 func unexpectedPragmaErr(f migrate.File, line int, pragma string) error {
 	var tool string
 	switch f := f.(type) {


Test patch:
diff --git a/sql/sqltool/tool_test.go b/sql/sqltool/tool_test.go
index 3f121eb1..66e369bb 100644
--- a/sql/sqltool/tool_test.go
+++ b/sql/sqltool/tool_test.go
@@ -359,6 +359,24 @@ func TestChecksum(t *testing.T) {
 				"R__views.sql",
 			},
 		},
+		{
+			name: "flyway with semver versioning",
+			dir: func() migrate.Dir {
+				fs := fstest.MapFS{
+					"V1__initial.sql":          &fstest.MapFile{Data: []byte("V1__initial")},
+					"V1.7__initial.sql":        &fstest.MapFile{Data: []byte("V1.7__initial")},
+					"V2__second_migration.sql": &fstest.MapFile{Data: []byte("V2__second_migration")},
+					"V3__third_migration.sql":  &fstest.MapFile{Data: []byte("V3__third_migration")},
+				}
+				return &sqltool.FlywayDir{&fs}
+			}(),
+			files: []string{
+				"V1__initial.sql",
+				"V1.7__initial.sql",
+				"V2__second_migration.sql",
+				"V3__third_migration.sql",
+			},
+		},
 		{
 			name: "liquibase",
 			dir: func() migrate.Dir {
Repository: ariga/atlas
Pull request #1691 (2023-05-30 09:35:03)

sql/sqltool: compare flyway version as semver


Patch:
diff --git a/sql/sqltool/tool.go b/sql/sqltool/tool.go
index e2692d54..22443ce5 100644
--- a/sql/sqltool/tool.go
+++ b/sql/sqltool/tool.go
@@ -13,6 +13,7 @@ import (
 	"path/filepath"
 	"regexp"
 	"sort"
+	"strconv"
 	"strings"
 	"text/template"
 	"time"
@@ -559,10 +560,24 @@ func flywayVersion(path string) string {
 
 func flywaySort(files []string) {
 	sort.Slice(files, func(i, j int) bool {
-		return flywayVersion(files[i]) < flywayVersion(files[j])
+		return flywayVersionCompare(flywayVersion(files[i]), flywayVersion(files[j])) < 0
 	})
 }
 
+func flywayVersionCompare(v1, v2 string) int {
+	parse := func(s string) []int {
+		ss := strings.Split(strings.ReplaceAll(s, "_", "."), ".")
+		var ret []int
+		for _, s := range ss {
+			// 0 for non-numeric parts.
+			i, _ := strconv.Atoi(s)
+			ret = append(ret, i)
+		}
+		return ret
+	}
+	return compareSliceInt(parse(v1), parse(v2))
+}
+
 func unexpectedPragmaErr(f migrate.File, line int, pragma string) error {
 	var tool string
 	switch f := f.(type) {
@@ -624,3 +639,24 @@ var (
 	_ dirPath = (*GooseDir)(nil)
 	_ dirPath = (*LiquibaseDir)(nil)
 )
+
+// Copied from golang.org/x/exp/slices.Compare
+func compareSliceInt(s1, s2 []int) int {
+	s2len := len(s2)
+	for i, v1 := range s1 {
+		if i >= s2len {
+			return +1
+		}
+		v2 := s2[i]
+		switch {
+		case v1 < v2:
+			return -1
+		case v1 > v2:
+			return +1
+		}
+	}
+	if len(s1) < s2len {
+		return -1
+	}
+	return 0
+}


Test patch:
diff --git a/sql/sqltool/tool_test.go b/sql/sqltool/tool_test.go
index 66e369bb..2a4ce7f1 100644
--- a/sql/sqltool/tool_test.go
+++ b/sql/sqltool/tool_test.go
@@ -363,18 +363,26 @@ func TestChecksum(t *testing.T) {
 			name: "flyway with semver versioning",
 			dir: func() migrate.Dir {
 				fs := fstest.MapFS{
-					"V1__initial.sql":          &fstest.MapFile{Data: []byte("V1__initial")},
-					"V1.7__initial.sql":        &fstest.MapFile{Data: []byte("V1.7__initial")},
-					"V2__second_migration.sql": &fstest.MapFile{Data: []byte("V2__second_migration")},
-					"V3__third_migration.sql":  &fstest.MapFile{Data: []byte("V3__third_migration")},
+					"V1__.sql":        &fstest.MapFile{Data: []byte("V1")},
+					"V1_1_0__.sql":    &fstest.MapFile{Data: []byte("V1.1.0")},
+					"V1.1.1__.sql":    &fstest.MapFile{Data: []byte("V1.1.1")},
+					"V2__.sql":        &fstest.MapFile{Data: []byte("V2")},
+					"V2.1.0__.sql":    &fstest.MapFile{Data: []byte("V2.1.0")},
+					"V3__.sql":        &fstest.MapFile{Data: []byte("V3")},
+					"V11__.sql":       &fstest.MapFile{Data: []byte("V11")},
+					"V11.11.11__.sql": &fstest.MapFile{Data: []byte("V11.11.11")},
 				}
 				return &sqltool.FlywayDir{&fs}
 			}(),
 			files: []string{
-				"V1__initial.sql",
-				"V1.7__initial.sql",
-				"V2__second_migration.sql",
-				"V3__third_migration.sql",
+				"V1__.sql",
+				"V1_1_0__.sql",
+				"V1.1.1__.sql",
+				"V2__.sql",
+				"V2.1.0__.sql",
+				"V3__.sql",
+				"V11__.sql",
+				"V11.11.11__.sql",
 			},
 		},
 		{
Repository: ariga/atlas
Pull request #1697 (2023-05-31 10:14:06)

sql/migrate: fixed archive logic on sum file


Patch:
diff --git a/sql/migrate/dir.go b/sql/migrate/dir.go
index 5c01c459..09e555fb 100644
--- a/sql/migrate/dir.go
+++ b/sql/migrate/dir.go
@@ -88,7 +88,11 @@ func (d *LocalDir) Path() string {
 
 // Open implements fs.FS.
 func (d *LocalDir) Open(name string) (fs.File, error) {
-	return os.Open(filepath.Join(d.path, name))
+	f, err := os.Open(filepath.Join(d.path, name))
+	if err != nil {
+		return nil, err
+	}
+	return f, nil
 }
 
 // WriteFile implements Dir.WriteFile.


Test patch:
diff --git a/sql/migrate/dir_test.go b/sql/migrate/dir_test.go
index c51e7f27..f786c054 100644
--- a/sql/migrate/dir_test.go
+++ b/sql/migrate/dir_test.go
@@ -15,6 +15,7 @@ import (
 	"time"
 
 	"ariga.io/atlas/sql/migrate"
+	"ariga.io/atlas/sql/sqltool"
 
 	"github.com/stretchr/testify/require"
 )
@@ -315,6 +316,12 @@ func TestDirTar(t *testing.T) {
 	require.NoError(t, err)
 	require.Equal(t, []string{"1.sql"}, f)
 
+	// Test with Golang migrate dir.
+	dir1, err := sqltool.NewGolangMigrateDir("./testdata/golang-migrate")
+	require.NoError(t, err)
+	b, err = migrate.ArchiveDir(dir1)
+	require.NoError(t, err)
+
 	// With sumfile.
 	checksum, err := d.Checksum()
 	require.NoError(t, err)
diff --git a/sql/migrate/testdata/golang-migrate/1_base.up.sql b/sql/migrate/testdata/golang-migrate/1_base.up.sql
new file mode 100644
index 00000000..5a3f49dc
--- /dev/null
+++ b/sql/migrate/testdata/golang-migrate/1_base.up.sql
@@ -0,0 +1,1 @@
+CREATE TABLE t(c int);
\ No newline at end of file
Repository: ariga/atlas
Pull request #1746 (2023-06-15 19:56:00)

sql/migrate: do not error on json encode unknown revision type


Patch:
diff --git a/sql/migrate/migrate.go b/sql/migrate/migrate.go
index a81f6c82..ee718201 100644
--- a/sql/migrate/migrate.go
+++ b/sql/migrate/migrate.go
@@ -276,27 +276,23 @@ func (r RevisionType) Has(f RevisionType) bool {
 
 // String implements fmt.Stringer.
 func (r RevisionType) String() string {
-	switch {
-	case r == RevisionTypeBaseline:
+	switch r {
+	case RevisionTypeBaseline:
 		return "baseline"
-	case r == RevisionTypeExecute:
+	case RevisionTypeExecute:
 		return "applied"
-	case r == RevisionTypeResolved:
+	case RevisionTypeResolved:
 		return "manually set"
-	case r == RevisionTypeExecute|RevisionTypeResolved:
+	case RevisionTypeExecute | RevisionTypeResolved:
 		return "applied + manually set"
 	default:
-		return "unknown"
+		return fmt.Sprintf("unknown (%04b)", r)
 	}
 }
 
 // MarshalText implements encoding.TextMarshaler.
 func (r RevisionType) MarshalText() ([]byte, error) {
-	s := r.String()
-	if s == "unknown" {
-		return nil, fmt.Errorf("unexpected revision type '%v'", r)
-	}
-	return []byte(s), nil
+	return []byte(r.String()), nil
 }
 
 // NewPlanner creates a new Planner.


Test patch:
diff --git a/sql/migrate/migrate_test.go b/sql/migrate/migrate_test.go
index 7fd3e556..e9d41a1c 100644
--- a/sql/migrate/migrate_test.go
+++ b/sql/migrate/migrate_test.go
@@ -23,24 +23,18 @@ import (
 
 func TestRevisionType_MarshalText(t *testing.T) {
 	for _, tt := range []struct {
-		r       migrate.RevisionType
-		ex      string
-		wantErr bool
+		r  migrate.RevisionType
+		ex string
 	}{
-		{migrate.RevisionTypeUnknown, "", true},
-		{migrate.RevisionTypeBaseline, "baseline", false},
-		{migrate.RevisionTypeExecute, "applied", false},
-		{migrate.RevisionTypeResolved, "manually set", false},
-		{migrate.RevisionTypeExecute | migrate.RevisionTypeResolved, "applied + manually set", false},
-		{migrate.RevisionTypeExecute | migrate.RevisionTypeBaseline, "", true},
-		{1 << 3, "", true},
+		{migrate.RevisionTypeUnknown, "unknown (0000)"},
+		{migrate.RevisionTypeBaseline, "baseline"},
+		{migrate.RevisionTypeExecute, "applied"},
+		{migrate.RevisionTypeResolved, "manually set"},
+		{migrate.RevisionTypeExecute | migrate.RevisionTypeResolved, "applied + manually set"},
+		{migrate.RevisionTypeExecute | migrate.RevisionTypeBaseline, "unknown (0011)"},
+		{1 << 3, "unknown (1000)"},
 	} {
 		ac, err := tt.r.MarshalText()
-		if tt.wantErr {
-			require.Error(t, err)
-			require.Zero(t, ac)
-			continue
-		}
 		require.NoError(t, err)
 		require.Equal(t, tt.ex, string(ac))
 	}