|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 2 | +# you may not use this file except in compliance with the License. |
| 3 | +# You may obtain a copy of the License at |
| 4 | +# |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | +# See the License for the specific language governing permissions and |
| 11 | +# limitations under the License. |
| 12 | +""" |
| 13 | +social auth models |
| 14 | +
|
| 15 | +Revision ID: fcb2e13374bb |
| 16 | +Revises: c8384ca429fc |
| 17 | +Create Date: 2025-04-27 16:01:36.308879 |
| 18 | +""" |
| 19 | + |
| 20 | +import social_sqlalchemy |
| 21 | +import sqlalchemy as sa |
| 22 | + |
| 23 | +from alembic import op |
| 24 | + |
| 25 | +revision = "fcb2e13374bb" |
| 26 | +down_revision = "13c1c0ac92e9" |
| 27 | + |
| 28 | + |
| 29 | +def upgrade(): |
| 30 | + op.create_table( |
| 31 | + "social_auth_association", |
| 32 | + sa.Column("id", sa.Integer(), nullable=False), |
| 33 | + sa.Column("server_url", sa.String(length=255), nullable=True), |
| 34 | + sa.Column("handle", sa.String(length=255), nullable=True), |
| 35 | + sa.Column("secret", sa.String(length=255), nullable=True), |
| 36 | + sa.Column("issued", sa.Integer(), nullable=True), |
| 37 | + sa.Column("lifetime", sa.Integer(), nullable=True), |
| 38 | + sa.Column("assoc_type", sa.String(length=64), nullable=True), |
| 39 | + sa.PrimaryKeyConstraint("id"), |
| 40 | + sa.UniqueConstraint("server_url", "handle"), |
| 41 | + ) |
| 42 | + op.create_table( |
| 43 | + "social_auth_code", |
| 44 | + sa.Column("id", sa.Integer(), nullable=False), |
| 45 | + sa.Column("email", sa.String(length=200), nullable=True), |
| 46 | + sa.Column("code", sa.String(length=32), nullable=True), |
| 47 | + sa.PrimaryKeyConstraint("id"), |
| 48 | + sa.UniqueConstraint("code", "email"), |
| 49 | + ) |
| 50 | + op.create_index( |
| 51 | + op.f("ix_social_auth_code_code"), "social_auth_code", ["code"], unique=False |
| 52 | + ) |
| 53 | + op.create_table( |
| 54 | + "social_auth_nonce", |
| 55 | + sa.Column("id", sa.Integer(), nullable=False), |
| 56 | + sa.Column("server_url", sa.String(length=255), nullable=True), |
| 57 | + sa.Column("timestamp", sa.Integer(), nullable=True), |
| 58 | + sa.Column("salt", sa.String(length=40), nullable=True), |
| 59 | + sa.PrimaryKeyConstraint("id"), |
| 60 | + sa.UniqueConstraint("server_url", "timestamp", "salt"), |
| 61 | + ) |
| 62 | + op.create_table( |
| 63 | + "social_auth_partial", |
| 64 | + sa.Column("id", sa.Integer(), nullable=False), |
| 65 | + sa.Column("token", sa.String(length=32), nullable=True), |
| 66 | + sa.Column("data", social_sqlalchemy.storage.JSONType(), nullable=True), |
| 67 | + sa.Column("next_step", sa.Integer(), nullable=True), |
| 68 | + sa.Column("backend", sa.String(length=32), nullable=True), |
| 69 | + sa.PrimaryKeyConstraint("id"), |
| 70 | + ) |
| 71 | + op.create_index( |
| 72 | + op.f("ix_social_auth_partial_token"), |
| 73 | + "social_auth_partial", |
| 74 | + ["token"], |
| 75 | + unique=False, |
| 76 | + ) |
| 77 | + op.create_table( |
| 78 | + "social_auth_usersocialauth", |
| 79 | + sa.Column("uid", sa.String(length=255), nullable=False), |
| 80 | + sa.Column("user_id", sa.UUID(), nullable=False), |
| 81 | + sa.Column("id", sa.Integer(), nullable=False), |
| 82 | + sa.Column("provider", sa.String(length=32), nullable=True), |
| 83 | + sa.Column("extra_data", social_sqlalchemy.storage.JSONType(), nullable=True), |
| 84 | + sa.ForeignKeyConstraint( |
| 85 | + ["user_id"], |
| 86 | + ["users.id"], |
| 87 | + ), |
| 88 | + sa.PrimaryKeyConstraint("id"), |
| 89 | + sa.UniqueConstraint("provider", "uid"), |
| 90 | + ) |
| 91 | + op.create_index( |
| 92 | + op.f("ix_social_auth_usersocialauth_user_id"), |
| 93 | + "social_auth_usersocialauth", |
| 94 | + ["user_id"], |
| 95 | + unique=False, |
| 96 | + ) |
| 97 | + |
| 98 | + |
| 99 | +def downgrade(): |
| 100 | + op.drop_index( |
| 101 | + op.f("ix_social_auth_usersocialauth_user_id"), |
| 102 | + table_name="social_auth_usersocialauth", |
| 103 | + ) |
| 104 | + op.drop_table("social_auth_usersocialauth") |
| 105 | + op.drop_index( |
| 106 | + op.f("ix_social_auth_partial_token"), table_name="social_auth_partial" |
| 107 | + ) |
| 108 | + op.drop_table("social_auth_partial") |
| 109 | + op.drop_table("social_auth_nonce") |
| 110 | + op.drop_index(op.f("ix_social_auth_code_code"), table_name="social_auth_code") |
| 111 | + op.drop_table("social_auth_code") |
| 112 | + op.drop_table("social_auth_association") |
0 commit comments