Remove workspaces.name unique constraint
- Added some random indexes - Fixed audit_events.request_id foreign key constraint
This commit is contained in:
parent
4de0338978
commit
885b2da308
@ -0,0 +1,42 @@
|
|||||||
|
"""remove workspaces.name unique constraint
|
||||||
|
|
||||||
|
Revision ID: 903d7c66ff1d
|
||||||
|
Revises: 7958cca588a1
|
||||||
|
Create Date: 2018-09-26 10:19:13.230064
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.dialects import postgresql
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '903d7c66ff1d'
|
||||||
|
down_revision = '7958cca588a1'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_index(op.f('ix_audit_events_request_id'), 'audit_events', ['request_id'], unique=False)
|
||||||
|
op.create_index(op.f('ix_audit_events_workspace_id'), 'audit_events', ['workspace_id'], unique=False)
|
||||||
|
op.create_foreign_key(None, 'audit_events', 'requests', ['request_id'], ['id'])
|
||||||
|
op.alter_column('request_status_events', 'time_created',
|
||||||
|
existing_type=postgresql.TIMESTAMP(timezone=True),
|
||||||
|
nullable=False,
|
||||||
|
existing_server_default=sa.text('now()'))
|
||||||
|
op.drop_constraint('workspaces_name_key', 'workspaces', type_='unique')
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_unique_constraint('workspaces_name_key', 'workspaces', ['name'])
|
||||||
|
op.alter_column('request_status_events', 'time_created',
|
||||||
|
existing_type=postgresql.TIMESTAMP(timezone=True),
|
||||||
|
nullable=True,
|
||||||
|
existing_server_default=sa.text('now()'))
|
||||||
|
op.drop_constraint(None, 'audit_events', type_='foreignkey')
|
||||||
|
op.drop_index(op.f('ix_audit_events_workspace_id'), table_name='audit_events')
|
||||||
|
op.drop_index(op.f('ix_audit_events_request_id'), table_name='audit_events')
|
||||||
|
# ### end Alembic commands ###
|
@ -17,7 +17,7 @@ class AuditEvent(Base, TimestampsMixin):
|
|||||||
workspace_id = Column(UUID(as_uuid=True), ForeignKey("workspaces.id"), index=True)
|
workspace_id = Column(UUID(as_uuid=True), ForeignKey("workspaces.id"), index=True)
|
||||||
workspace = relationship("Workspace", backref="audit_events")
|
workspace = relationship("Workspace", backref="audit_events")
|
||||||
|
|
||||||
request_id = Column(UUID(as_uuid=True), ForeignKey("request.id"), index=True)
|
request_id = Column(UUID(as_uuid=True), ForeignKey("requests.id"), index=True)
|
||||||
|
|
||||||
resource_type = Column(String(), nullable=False)
|
resource_type = Column(String(), nullable=False)
|
||||||
resource_id = Column(UUID(as_uuid=True), index=True, nullable=False)
|
resource_id = Column(UUID(as_uuid=True), index=True, nullable=False)
|
||||||
|
@ -12,7 +12,7 @@ class Workspace(Base, mixins.TimestampsMixin, mixins.AuditableMixin):
|
|||||||
__tablename__ = "workspaces"
|
__tablename__ = "workspaces"
|
||||||
|
|
||||||
id = Id()
|
id = Id()
|
||||||
name = Column(String, unique=True)
|
name = Column(String)
|
||||||
request_id = Column(ForeignKey("requests.id"), nullable=False)
|
request_id = Column(ForeignKey("requests.id"), nullable=False)
|
||||||
projects = relationship("Project", back_populates="workspace")
|
projects = relationship("Project", back_populates="workspace")
|
||||||
roles = relationship("WorkspaceRole")
|
roles = relationship("WorkspaceRole")
|
||||||
|
@ -250,3 +250,9 @@ def test_get_for_update_information():
|
|||||||
ccpo = UserFactory.from_atat_role("ccpo")
|
ccpo = UserFactory.from_atat_role("ccpo")
|
||||||
with pytest.raises(UnauthorizedError):
|
with pytest.raises(UnauthorizedError):
|
||||||
Workspaces.get_for_update_information(ccpo, workspace.id)
|
Workspaces.get_for_update_information(ccpo, workspace.id)
|
||||||
|
|
||||||
|
|
||||||
|
def test_can_create_workspaces_with_matching_names():
|
||||||
|
workspace_name = "Great Workspace"
|
||||||
|
Workspaces.create(RequestFactory.create(), name=workspace_name)
|
||||||
|
Workspaces.create(RequestFactory.create(), name=workspace_name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user