45 lines
1.8 KiB
Python
45 lines
1.8 KiB
Python
"""add audit_events table
|
|
|
|
Revision ID: 875841fac207
|
|
Revises: 2572be7fb7fc
|
|
Create Date: 2018-09-13 15:34:18.815205
|
|
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy.dialects import postgresql
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = '875841fac207'
|
|
down_revision = '359caaf8c5f1'
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.create_table('audit_events',
|
|
sa.Column('time_created', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
|
|
sa.Column('time_updated', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
|
|
sa.Column('id', postgresql.UUID(as_uuid=True), server_default=sa.text('uuid_generate_v4()'), nullable=False),
|
|
sa.Column('user_id', postgresql.UUID(as_uuid=True), nullable=True),
|
|
sa.Column('resource_name', sa.String(), nullable=False),
|
|
sa.Column('resource_id', postgresql.UUID(as_uuid=True), nullable=False),
|
|
sa.Column('action', sa.String(), nullable=False),
|
|
sa.Column('workspace_id', postgresql.UUID(as_uuid=True), nullable=True),
|
|
sa.ForeignKeyConstraint(['user_id'], ['users.id']),
|
|
sa.ForeignKeyConstraint(['workspace_id'], ['workspaces.id']),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_audit_events_resource_id'), 'audit_events', ['resource_id'], unique=False)
|
|
op.create_index(op.f('ix_audit_events_user_id'), 'audit_events', ['user_id'], unique=False)
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
def downgrade():
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.drop_index(op.f('ix_audit_events_user_id'), table_name='audit_events')
|
|
op.drop_index(op.f('ix_audit_events_resource_id'), table_name='audit_events')
|
|
op.drop_table('audit_events')
|
|
# ### end Alembic commands ###
|