Repository: edgedb/edgedb

Issue:
Migration error: cannot create a union of enum scalar type
<!-- Please search existing issues to avoid creating duplicates. -->
 - OS: Ubuntu 20.04 LTS (WSL)
 - EdgeDB version: 2.1+c73716f

Got this error when I run `edgedb migration apply` on a clean db:
`edgedb error: SchemaError: cannot create a union of default::ClipType, default::RecordingType`

But if I add each `_type` property in separate migrations, it seems to work.

<!-- If the issue is about a query error, please also provide your schema -->
Schema:
```sql
module default {
  scalar type ClipType extending enum<Test1, Test2>;
  scalar type RecordingType extending enum<Test3, Test4>;

  type LiveClass {
    link _clips := .<_class[is Clip];
    link _recordings := .<_class[is Recording];
  }

  type Clip {
    required property _type -> ClipType;
    link _class -> LiveClass;
  }

  type Recording {
    required property _type -> RecordingType;
    # ⬇️ changing _type to another name works.
    # required property _typexyz -> RecordingType;
    link _class -> LiveClass;
  }
}
```

Generated migration:
```sql
CREATE MIGRATION m1qv6cqu3zdfyh5jbknm5jjmhvv6eeyepqyjdzkmxcts2hc2xtz7yq
    ONTO initial
{
  CREATE SCALAR TYPE default::ClipType EXTENDING enum<Test1, Test2>;
  CREATE TYPE default::Clip {
      CREATE REQUIRED PROPERTY _type -> default::ClipType;
  };
  CREATE TYPE default::LiveClass;
  ALTER TYPE default::Clip {
      CREATE LINK _class -> default::LiveClass;
  };
  ALTER TYPE default::LiveClass {
      CREATE LINK _clips := (.<_class[IS default::Clip]);
  };
  CREATE SCALAR TYPE default::RecordingType EXTENDING enum<Test3, Test4>;
  CREATE TYPE default::Recording {
      CREATE LINK _class -> default::LiveClass;
      CREATE REQUIRED PROPERTY _type -> default::RecordingType;
  };
  ALTER TYPE default::LiveClass {
      CREATE LINK _recordings := (.<_class[IS default::Recording]);
  };
};
```


Discussion:
I've had a lot of those happen myself, not just with enums but normal types.
It is kinda annoying to have to change names of properties so they arent as concise anymore. e.g. I had to rename sth like controlling_faction to station_controlling_faction in my schema for a third party tool for a game named Elite Dangerous and the one on the StarSystem type to star_system_controlling_faction. 
@msullivan, this is a common gotcha, let's see if we can prioritize a fix.

Resolving patch:
diff --git a/edb/schema/pointers.py b/edb/schema/pointers.py
--- a/edb/schema/pointers.py
+++ b/edb/schema/pointers.py
@@ -2850,7 +2850,7 @@ def get_or_create_union_pointer(
         transient=transient,
     )
 
-    if isinstance(result, s_sources.Source):
+    if isinstance(result, s_sources.Source) and not opaque:
         # cast below, because in this case the list of Pointer
         # is also a list of Source (links.Link)
         schema = s_sources.populate_pointer_set_for_source_union(


Test patch:
diff --git a/tests/test_schema.py b/tests/test_schema.py
--- a/tests/test_schema.py
+++ b/tests/test_schema.py
@@ -3085,6 +3085,29 @@ def test_schema_get_migration_52(self):
 
         self._assert_migration_consistency(schema)
 
+    def test_schema_get_migration_53(self):
+        schema = r'''
+            scalar type ClipType extending enum<Test1, Test2>;
+            scalar type RecordingType extending enum<Test3, Test4>;
+
+            type LiveClass {
+              link _clips := .<_class[is Clip];
+              link _recordings := .<_class[is Recording];
+            }
+
+            type Clip {
+              required property _type -> ClipType;
+              link _class -> LiveClass;
+            }
+
+            type Recording {
+              required property _type -> RecordingType;
+              link _class -> LiveClass;
+            }
+        '''
+
+        self._assert_migration_consistency(schema)
+
     def test_schema_get_migration_multi_module_01(self):
         schema = r'''
             # The two declared types declared are from different