Repository: edgedb/edgedb

Issue:
Unable to create a migration to an alias of a type
`edb cli migration create` fails when trying to migrate from:

```
# schema 1
    type User {
        link currentPolls: Poll;
    };

    type Poll;
```
... to:
```
# schema 2
    alias TEMP := User;

    type User {
        link currentPolls: Poll;
    };

    type Poll;
```

- EdgeDB Version: ced39b843




Discussion:
This issue was sent to me by @elprans, who got the schema and migrations from (I believe) @avedetvedea
This is delta mismatch:
```
================================================================================
DESCRIBE CURRENT MIGRATION AS JSON mismatch
================================================================================
<DeltaRoot at 0x7f92da98b510> (
    <AlterObjectType canonical=True, classname=default::TEMP, annotations={'confidence': 1.0}, orig_cmd_type=<class 'edb.schema.objtypes.AlterObjectType'> at 0x7f92d9a0f8d0> (
        <AlterLink canonical=True, classname=default::__|currentPolls@default|TEMP, annotations={'confidence': 1.0}, aux_object_data={'from_alias': True} at 0x7f92d9a0ee50> (
            computable       = False | None,
            inherited_fields = edb.common.checked.FrozenCheckedSet[str]({'computable', 'readonly', 'target', 'cardinality'}) | edb.common.checked.FrozenCheckedSet[str]({'readonly', 'target', 'cardinality'})
        )
    )
)
```

It seems like the `computable` gets inherited as `False` from the parent of the link, on the current schema, but not on the target schema.
I just found out that this does *not* reproduce if you migrate from empty schema, to schema 1 and then try to migrate to schema 2.

It shows up only if you apply the whole migration log reported by @avedetvedea (190+ migrations) and my migrations that pruned down the schema (20+ migrations).

So my next course of action is to look trough all the migrations to find anything related and trying to reproduce on empty schema. This will be my day.
I thought Elvis told you, but he found that out initially. Only after he couldn't reproduce, I sent the full dbschema folder and things blew up. 

Also I'm personally excited because I had couple of cases since 2.0 that correctly applied migrations caused problems down the line and I couldn't wrap my head around for a long time.
He did not, but in retrospect, it would not have mattered - I had to do the long schema pruning and bug isolation, and only now its easy to find the cause issue:

I'm able to reproduce this by:
1. migrating to:
  ```
  # schema 0
  type User {
      multi link currentPolls := (SELECT Poll);
  };

  type Poll;
  ```
2. migrating to schema 1,
3. migrating to schema 2 fails

So the cause is (most probably) in the code that converts a computed link into a non-computed, also known as RESET EXPRESSION, also known as `qlast.SetField(name='expr', value=None, special_syntax=True)`, also known as `sd.AlterObjectProperty`.
Also fails with `single link`, `single property` and `multi property`.

Resolving patch:
diff --git a/edb/schema/indexes.py b/edb/schema/indexes.py
--- a/edb/schema/indexes.py
+++ b/edb/schema/indexes.py
@@ -1220,12 +1220,12 @@ def get_effective_fts_index(
 
     else:
         # there are no fts indexes defined on the subject
-        # the inhereted indexes take effect
+        # the inherited indexes take effect
 
         if len(fts_indexes) > 1:
             subject_name = subject.get_displayname(schema)
             raise errors.SchemaDefinitionError(
-                f'multiple {fts_name} indexes inhereted for {subject_name}'
+                f'multiple {fts_name} indexes inherited for {subject_name}'
             )
 
         effective = fts_indexes[0]
diff --git a/edb/schema/pointers.py b/edb/schema/pointers.py
--- a/edb/schema/pointers.py
+++ b/edb/schema/pointers.py
@@ -2179,7 +2179,7 @@ def canonicalize_attributes(
                 # that means that `RESET EXPRESSION` was executed
                 # and this is no longer a computable.
 
-                self.set_attribute_value('computable', False)
+                self.set_attribute_value('computable', None)
                 computed_fields = pointer.get_computed_fields(schema)
                 if (
                     'required' in computed_fields


Test patch:
diff --git a/tests/test_edgeql_ddl.py b/tests/test_edgeql_ddl.py
--- a/tests/test_edgeql_ddl.py
+++ b/tests/test_edgeql_ddl.py
@@ -14329,6 +14329,32 @@ async def test_edgeql_ddl_adjust_computed_11(self):
             }
         ''')
 
+    async def test_edgeql_ddl_adjust_computed_12(self):
+        # GH Issue #6459
+        await self.con.execute(r'''
+            CREATE TYPE default::Foo {
+                CREATE PROPERTY foo := 'hello';
+            };
+            ALTER TYPE default::Foo {
+                ALTER PROPERTY foo {
+                    RESET EXPRESSION;
+                    RESET OPTIONALITY;
+                    SET TYPE std::str;
+                }
+            };
+        ''')
+
+        await self.con.execute(r'''
+            START MIGRATION TO {
+                TYPE default::Foo {
+                    PROPERTY foo: std::str;
+                };
+                ALIAS default::FooAlias := default::Foo;
+            };
+            POPULATE MIGRATION;
+            COMMIT MIGRATION;
+        ''')
+
     async def test_edgeql_ddl_captured_as_migration_01(self):
 
         await self.con.execute(r"""