feat: project consistency
This commit is contained in:
parent
7804816a1a
commit
cb70f17ad5
16 changed files with 572 additions and 219 deletions
97
alembic/versions/2026-04-06_initial_database_model.py
Normal file
97
alembic/versions/2026-04-06_initial_database_model.py
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
"""initial database model
|
||||
|
||||
Revision ID: 8fe51426321d
|
||||
Revises:
|
||||
Create Date: 2026-04-06 12:36:46.877760
|
||||
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "8fe51426321d"
|
||||
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(
|
||||
"contact",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("email", sa.String(), nullable=True),
|
||||
sa.Column("first_name", sa.String(), nullable=True),
|
||||
sa.Column("last_name", sa.String(), nullable=True),
|
||||
sa.Column("phonenumber", sa.String(), nullable=True),
|
||||
sa.Column("vat_number", sa.String(), nullable=True),
|
||||
sa.Column("street_address", sa.String(), nullable=True),
|
||||
sa.Column("street_address_line_2", sa.String(), nullable=True),
|
||||
sa.Column("post_office_box_number", sa.String(), nullable=True),
|
||||
sa.Column("locality", sa.String(), nullable=True),
|
||||
sa.Column("country_code", sa.String(), nullable=True),
|
||||
sa.Column("address_region", sa.String(), nullable=True),
|
||||
sa.Column("postal_code", sa.String(), nullable=True),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_table(
|
||||
"user",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("email", sa.String(), nullable=True),
|
||||
sa.Column("first_name", sa.String(), nullable=True),
|
||||
sa.Column("last_name", sa.String(), nullable=True),
|
||||
sa.Column("oidc_id", sa.String(), nullable=True),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_index(op.f("ix_user_oidc_id"), "user", ["oidc_id"], unique=True)
|
||||
op.create_table(
|
||||
"organisation",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("name", sa.String(), nullable=True),
|
||||
sa.Column("status", sa.String(), nullable=True),
|
||||
sa.Column("intake_questionnaire", sa.JSON(), nullable=True),
|
||||
sa.Column("billing_contact_id", sa.Integer(), nullable=True),
|
||||
sa.Column("security_contact_id", sa.Integer(), nullable=True),
|
||||
sa.Column("owner_contact_id", sa.Integer(), nullable=True),
|
||||
sa.ForeignKeyConstraint(
|
||||
["billing_contact_id"],
|
||||
["contact.id"],
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["owner_contact_id"],
|
||||
["contact.id"],
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["security_contact_id"],
|
||||
["contact.id"],
|
||||
),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_table(
|
||||
"orgusers",
|
||||
sa.Column("org_id", sa.Integer(), nullable=False),
|
||||
sa.Column("user_id", sa.Integer(), nullable=False),
|
||||
sa.Column(
|
||||
"is_admin", sa.Boolean(), server_default=sa.text("false"), nullable=False
|
||||
),
|
||||
sa.ForeignKeyConstraint(["org_id"], ["organisation.id"], ondelete="CASCADE"),
|
||||
sa.ForeignKeyConstraint(["user_id"], ["user.id"], ondelete="CASCADE"),
|
||||
sa.PrimaryKeyConstraint("org_id", "user_id"),
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table("orgusers")
|
||||
op.drop_table("organisation")
|
||||
op.drop_index(op.f("ix_user_oidc_id"), table_name="user")
|
||||
op.drop_table("user")
|
||||
op.drop_table("contact")
|
||||
# ### end Alembic commands ###
|
||||
100
alembic/versions/2026-05-22_init_iam.py
Normal file
100
alembic/versions/2026-05-22_init_iam.py
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
"""Init IAM
|
||||
|
||||
Revision ID: a147965e644e
|
||||
Revises: 8fe51426321d
|
||||
Create Date: 2026-05-22 15:59:36.469374
|
||||
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "a147965e644e"
|
||||
down_revision: Union[str, Sequence[str], None] = "8fe51426321d"
|
||||
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(
|
||||
"service",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("name", sa.String(), nullable=True),
|
||||
sa.Column("api_key", sa.String(), nullable=True),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("api_key"),
|
||||
sa.UniqueConstraint("name"),
|
||||
)
|
||||
op.create_table(
|
||||
"permission",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("resource", sa.String(), nullable=False),
|
||||
sa.Column("action", sa.String(), nullable=False),
|
||||
sa.Column("service_id", sa.Integer(), nullable=True),
|
||||
sa.ForeignKeyConstraint(["service_id"], ["service.id"], ondelete="CASCADE"),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_table(
|
||||
"group",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("name", sa.String(), nullable=False),
|
||||
sa.Column("org_id", sa.Integer(), nullable=True),
|
||||
sa.ForeignKeyConstraint(["org_id"], ["organisation.id"], ondelete="CASCADE"),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("name"),
|
||||
)
|
||||
op.create_table(
|
||||
"group_permissions",
|
||||
sa.Column("group_id", sa.Integer(), nullable=False),
|
||||
sa.Column("permission_id", sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(["group_id"], ["group.id"], ondelete="CASCADE"),
|
||||
sa.ForeignKeyConstraint(["permission_id"], ["permission.id"], ondelete="CASCADE"),
|
||||
sa.PrimaryKeyConstraint("group_id", "permission_id"),
|
||||
)
|
||||
op.create_table(
|
||||
"user_groups",
|
||||
sa.Column("org_id", sa.Integer(), nullable=False),
|
||||
sa.Column("user_id", sa.Integer(), nullable=False),
|
||||
sa.Column("group_id", sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(["group_id"], ["group.id"], ondelete="CASCADE"),
|
||||
sa.ForeignKeyConstraint(["org_id"], ["organisation.id"], ondelete="CASCADE"),
|
||||
sa.ForeignKeyConstraint(["user_id"], ["user.id"], ondelete="CASCADE"),
|
||||
sa.PrimaryKeyConstraint("org_id", "user_id", "group_id"),
|
||||
)
|
||||
op.add_column("organisation", sa.Column("root_user_id", sa.Integer(), nullable=True))
|
||||
op.create_unique_constraint("organisation_name_key", "organisation", ["name"])
|
||||
op.create_foreign_key(
|
||||
"organisation_root_user_fkey", "organisation", "user", ["root_user_id"], ["id"]
|
||||
)
|
||||
op.drop_column("orgusers", "is_admin")
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column(
|
||||
"orgusers",
|
||||
sa.Column(
|
||||
"is_admin",
|
||||
sa.BOOLEAN(),
|
||||
server_default=sa.text("false"),
|
||||
autoincrement=False,
|
||||
nullable=False,
|
||||
),
|
||||
)
|
||||
op.drop_constraint("organisation_root_user_fkey", "organisation", type_="foreignkey")
|
||||
op.drop_constraint("organisation_name_key", "organisation", type_="unique")
|
||||
op.drop_column("organisation", "root_user_id")
|
||||
op.drop_table("user_groups")
|
||||
op.drop_table("group_permissions")
|
||||
op.drop_table("group")
|
||||
op.drop_table("permission")
|
||||
op.drop_table("service")
|
||||
# ### end Alembic commands ###
|
||||
37
alembic/versions/2026-05-25_contact_model_changes.py
Normal file
37
alembic/versions/2026-05-25_contact_model_changes.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
"""Contact model changes
|
||||
|
||||
Revision ID: 8132c4b88665
|
||||
Revises: a147965e644e
|
||||
Create Date: 2026-05-25 13:09:22.635058
|
||||
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "8132c4b88665"
|
||||
down_revision: Union[str, Sequence[str], None] = "a147965e644e"
|
||||
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.add_column("contact", sa.Column("org_id", sa.Integer(), nullable=False))
|
||||
op.create_foreign_key(
|
||||
None, "contact", "organisation", ["org_id"], ["id"], ondelete="CASCADE"
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint(None, "contact", type_="foreignkey")
|
||||
op.drop_column("contact", "org_id")
|
||||
# ### end Alembic commands ###
|
||||
45
alembic/versions/2026-05-29_drop_user_groups_org_column.py
Normal file
45
alembic/versions/2026-05-29_drop_user_groups_org_column.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
"""Drop user_groups org column
|
||||
|
||||
Revision ID: d9dc6986fe38
|
||||
Revises: 8132c4b88665
|
||||
Create Date: 2026-05-29 16:10:00.320982
|
||||
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "d9dc6986fe38"
|
||||
down_revision: Union[str, Sequence[str], None] = "8132c4b88665"
|
||||
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.drop_constraint(op.f("user_groups_org_id_fkey"), "user_groups", type_="foreignkey")
|
||||
op.drop_column("user_groups", "org_id")
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column(
|
||||
"user_groups",
|
||||
sa.Column("org_id", sa.INTEGER(), autoincrement=False, nullable=False),
|
||||
)
|
||||
op.create_foreign_key(
|
||||
op.f("user_groups_org_id_fkey"),
|
||||
"user_groups",
|
||||
"organisation",
|
||||
["org_id"],
|
||||
["id"],
|
||||
ondelete="CASCADE",
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
37
alembic/versions/2026-06-08_fix_permission_unique.py
Normal file
37
alembic/versions/2026-06-08_fix_permission_unique.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
"""fix permission unique
|
||||
|
||||
Revision ID: b6c8614ef799
|
||||
Revises: d9dc6986fe38
|
||||
Create Date: 2026-06-08 16:00:27.533099
|
||||
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "b6c8614ef799"
|
||||
down_revision: Union[str, Sequence[str], None] = "d9dc6986fe38"
|
||||
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_unique_constraint(
|
||||
"uniq_permission_resource_and_action",
|
||||
"permission",
|
||||
["service_id", "resource", "action"],
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint("uniq_permission_resource_and_action", "permission", type_="unique")
|
||||
# ### end Alembic commands ###
|
||||
37
alembic/versions/2026-06-15_group_name_unique_per_org.py
Normal file
37
alembic/versions/2026-06-15_group_name_unique_per_org.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
"""group name unique per org
|
||||
|
||||
Revision ID: 98e20aae555c
|
||||
Revises: b6c8614ef799
|
||||
Create Date: 2026-06-15 11:05:16.673658
|
||||
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "98e20aae555c"
|
||||
down_revision: Union[str, Sequence[str], None] = "b6c8614ef799"
|
||||
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.drop_constraint(op.f("group_name_key"), "group", type_="unique")
|
||||
op.create_unique_constraint("uniq_group_name_org_id", "group", ["name", "org_id"])
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint("uniq_group_name_org_id", "group", type_="unique")
|
||||
op.create_unique_constraint(
|
||||
op.f("group_name_key"), "group", ["name"], postgresql_nulls_not_distinct=False
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
40
alembic/versions/2026-06-16_org_perm_perms_join_table.py
Normal file
40
alembic/versions/2026-06-16_org_perm_perms_join_table.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
"""org perm perms join table
|
||||
|
||||
Revision ID: 85edbf9a176c
|
||||
Revises: 98e20aae555c
|
||||
Create Date: 2026-06-16 13:31:57.427953
|
||||
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "85edbf9a176c"
|
||||
down_revision: Union[str, Sequence[str], None] = "98e20aae555c"
|
||||
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(
|
||||
"org_permissions",
|
||||
sa.Column("org_id", sa.Integer(), nullable=False),
|
||||
sa.Column("permission_id", sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(["org_id"], ["organisation.id"], ondelete="CASCADE"),
|
||||
sa.ForeignKeyConstraint(["permission_id"], ["permission.id"], ondelete="CASCADE"),
|
||||
sa.PrimaryKeyConstraint("org_id", "permission_id"),
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table("org_permissions")
|
||||
# ### end Alembic commands ###
|
||||
Loading…
Add table
Add a link
Reference in a new issue