|
| 1 | +"""add common tables |
| 2 | +
|
| 3 | +Revision ID: a19721f73cfb |
| 4 | +Revises: |
| 5 | +Create Date: 2023-09-21 18:02:50.136222 |
| 6 | +
|
| 7 | +""" |
| 8 | +import sqlalchemy as sa |
| 9 | +from alembic import op |
| 10 | +from sqlalchemy.dialects import mysql |
| 11 | + |
| 12 | +# revision identifiers, used by Alembic. |
| 13 | +revision = "a19721f73cfb" |
| 14 | +down_revision = None |
| 15 | +branch_labels = None |
| 16 | +depends_on = None |
| 17 | + |
| 18 | + |
| 19 | +def upgrade() -> None: |
| 20 | + # ### commands auto generated by Alembic - please adjust! ### |
| 21 | + op.create_table( |
| 22 | + "organization", |
| 23 | + sa.Column("id", mysql.BIGINT(unsigned=True), nullable=False), |
| 24 | + sa.Column("name", sa.String(length=100), nullable=False), |
| 25 | + sa.Column( |
| 26 | + "created_at", |
| 27 | + sa.DateTime(), |
| 28 | + server_default=sa.text("CURRENT_TIMESTAMP"), |
| 29 | + nullable=True, |
| 30 | + ), |
| 31 | + sa.PrimaryKeyConstraint("id"), |
| 32 | + ) |
| 33 | + op.create_table( |
| 34 | + "roles", |
| 35 | + sa.Column("id", mysql.BIGINT(unsigned=True), nullable=False), |
| 36 | + sa.Column("role", sa.String(length=100), nullable=False), |
| 37 | + sa.Column( |
| 38 | + "created_at", |
| 39 | + sa.DateTime(), |
| 40 | + server_default=sa.text("CURRENT_TIMESTAMP"), |
| 41 | + nullable=True, |
| 42 | + ), |
| 43 | + sa.PrimaryKeyConstraint("id"), |
| 44 | + ) |
| 45 | + op.create_table( |
| 46 | + "users", |
| 47 | + sa.Column("id", mysql.BIGINT(unsigned=True), nullable=False), |
| 48 | + sa.Column("organization_id", mysql.BIGINT(unsigned=True), nullable=False), |
| 49 | + sa.Column("uid", sa.String(length=100), nullable=False), |
| 50 | + sa.Column("name", sa.String(length=100), nullable=False), |
| 51 | + sa.Column("email", sa.String(length=255), nullable=False), |
| 52 | + sa.Column("attributes", sa.JSON(), nullable=True), |
| 53 | + sa.Column( |
| 54 | + "created_at", |
| 55 | + sa.DateTime(), |
| 56 | + server_default=sa.text("CURRENT_TIMESTAMP"), |
| 57 | + nullable=True, |
| 58 | + ), |
| 59 | + sa.Column( |
| 60 | + "updated_at", |
| 61 | + sa.DateTime(), |
| 62 | + server_default=sa.text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"), |
| 63 | + nullable=True, |
| 64 | + ), |
| 65 | + sa.Column("active", sa.Boolean(), nullable=False), |
| 66 | + sa.ForeignKeyConstraint( |
| 67 | + ["organization_id"], |
| 68 | + ["organization.id"], |
| 69 | + ), |
| 70 | + sa.PrimaryKeyConstraint("id"), |
| 71 | + sa.UniqueConstraint("uid", name="idx_uid"), |
| 72 | + ) |
| 73 | + op.create_table( |
| 74 | + "user_roles", |
| 75 | + sa.Column("id", mysql.BIGINT(unsigned=True), nullable=False), |
| 76 | + sa.Column("user_id", mysql.BIGINT(unsigned=True), nullable=False), |
| 77 | + sa.Column("role_id", mysql.BIGINT(unsigned=True), nullable=False), |
| 78 | + sa.Column( |
| 79 | + "created_at", |
| 80 | + sa.DateTime(), |
| 81 | + server_default=sa.text("CURRENT_TIMESTAMP"), |
| 82 | + nullable=True, |
| 83 | + ), |
| 84 | + sa.ForeignKeyConstraint( |
| 85 | + ["role_id"], |
| 86 | + ["roles.id"], |
| 87 | + ), |
| 88 | + sa.ForeignKeyConstraint( |
| 89 | + ["user_id"], |
| 90 | + ["users.id"], |
| 91 | + ), |
| 92 | + sa.PrimaryKeyConstraint("id"), |
| 93 | + sa.UniqueConstraint("user_id", "role_id", name="idx_user_id"), |
| 94 | + ) |
| 95 | + op.create_table( |
| 96 | + "workspaces", |
| 97 | + sa.Column("id", mysql.BIGINT(unsigned=True), nullable=False), |
| 98 | + sa.Column("name", sa.String(length=100), nullable=False), |
| 99 | + sa.Column("user_id", mysql.BIGINT(unsigned=True), nullable=False), |
| 100 | + sa.Column( |
| 101 | + "created_at", |
| 102 | + sa.DateTime(), |
| 103 | + server_default=sa.text("CURRENT_TIMESTAMP"), |
| 104 | + nullable=True, |
| 105 | + ), |
| 106 | + sa.Column( |
| 107 | + "updated_at", |
| 108 | + sa.DateTime(), |
| 109 | + server_default=sa.text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"), |
| 110 | + nullable=True, |
| 111 | + ), |
| 112 | + sa.Column("deleted", sa.Boolean(), nullable=False), |
| 113 | + sa.ForeignKeyConstraint(["user_id"], ["users.id"], name="user"), |
| 114 | + sa.PrimaryKeyConstraint("id"), |
| 115 | + ) |
| 116 | + op.create_table( |
| 117 | + "workspaces_share_users", |
| 118 | + sa.Column("id", mysql.BIGINT(unsigned=True), nullable=False), |
| 119 | + sa.Column("workspace_id", mysql.BIGINT(unsigned=True), nullable=False), |
| 120 | + sa.Column("user_id", mysql.BIGINT(unsigned=True), nullable=False), |
| 121 | + sa.Column( |
| 122 | + "created_at", |
| 123 | + sa.DateTime(), |
| 124 | + server_default=sa.text("CURRENT_TIMESTAMP"), |
| 125 | + nullable=True, |
| 126 | + ), |
| 127 | + sa.ForeignKeyConstraint( |
| 128 | + ["user_id"], |
| 129 | + ["users.id"], |
| 130 | + ), |
| 131 | + sa.ForeignKeyConstraint( |
| 132 | + ["workspace_id"], |
| 133 | + ["workspaces.id"], |
| 134 | + ), |
| 135 | + sa.PrimaryKeyConstraint("id"), |
| 136 | + sa.UniqueConstraint("workspace_id", "user_id", name="idx_workspace_id_user_id"), |
| 137 | + ) |
| 138 | + # ### end Alembic commands ### |
| 139 | + |
| 140 | + |
| 141 | +def downgrade() -> None: |
| 142 | + # ### commands auto generated by Alembic - please adjust! ### |
| 143 | + op.drop_table("workspaces_share_users") |
| 144 | + op.drop_table("workspaces") |
| 145 | + op.drop_table("user_roles") |
| 146 | + op.drop_table("users") |
| 147 | + op.drop_table("roles") |
| 148 | + op.drop_table("organization") |
| 149 | + # ### end Alembic commands ### |
0 commit comments