Repository: edgedb/edgedb

Issue:
Regression of migration create
- EdgeDB Version: 1.0b3.dev5669+d2021061000.g7da47c19e.cv202105190000-202106100012~focal.nightly

Schema:
```
module default {
    type Bar { link spam -> Spam };
    type Spam { link bar -> Bar };
};
```

Running `edgedb migration create`:
```
did you create object type 'default::Bar'? [y,n,l,c,b,s,q,?]
l
Following DDL statements will be applied:
    CREATE TYPE default::Bar;
did you create object type 'default::Bar'? [y,n,l,c,b,s,q,?]
y
did you create object type 'default::Spam'? [y,n,l,c,b,s,q,?]
l
Following DDL statements will be applied:
    CREATE TYPE default::Spam {
        CREATE LINK bar -> default::Bar;
    };
did you create object type 'default::Spam'? [y,n,l,c,b,s,q,?]
y
did you create link 'spam' of object type 'default::Bar'? [y,n,l,c,b,s,q,?]
l
Following DDL statements will be applied:
    ALTER TYPE default::Bar {
        CREATE LINK spam -> default::Spam;
    };
did you create link 'spam' of object type 'default::Bar'? [y,n,l,c,b,s,q,?]
y
Created tests/migrations/db2/migrations/00001.edgeql, id: m1puqocioek7ruyi55htuvibjiqixtwi2r4lkajtl22luwnmr4erca
```

That last question should not be asked. as it's an extra DDL for the question 1 (creating `Bar` type).


Discussion:
It looks like the regression was introduced by #2561
And the best part is that there was a test for it, test_edgeql_migration_prompt_id_01, and I just updated it to test the wrong behavior.
(I didn't understand what `prompt_id` was used for and probably should have figured that out before messing with it much.)

Resolving patch:
diff --git a/edb/server/compiler/compiler.py b/edb/server/compiler/compiler.py
--- a/edb/server/compiler/compiler.py
+++ b/edb/server/compiler/compiler.py
@@ -1045,8 +1045,12 @@ def _compile_ql_migration(
                                 schema=schema,
                                 modaliases=current_tx.get_modaliases(),
                             )
+                            _, prompt_text = top_op2.get_user_prompt()
 
-                            prompt_id, prompt_text = top_op2.get_user_prompt()
+                            # The prompt_id still needs to come from
+                            # the original op, though, since
+                            # orig_cmd_class is lost in ddl.
+                            prompt_id, _ = top_op.get_user_prompt()
                             confidence = top_op.get_annotation('confidence')
                             assert confidence is not None
 


Test patch:
diff --git a/tests/test_edgeql_data_migration.py b/tests/test_edgeql_data_migration.py
--- a/tests/test_edgeql_data_migration.py
+++ b/tests/test_edgeql_data_migration.py
@@ -8608,9 +8608,13 @@ async def test_edgeql_migration_prompt_id_01(self):
 
         await self.fast_forward_describe_migration(limit=1)
 
+        # N.B: It is important that the prompt_id here match the
+        # prompt_id in the first migration, so that the migration tool
+        # will automatically apply this proposal as part of the
+        # earlier action.
         await self.assert_describe_migration({
             'proposed': {
-                'prompt_id': 'CreateLink LINK test::`__|spam@test|Bar`',
+                'prompt_id': 'CreateObjectType TYPE test::Bar',
                 'statements': [{
                     'text': """
                         ALTER TYPE test::Bar {