From f3bec23e3d07f4b48e9dc9394e92e3e322a4e109 Mon Sep 17 00:00:00 2001 From: Victoria Earl Date: Mon, 7 Oct 2024 17:43:56 -0400 Subject: [PATCH] Add relationship between MIVS dev and attendee We've been using a crude matching algorithm for this for years instead of just tying them together via a DB relationship. Doing so meant that changing the email address for an indie-dev-created badge would break the link. Now it doesn't! --- ...4c4ac_add_mivs_to_attendee_relationship.py | 63 ++++++++++++++++++ celerybeat-schedule | Bin 77824 -> 94208 bytes docker-compose.yml | 1 - uber/configspec.ini | 2 + uber/models/attendee.py | 3 + uber/models/group.py | 2 +- uber/models/mivs.py | 13 ++-- uber/site_sections/mivs.py | 6 +- uber/templates/mivs_admin/studios.html | 4 +- 9 files changed, 80 insertions(+), 14 deletions(-) create mode 100644 alembic/versions/9b657ae4c4ac_add_mivs_to_attendee_relationship.py diff --git a/alembic/versions/9b657ae4c4ac_add_mivs_to_attendee_relationship.py b/alembic/versions/9b657ae4c4ac_add_mivs_to_attendee_relationship.py new file mode 100644 index 000000000..01e64a9dc --- /dev/null +++ b/alembic/versions/9b657ae4c4ac_add_mivs_to_attendee_relationship.py @@ -0,0 +1,63 @@ +"""Add MIVS to attendee relationship + +Revision ID: 9b657ae4c4ac +Revises: 318d761a5c62 +Create Date: 2024-10-07 20:53:07.005134 + +""" + + +# revision identifiers, used by Alembic. +revision = '9b657ae4c4ac' +down_revision = '318d761a5c62' +branch_labels = None +depends_on = None + +from alembic import op +import sqlalchemy as sa +import residue + + +try: + is_sqlite = op.get_context().dialect.name == 'sqlite' +except Exception: + is_sqlite = False + +if is_sqlite: + op.get_context().connection.execute('PRAGMA foreign_keys=ON;') + utcnow_server_default = "(datetime('now', 'utc'))" +else: + utcnow_server_default = "timezone('utc', current_timestamp)" + +def sqlite_column_reflect_listener(inspector, table, column_info): + """Adds parenthesis around SQLite datetime defaults for utcnow.""" + if column_info['default'] == "datetime('now', 'utc')": + column_info['default'] = utcnow_server_default + +sqlite_reflect_kwargs = { + 'listeners': [('column_reflect', sqlite_column_reflect_listener)] +} + +# =========================================================================== +# HOWTO: Handle alter statements in SQLite +# +# def upgrade(): +# if is_sqlite: +# with op.batch_alter_table('table_name', reflect_kwargs=sqlite_reflect_kwargs) as batch_op: +# batch_op.alter_column('column_name', type_=sa.Unicode(), server_default='', nullable=False) +# else: +# op.alter_column('table_name', 'column_name', type_=sa.Unicode(), server_default='', nullable=False) +# +# =========================================================================== + + +def upgrade(): + op.add_column('indie_developer', sa.Column('attendee_id', residue.UUID(), nullable=True)) + op.create_unique_constraint(op.f('uq_indie_developer_attendee_id'), 'indie_developer', ['attendee_id']) + op.create_foreign_key(op.f('fk_indie_developer_attendee_id_attendee'), 'indie_developer', 'attendee', ['attendee_id'], ['id']) + + +def downgrade(): + op.drop_constraint(op.f('fk_indie_developer_attendee_id_attendee'), 'indie_developer', type_='foreignkey') + op.drop_constraint(op.f('uq_indie_developer_attendee_id'), 'indie_developer', type_='unique') + op.drop_column('indie_developer', 'attendee_id') diff --git a/celerybeat-schedule b/celerybeat-schedule index 0fd001d91b872b48ecd3418312330e74892d5da1..2b81de8c96219c6137cbfefb45ebc5f383c98080 100644 GIT binary patch delta 1395 zcmZp8z|!!5b%G*K0V4wl`~hN_jk?v0lQ|R=w3!9Kf(#5FAT%3{F91`IX%WljFTL=nBoK` z^L%*0!No2r%E4Y;IQh?qKt|=sejgtQLWB-?P00{zn-Vm|TYa+qr(00bQ=AA<{x5Qq z>x;@J@B8ckl|3(wEV~dSD$l`wWinLMH(~O@FBimsqKX{sH{ZiVFR^4uXUI;TXzVum z?bj%%QTLn?Mn!yECjoKPV@H@McZRNpH-k6BWW&$mldDZkCcnLEGFid)~pR4xd1)-YLwIvz#p|1Zl8>SBA zdWFe*O)V$yyKX-HwqKeGU^=p9~7?eD{Fqs#?jmla~QKEMQKfigF~hOW)|3! nkhCU@k=A;^Y0wx|JWCOn0O4s*g@Y}i0&18yI1{6!JyT8qM {{ studio.name }} - {%- if studio.primary_contacts[0].matching_attendee -%} - {{ studio.primary_contacts[0].full_name }} + {%- if studio.primary_contacts[0].attendee -%} + {{ studio.primary_contacts[0].full_name }} {%- else -%} {{ studio.primary_contacts[0].full_name }} {%- endif %}