Repository: edgedb/edgedb

Issue:
Migrating from link to multi link -> ERROR: MissingRequiredError
### Discussed in https://github.com/edgedb/edgedb/discussions/2777

<div type='discussions-op-text'>

<sup>Originally posted by **clmno** August  6, 2021</sup>
EdgeDB Version: EdgeDB 1.0-beta.2+ga7130d5c7.cv202104290000 (repl 1.0.0-beta.2)

```sql
START MIGRATION TO {
    module default {
        type Company {
            required property name -> str {
                constraint exclusive;
            }
            link admin -> User;
        }
        type User {
            required property name -> str {
                constraint exclusive;
            }
            link company -> Company;
        }
    }
};
POPULATE MIGRATION;
COMMIT MIGRATION;

INSERT Company {name := "ABC Company"};
INSERT Company {name := "XYZ Company"};
INSERT Company {name := "123 Company"};

INSERT User {name := "Alice", company := (SELECT Company FILTER .name = "ABC Company")};
INSERT User {name := "Bob", company := (SELECT Company FILTER .name = "XYZ Company")};
INSERT User {name := "Cathy", company := (SELECT Company FILTER .name = "ABC Company")};

UPDATE Company FILTER .name = "ABC Company" SET {admin := (SELECT User Filter .name = "Alice")};
UPDATE Company FILTER .name = "XYZ Company" SET {admin := (SELECT User Filter .name = "Bob")};
```

Here Company `123 Company` as no link for `admin`. Which is acceptable according to the schema.

But when I try changing `link admin` to `multi link admin` I get this error
> Error: ERROR: MissingRequiredError: missing value for required link 'admin' of object type 'default::Company'

<details>
  <summary>View migration </summary>

  ```sql
    START MIGRATION TO {
      module default {
          type Company {
              required property name -> str {
                  constraint exclusive;
              }
              multi link admin -> User; # multi link
          }
          type User {
              required property name -> str {
                  constraint exclusive;
              }
              link company -> Company;
          }
      }
  };
  POPULATE MIGRATION;
  COMMIT MIGRATION;
  ```

</details></div>


Discussion:

Resolving patch:
diff --git a/edb/pgsql/delta.py b/edb/pgsql/delta.py
--- a/edb/pgsql/delta.py
+++ b/edb/pgsql/delta.py
@@ -3113,23 +3113,6 @@ def _alter_pointer_cardinality(
 
             self.pgops.add(dbops.Query(update_qry))
 
-            check_qry = textwrap.dedent(f'''\
-                SELECT
-                    edgedb.raise(
-                        NULL::text,
-                        'not_null_violation',
-                        msg => 'missing value for required property',
-                        detail => '{{"object_id": "' || id || '"}}',
-                        "column" => {ql(str(ptr.id))}
-                    )
-                FROM {src_tab}
-                WHERE id != ALL (SELECT source FROM {tab})
-                LIMIT 1
-                INTO _dummy_text;
-            ''')
-
-            self.pgops.add(dbops.Query(check_qry))
-
             self.pgops.add(
                 self.drop_inhview(
                     orig_schema,


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
@@ -145,6 +145,7 @@ async def test_edgeql_ddl_type_06(self):
                 a := (SELECT A6 LIMIT 1),
                 b := 'foo'
             };
+            INSERT Object6;
         """)
 
         await self.assert_query_result(
@@ -184,7 +185,7 @@ async def test_edgeql_ddl_type_06(self):
             SELECT Object6 {
                 a: {name},
                 b,
-            }
+            } FILTER EXISTS .a
             """,
             [{
                 'a': {'name': 'a6'},
@@ -240,7 +241,7 @@ async def test_edgeql_ddl_type_06(self):
             SELECT Object6 {
                 a: {name},
                 b,
-            }
+            } FILTER EXISTS .a
             """,
             [{
                 'a': [{'name': 'a6'}],
@@ -297,7 +298,7 @@ async def test_edgeql_ddl_type_06(self):
             SELECT Object6 {
                 a: {name},
                 b,
-            }
+            } FILTER EXISTS .a
             """,
             [{
                 'a': {'name': 'a6'},