FIX assignment repo migration where dangling submissions exist
@@ -20,7 +20,7 @@ def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"assignment_repo",
- sa.Column("netid", sa.String(length=128), nullable=True),
+ sa.Column("netid", mysql.VARCHAR(collation="utf8mb4_unicode_ci", length=128), nullable=True),
)
conn = op.get_bind()
@@ -28,6 +28,20 @@ def upgrade():
conn.execute('update assignment_repo '
'join user on assignment_repo.owner_id = user.id '
'set assignment_repo.netid = user.netid;')
+ # Drop dangling
+ conn.execute('delete sb from assignment_repo ar '
+ 'join submission s on s.assignment_repo_id = ar.id '
+ 'join submission_build sb on sb.submission_id = s.id '
+ 'where ar.netid is NULL;')
+ conn.execute('delete str from assignment_repo ar '
+ 'join submission s on s.assignment_repo_id = ar.id '
+ 'join submission_test_result str on str.submission_id = s.id '
+ 'where ar.netid is NULL;')
+ conn.execute('delete s from assignment_repo ar '
+ 'join submission s on s.assignment_repo_id = ar.id '
+ 'where ar.netid is NULL;')
+ conn.execute('delete ar from assignment_repo ar '
+ 'where ar.netid is NULL;')
op.alter_column(
"assignment_repo",
