update foreign key names; workspace_id -> portfolio_id, project_id -> application_id
This commit is contained in:
parent
0eec42c55b
commit
48954ded11
@ -0,0 +1,34 @@
|
|||||||
|
"""change workspace and project
|
||||||
|
|
||||||
|
Revision ID: acd0c11be93a
|
||||||
|
Revises: 71cbe76c3b87
|
||||||
|
Create Date: 2019-01-11 10:01:07.667126
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.dialects import postgresql
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = 'acd0c11be93a'
|
||||||
|
down_revision = '71cbe76c3b87'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.alter_column('audit_events', "workspace_id", new_column_name="portfolio_id")
|
||||||
|
op.alter_column('environments', "project_id", new_column_name="application_id")
|
||||||
|
op.alter_column('projects', "workspace_id", new_column_name="portfolio_id")
|
||||||
|
op.alter_column('task_orders', "workspace_id", new_column_name="portfolio_id")
|
||||||
|
op.alter_column('workspace_roles', "workspace_id", new_column_name="portfolio_id")
|
||||||
|
op.alter_column('invitations', "workspace_role_id", new_column_name="portfolio_role_id")
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.alter_column('audit_events', "portfolio_id", new_column_name="workspace_id")
|
||||||
|
op.alter_column('environments', "application_id", new_column_name="project_id")
|
||||||
|
op.alter_column('projects', "portfolio_id", new_column_name="workspace_id")
|
||||||
|
op.alter_column('task_orders', "portfolio_id", new_column_name="workspace_id")
|
||||||
|
op.alter_column('workspace_roles', "portfolio_id", new_column_name="workspace_id")
|
||||||
|
op.alter_column('invitations', "portfolio_role_id", new_column_name="workspace_role_id")
|
@ -46,7 +46,7 @@ class Applications(object):
|
|||||||
db.session.query(Application)
|
db.session.query(Application)
|
||||||
.join(Environment)
|
.join(Environment)
|
||||||
.join(EnvironmentRole)
|
.join(EnvironmentRole)
|
||||||
.filter(Application.workspace_id == portfolio.id)
|
.filter(Application.portfolio_id == portfolio.id)
|
||||||
.filter(EnvironmentRole.user_id == user.id)
|
.filter(EnvironmentRole.user_id == user.id)
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
|
@ -46,7 +46,7 @@ class Environments(object):
|
|||||||
.join(EnvironmentRole)
|
.join(EnvironmentRole)
|
||||||
.join(Application)
|
.join(Application)
|
||||||
.filter(EnvironmentRole.user_id == user.id)
|
.filter(EnvironmentRole.user_id == user.id)
|
||||||
.filter(Environment.project_id == application.id)
|
.filter(Environment.application_id == application.id)
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ class PortfolioRoles(object):
|
|||||||
return (
|
return (
|
||||||
db.session.query(PortfolioRole)
|
db.session.query(PortfolioRole)
|
||||||
.join(User)
|
.join(User)
|
||||||
.filter(User.id == user_id, PortfolioRole.workspace_id == portfolio_id)
|
.filter(User.id == user_id, PortfolioRole.portfolio_id == portfolio_id)
|
||||||
.filter(PortfolioRole.status == PortfolioRoleStatus.ACTIVE)
|
.filter(PortfolioRole.status == PortfolioRoleStatus.ACTIVE)
|
||||||
.one()
|
.one()
|
||||||
)
|
)
|
||||||
|
@ -13,7 +13,7 @@ class Application(Base, mixins.TimestampsMixin, mixins.AuditableMixin):
|
|||||||
name = Column(String, nullable=False)
|
name = Column(String, nullable=False)
|
||||||
description = Column(String, nullable=False)
|
description = Column(String, nullable=False)
|
||||||
|
|
||||||
workspace_id = Column(ForeignKey("workspaces.id"), nullable=False)
|
portfolio_id = Column(ForeignKey("workspaces.id"), nullable=False)
|
||||||
portfolio = relationship("Portfolio")
|
portfolio = relationship("Portfolio")
|
||||||
environments = relationship("Environment", back_populates="application")
|
environments = relationship("Environment", back_populates="application")
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ class AuditEvent(Base, TimestampsMixin):
|
|||||||
user_id = Column(UUID(as_uuid=True), ForeignKey("users.id"), index=True)
|
user_id = Column(UUID(as_uuid=True), ForeignKey("users.id"), index=True)
|
||||||
user = relationship("User", backref="audit_events")
|
user = relationship("User", backref="audit_events")
|
||||||
|
|
||||||
workspace_id = Column(UUID(as_uuid=True), ForeignKey("workspaces.id"), index=True)
|
portfolio_id = Column(UUID(as_uuid=True), ForeignKey("workspaces.id"), index=True)
|
||||||
portfolio = relationship("Portfolio", backref="audit_events")
|
portfolio = relationship("Portfolio", backref="audit_events")
|
||||||
|
|
||||||
request_id = Column(UUID(as_uuid=True), ForeignKey("requests.id"), index=True)
|
request_id = Column(UUID(as_uuid=True), ForeignKey("requests.id"), index=True)
|
||||||
|
@ -12,7 +12,7 @@ class Environment(Base, mixins.TimestampsMixin, mixins.AuditableMixin):
|
|||||||
id = Id()
|
id = Id()
|
||||||
name = Column(String, nullable=False)
|
name = Column(String, nullable=False)
|
||||||
|
|
||||||
project_id = Column(ForeignKey("projects.id"), nullable=False)
|
application_id = Column(ForeignKey("projects.id"), nullable=False)
|
||||||
application = relationship("Application")
|
application = relationship("Application")
|
||||||
|
|
||||||
cloud_id = Column(String)
|
cloud_id = Column(String)
|
||||||
@ -34,7 +34,7 @@ class Environment(Base, mixins.TimestampsMixin, mixins.AuditableMixin):
|
|||||||
return self.application.portfolio
|
return self.application.portfolio
|
||||||
|
|
||||||
def auditable_portfolio_id(self):
|
def auditable_portfolio_id(self):
|
||||||
return self.application.workspace_id
|
return self.application.portfolio_id
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<Environment(name='{}', num_users='{}', application='{}', portfolio='{}', id='{}')>".format(
|
return "<Environment(name='{}', num_users='{}', application='{}', portfolio='{}', id='{}')>".format(
|
||||||
|
@ -46,7 +46,7 @@ class EnvironmentRole(Base, mixins.TimestampsMixin, mixins.AuditableMixin):
|
|||||||
"environment": self.environment.displayname,
|
"environment": self.environment.displayname,
|
||||||
"environment_id": str(self.environment_id),
|
"environment_id": str(self.environment_id),
|
||||||
"application": self.environment.application.name,
|
"application": self.environment.application.name,
|
||||||
"application_id": str(self.environment.project_id),
|
"application_id": str(self.environment.application_id),
|
||||||
"portfolio": self.environment.application.portfolio.name,
|
"portfolio": self.environment.application.portfolio.name,
|
||||||
"portfolio_id": str(self.environment.application.portfolio.id),
|
"portfolio_id": str(self.environment.application.portfolio.id),
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ class Invitation(Base, TimestampsMixin, AuditableMixin):
|
|||||||
user_id = Column(UUID(as_uuid=True), ForeignKey("users.id"), index=True)
|
user_id = Column(UUID(as_uuid=True), ForeignKey("users.id"), index=True)
|
||||||
user = relationship("User", backref="invitations", foreign_keys=[user_id])
|
user = relationship("User", backref="invitations", foreign_keys=[user_id])
|
||||||
|
|
||||||
workspace_role_id = Column(
|
portfolio_role_id = Column(
|
||||||
UUID(as_uuid=True), ForeignKey("workspace_roles.id"), index=True
|
UUID(as_uuid=True), ForeignKey("workspace_roles.id"), index=True
|
||||||
)
|
)
|
||||||
portfolio_role = relationship(
|
portfolio_role = relationship(
|
||||||
@ -123,4 +123,4 @@ class Invitation(Base, TimestampsMixin, AuditableMixin):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def portfolio_id(self):
|
def portfolio_id(self):
|
||||||
return self.portfolio_role.workspace_id
|
return self.portfolio_role.portfolio_id
|
||||||
|
@ -13,7 +13,7 @@ class AuditableMixin(object):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def create_audit_event(connection, resource, action):
|
def create_audit_event(connection, resource, action):
|
||||||
user_id = getattr_path(g, "current_user.id")
|
user_id = getattr_path(g, "current_user.id")
|
||||||
portfolio_id = resource.workspace_id
|
portfolio_id = resource.portfolio_id
|
||||||
request_id = resource.request_id
|
request_id = resource.request_id
|
||||||
resource_type = resource.resource_type
|
resource_type = resource.resource_type
|
||||||
display_name = resource.displayname
|
display_name = resource.displayname
|
||||||
@ -23,7 +23,7 @@ class AuditableMixin(object):
|
|||||||
|
|
||||||
audit_event = AuditEvent(
|
audit_event = AuditEvent(
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
workspace_id=portfolio_id,
|
portfolio_id=portfolio_id,
|
||||||
request_id=request_id,
|
request_id=request_id,
|
||||||
resource_type=resource_type,
|
resource_type=resource_type,
|
||||||
resource_id=resource.id,
|
resource_id=resource.id,
|
||||||
@ -88,7 +88,7 @@ class AuditableMixin(object):
|
|||||||
return camel_to_snake(type(self).__name__)
|
return camel_to_snake(type(self).__name__)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def workspace_id(self):
|
def portfolio_id(self):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -34,7 +34,7 @@ class PortfolioRole(Base, mixins.TimestampsMixin, mixins.AuditableMixin):
|
|||||||
__tablename__ = "workspace_roles"
|
__tablename__ = "workspace_roles"
|
||||||
|
|
||||||
id = Id()
|
id = Id()
|
||||||
workspace_id = Column(
|
portfolio_id = Column(
|
||||||
UUID(as_uuid=True), ForeignKey("workspaces.id"), index=True, nullable=False
|
UUID(as_uuid=True), ForeignKey("workspaces.id"), index=True, nullable=False
|
||||||
)
|
)
|
||||||
portfolio = relationship("Portfolio", back_populates="roles")
|
portfolio = relationship("Portfolio", back_populates="roles")
|
||||||
@ -159,6 +159,6 @@ class PortfolioRole(Base, mixins.TimestampsMixin, mixins.AuditableMixin):
|
|||||||
Index(
|
Index(
|
||||||
"portfolio_role_user_portfolio",
|
"portfolio_role_user_portfolio",
|
||||||
PortfolioRole.user_id,
|
PortfolioRole.user_id,
|
||||||
PortfolioRole.workspace_id,
|
PortfolioRole.portfolio_id,
|
||||||
unique=True,
|
unique=True,
|
||||||
)
|
)
|
||||||
|
@ -24,7 +24,7 @@ class TaskOrder(Base, mixins.TimestampsMixin):
|
|||||||
|
|
||||||
id = types.Id()
|
id = types.Id()
|
||||||
|
|
||||||
workspace_id = Column(ForeignKey("workspaces.id"))
|
portfolio_id = Column(ForeignKey("workspaces.id"))
|
||||||
portfolio = relationship("Portfolio")
|
portfolio = relationship("Portfolio")
|
||||||
|
|
||||||
user_id = Column(ForeignKey("users.id"))
|
user_id = Column(ForeignKey("users.id"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user