Repository: edgedb/edgedb

Issue:
Alteration of enums doesn't work at all in migraitons
```
create scalar type MyEnum extending enum<Foo, Bar>;
```

And then

```
start migration to { module default {
  scalar type MyEnum extending enum<Foo, Bar, Baz>;
}; }; populate migration; commit migration;
```

doesn't crash but doesn't actually modify the enum either.


Discussion:

Resolving patch:
diff --git a/edb/schema/scalars.py b/edb/schema/scalars.py
--- a/edb/schema/scalars.py
+++ b/edb/schema/scalars.py
@@ -214,6 +214,39 @@ def get_verbosename(
         dname = self.get_displayname(schema)
         return f"{clsname} '{dname}'"
 
+    def as_alter_delta(
+        self,
+        other: ScalarType,
+        *,
+        self_schema: s_schema.Schema,
+        other_schema: s_schema.Schema,
+        confidence: float,
+        context: so.ComparisonContext,
+    ) -> sd.ObjectCommand[ScalarType]:
+        alter = super().as_alter_delta(
+            other,
+            self_schema=self_schema,
+            other_schema=other_schema,
+            confidence=confidence,
+            context=context,
+        )
+
+        # If this is an enum and enum_values changed, we need to
+        # generate a rebase.
+        enum_values = alter.get_attribute_value('enum_values')
+        if enum_values is not None:
+            assert isinstance(alter.classname, s_name.QualName)
+            rebase = RebaseScalarType(
+                classname=alter.classname,
+                removed_bases=(),
+                added_bases=(
+                    ([AnonymousEnumTypeShell(elements=enum_values)], ''),
+                ),
+            )
+            alter.add(rebase)
+
+        return alter
+
 
 class AnonymousEnumTypeShell(s_types.TypeShell):
 
diff --git a/edb/schema/utils.py b/edb/schema/utils.py
--- a/edb/schema/utils.py
+++ b/edb/schema/utils.py
@@ -499,6 +499,7 @@ def shell_to_ast(
 ) -> qlast.TypeExpr:
     from . import pseudo as s_pseudo
     from . import types as s_types
+    from . import scalars as s_scalars
 
     result: qlast.TypeExpr
     qlref: qlast.BaseObjectRef
@@ -554,6 +555,17 @@ def shell_to_ast(
                 op='|',
                 right=typeref_to_ast(schema, component),
             )
+    elif isinstance(t, s_scalars.AnonymousEnumTypeShell):
+        result = qlast.TypeName(
+            name=_name,
+            maintype=qlast.ObjectRef(
+                name='enum',
+            ),
+            subtypes=[
+                qlast.TypeName(maintype=qlast.ObjectRef(name=x))
+                for x in t.elements
+            ]
+        )
     elif isinstance(t, so.ObjectShell):
         name = t.name
         if isinstance(name, sn.QualName):


Test patch:
diff --git a/tests/test_schema.py b/tests/test_schema.py
--- a/tests/test_schema.py
+++ b/tests/test_schema.py
@@ -5355,6 +5355,13 @@ def test_schema_migrations_computed_optionality_01(self):
             };
         """])
 
+    def test_schema_migrations_extend_enum_01(self):
+        self._assert_migration_equivalence([r"""
+            scalar type foo extending enum<Foo, Bar>;
+        """, r"""
+            scalar type foo extending enum<Foo, Bar, Baz>;
+        """])
+
 
 class TestDescribe(tb.BaseSchemaLoadTest):
     """Test the DESCRIBE command."""