first tables setup
This commit is contained in:
parent
d79ba5d208
commit
d7039884d2
@ -0,0 +1,66 @@
|
||||
"""basic user setup
|
||||
|
||||
Revision ID: e1f390264396
|
||||
Revises:
|
||||
Create Date: 2025-12-24 12:27:59.305916
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'e1f390264396'
|
||||
down_revision: Union[str, Sequence[str], None] = None
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('pillar_tool_permission',
|
||||
sa.Column('id', sa.UUID(), nullable=False),
|
||||
sa.Column('name', sa.String(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('pillar_tool_role',
|
||||
sa.Column('id', sa.UUID(), nullable=False),
|
||||
sa.Column('name', sa.String(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('pillar_tool_user',
|
||||
sa.Column('id', sa.UUID(), nullable=False),
|
||||
sa.Column('username', sa.String(), nullable=False),
|
||||
sa.Column('pw_hash', sa.String(), nullable=False),
|
||||
sa.Column('pw_salt', sa.String(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('pillar_tool_role_permission',
|
||||
sa.Column('role_id', sa.UUID(), nullable=False),
|
||||
sa.Column('permission_id', sa.UUID(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['permission_id'], ['pillar_tool_permission.id'], ),
|
||||
sa.ForeignKeyConstraint(['role_id'], ['pillar_tool_role.id'], ),
|
||||
sa.PrimaryKeyConstraint('role_id', 'permission_id')
|
||||
)
|
||||
op.create_table('pillar_tool_user_role',
|
||||
sa.Column('user_id', sa.UUID(), nullable=False),
|
||||
sa.Column('role_id', sa.UUID(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['role_id'], ['pillar_tool_role.id'], ),
|
||||
sa.ForeignKeyConstraint(['user_id'], ['pillar_tool_user.id'], ),
|
||||
sa.PrimaryKeyConstraint('user_id', 'role_id')
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('pillar_tool_user_role')
|
||||
op.drop_table('pillar_tool_role_permission')
|
||||
op.drop_table('pillar_tool_user')
|
||||
op.drop_table('pillar_tool_role')
|
||||
op.drop_table('pillar_tool_permission')
|
||||
# ### end Alembic commands ###
|
||||
@ -1,14 +1,32 @@
|
||||
from sqlalchemy import Column, String, UUID
|
||||
from sqlalchemy import Column, String, UUID, ForeignKey
|
||||
|
||||
from pillar_tool.db.database import Base
|
||||
|
||||
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = 'users'
|
||||
__tablename__ = 'pillar_tool_user'
|
||||
id = Column(UUID, primary_key=True)
|
||||
username = Column(String, nullable=False)
|
||||
pw_hash = Column(String, nullable=False)
|
||||
pw_salt = Column(String, nullable=False)
|
||||
|
||||
class Role(Base):
|
||||
__tablename__ = 'pillar_tool_role'
|
||||
id = Column(UUID, primary_key=True)
|
||||
name = Column(String, nullable=False)
|
||||
|
||||
class Permission(Base):
|
||||
__tablename__ = 'pillar_tool_permission'
|
||||
id = Column(UUID, primary_key=True)
|
||||
name = Column(String, nullable=False)
|
||||
|
||||
class RolePermission(Base):
|
||||
__tablename__ = 'pillar_tool_role_permission'
|
||||
role_id = Column(UUID, ForeignKey("pillar_tool_role.id"), primary_key=True)
|
||||
permission_id = Column(UUID, ForeignKey("pillar_tool_permission.id"), primary_key=True)
|
||||
|
||||
class UserRole(Base):
|
||||
__tablename__ = 'pillar_tool_user_role'
|
||||
user_id = Column(UUID, ForeignKey("pillar_tool_user.id"), primary_key=True)
|
||||
role_id = Column(UUID, ForeignKey("pillar_tool_role.id"), primary_key=True)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user