forked from VictoryCTO/project-python-flask
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 04-Add role entity to the model
- Loading branch information
1 parent
0272bda
commit 3b53544
Showing
2 changed files
with
102 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
migrations/versions/d496c141abd6_modded_users_table_and_added_roles_.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"""Modded users table and added roles tables for many-to-many relationsihps | ||
Revision ID: d496c141abd6 | ||
Revises: 8e0626ed0ebe | ||
Create Date: 2024-10-15 15:42:30.995773 | ||
""" | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "d496c141abd6" | ||
down_revision = "8e0626ed0ebe" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"roles_lookup", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("role_name", sa.String(length=16), nullable=False), | ||
sa.Column("department_name", sa.String(length=64), nullable=False), | ||
sa.PrimaryKeyConstraint("id"), | ||
sa.UniqueConstraint("role_name", "department_name", name="_role_dept_uc"), | ||
) | ||
op.create_table( | ||
"users_roles", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("user_id", sa.Integer(), nullable=False), | ||
sa.Column("role_id", sa.Integer(), nullable=False), | ||
sa.ForeignKeyConstraint( | ||
["role_id"], | ||
["roles_lookup.id"], | ||
), | ||
sa.ForeignKeyConstraint( | ||
["user_id"], | ||
["users.id"], | ||
), | ||
sa.PrimaryKeyConstraint("id"), | ||
sa.UniqueConstraint("user_id", "role_id", name="_user_role_uc"), | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table("users_roles") | ||
op.drop_table("roles_lookup") | ||
# ### end Alembic commands ### |