From 0ab89116ee02410cda3e406699b0ac1f44fe4448 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Mon, 30 Oct 2017 11:17:46 +0000 Subject: [PATCH] use server_default in alembic to ensure zero-downtimeness we can back-fill data, however, between alembic running and the api updating to the new code, it'll still try and create new users without adding the auth_type, because that won't be referenced in the model yet. Instead of using a python-level default, a postgres-level server_default will make postgres set every row to sms_auth if it's not defined in the application. --- migrations/versions/0131_user_auth_types.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/migrations/versions/0131_user_auth_types.py b/migrations/versions/0131_user_auth_types.py index d86124ff7..a41a7c163 100644 --- a/migrations/versions/0131_user_auth_types.py +++ b/migrations/versions/0131_user_auth_types.py @@ -21,16 +21,12 @@ def upgrade(): ) op.execute("INSERT INTO auth_type VALUES ('email_auth'), ('sms_auth')") - op.add_column('users', sa.Column('auth_type', sa.String(), nullable=True)) - op.execute("UPDATE users SET auth_type='sms_auth'") - op.alter_column('users', 'auth_type', nullable=False) + op.add_column('users', sa.Column('auth_type', sa.String(), nullable=False, server_default='sms_auth')) op.create_index(op.f('ix_users_auth_type'), 'users', ['auth_type'], unique=False) op.create_foreign_key(None, 'users', 'auth_type', ['auth_type'], ['name']) - op.add_column('invited_users', sa.Column('auth_type', sa.String(), nullable=True)) - op.execute("UPDATE invited_users SET auth_type='sms_auth'") - op.alter_column('invited_users', 'auth_type', nullable=False) + op.add_column('invited_users', sa.Column('auth_type', sa.String(), nullable=False, server_default='sms_auth')) op.create_index(op.f('ix_invited_users_auth_type'), 'invited_users', ['auth_type'], unique=False) op.create_foreign_key(None, 'invited_users', 'auth_type', ['auth_type'], ['name'])