Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ adding migration of projects_nodes + connect pricing-unit with project_nodes endpoint ( πŸ—ƒοΈ) #4834

Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""project_nodes modification + creation projects_node_to_pricing_unit

Revision ID: 605fc07e068d
Revises: b102946c8134
Create Date: 2023-10-05 12:12:15.250040+00:00

"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "605fc07e068d"
down_revision = "b102946c8134"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###

op.execute("ALTER TABLE projects_nodes DROP CONSTRAINT projects_nodes_pkey")
op.execute(
"ALTER TABLE projects_nodes ADD COLUMN project_node_id SERIAL PRIMARY KEY"
)
op.execute(
"ALTER TABLE projects_nodes ADD CONSTRAINT projects_nodes__node_project UNIQUE (node_id, project_uuid)"
)

op.create_table(
"projects_node_to_pricing_unit",
sa.Column("project_node_id", sa.BigInteger(), nullable=False),
sa.Column("pricing_unit_id", sa.BigInteger(), nullable=False),
sa.Column(
"created",
sa.DateTime(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column(
"modified",
sa.DateTime(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.ForeignKeyConstraint(
["project_node_id"],
["projects_nodes.project_node_id"],
name="fk_projects_nodes__project_node_to_pricing_unit__uuid",
onupdate="CASCADE",
ondelete="CASCADE",
),
sa.UniqueConstraint("project_node_id", "pricing_unit_id"),
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table("projects_node_to_pricing_unit")

op.execute("ALTER TABLE projects_nodes DROP CONSTRAINT projects_nodes_pkey")
op.execute(
"ALTER TABLE projects_nodes DROP CONSTRAINT projects_nodes__node_project"
)
op.execute("ALTER TABLE projects_nodes ADD PRIMARY KEY (node_id, project_uuid)")

# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
""" Groups table

- List of groups in the framework
- Groups have a ID, name and a list of users that belong to the group
"""

import sqlalchemy as sa

from ._common import (
column_created_datetime,
column_modified_datetime,
register_modified_datetime_auto_update_trigger,
)
from .base import metadata
from .projects_nodes import projects_nodes

projects_node_to_pricing_unit = sa.Table(
"projects_node_to_pricing_unit",
metadata,
sa.Column(
"project_node_id",
sa.BigInteger,
sa.ForeignKey(
projects_nodes.c.project_node_id,
onupdate="CASCADE",
ondelete="CASCADE",
name="fk_projects_nodes__project_node_to_pricing_unit__uuid",
),
nullable=False,
doc="The project node unique identifier",
),
sa.Column(
"pricing_unit_id",
sa.BigInteger,
nullable=False,
doc="The pricing unit unique identifier",
),
# TIME STAMPS ----
column_created_datetime(timezone=True),
column_modified_datetime(timezone=True),
sa.UniqueConstraint("project_node_id", "pricing_unit_id"),
)


register_modified_datetime_auto_update_trigger(projects_nodes)
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
projects_nodes = sa.Table(
"projects_nodes",
metadata,
sa.Column(
"project_node_id",
sa.BigInteger,
nullable=False,
autoincrement=True,
primary_key=True,
doc="Project node index",
),
sa.Column(
"project_uuid",
sa.String,
Expand Down Expand Up @@ -48,7 +56,7 @@
# TIME STAMPS ----
column_created_datetime(timezone=True),
column_modified_datetime(timezone=True),
sa.PrimaryKeyConstraint("project_uuid", "node_id"),
sa.UniqueConstraint("project_uuid", "node_id"),
)


Expand Down