-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add role, organization and UserOrganization link table (#9)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
- Loading branch information
1 parent
d4201d4
commit 6e36c6e
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
backend/app/alembic/versions/56310da83983_add_organization_table_and_.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,43 @@ | ||
"""Add organization table and UserOrganization join table | ||
Revision ID: 56310da83983 | ||
Revises: e2412789c190 | ||
Create Date: 2024-03-27 21:29:02.652462 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
import sqlmodel.sql.sqltypes | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '56310da83983' | ||
down_revision = 'e2412789c190' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table('organization', | ||
sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False), | ||
sa.Column('description', sqlmodel.sql.sqltypes.AutoString(), nullable=True), | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
op.create_table('userorganization', | ||
sa.Column('user_id', sa.Integer(), nullable=False), | ||
sa.Column('organization_id', sa.Integer(), nullable=False), | ||
sa.Column('role', sa.Enum('MEMBER', 'ADMIN', name='permissionsenum'), nullable=False), | ||
sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], ), | ||
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), | ||
sa.PrimaryKeyConstraint('user_id', 'organization_id') | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table('userorganization') | ||
op.drop_table('organization') | ||
# ### end Alembic commands ### |
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