Indexes on Computed Properties cause Invalid Reference Error
EdgeDB 4.0-dev.7528+local (repl 3.1.0-dev)


Reproduction:
1. run `edb cli migration create` on the following schema:

```
module default {
type Person {

    required property name -> str;
    
    property name2 := .name;

    index on (.name2);
}

}
```

The error is:
```
edgedb error: InvalidReferenceError: object type 'default::Person' has no link or property 'name2' (on line 1, column 1)
  Hint: did you mean 'name'?
<stacktraces>
        File "edgedb/edb/edgeql/compiler/setgen.py", line 843, in resolve_ptr_with_intersections
      edb.errors.InvalidReferenceError: object type 'default::Person' has no link or property 'name2'
```
diff --git a/edb/edgeql/compiler/setgen.py b/edb/edgeql/compiler/setgen.py
index 9889fcff5..9a86037fb 100644
--- a/edb/edgeql/compiler/setgen.py
+++ b/edb/edgeql/compiler/setgen.py
@@ -726,6 +726,15 @@ def resolve_ptr_with_intersections(
         if ptr is not None:
             ref = ptr.get_nearest_non_derived_parent(ctx.env.schema)
             if track_ref is not False:
+                # XXX: This condition is a hack that approximates what
+                # really exists in the schema and what does not exist.
+                # The approximation is: a computed pointer that does not
+                # come from an alias exists in the schema, even it is derived.
+                if (ref != ptr and
+                        ptr.get_computable(ctx.env.schema) and
+                        not ptr.get_from_alias(ctx.env.schema)):
+                    ctx.env.add_schema_ref(ptr, track_ref)
+
                 ctx.env.add_schema_ref(ref, track_ref)
                 _add_target_schema_refs(
                     ref.get_target(ctx.env.schema), ctx=ctx)
diff --git a/tests/test_schema.py b/tests/test_schema.py
index 1ff1da506..389fb6455 100644
--- a/tests/test_schema.py
+++ b/tests/test_schema.py
@@ -6214,6 +6214,21 @@ class TestGetMigration(tb.BaseSchemaLoadTest):
             }
         """])
 
+    def test_schema_migrations_equivalence_index_06(self):
+        self._assert_migration_equivalence([r"""
+            type Base {
+                property first_name -> str;
+                property name := .first_name;
+            }
+        """, r"""
+            type Base {
+                property first_name -> str;
+                property name := .first_name;
+                # an index on a computable
+                index on (.name);
+            }
+        """])
+
     def test_schema_migrations_equivalence_constraint_01(self):
         self._assert_migration_equivalence([r"""
             type Base {
['edb/edgeql/compiler/setgen.py', 'tests/test_schema.py']