Skip to content

Commit

Permalink
Merge pull request #43 from lsst-dm/tickets/DM-46073-hotfix
Browse files Browse the repository at this point in the history
Add foreign keys and unique constraint
  • Loading branch information
bbrondel authored Oct 2, 2024
2 parents a12d58e + eedb020 commit 8cd8957
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""Add foreign keys and unique constraint for exposure.exposure_id
Revision ID: e9fd2cdb9c12
Revises: 56077b746de8
Create Date: 2024-09-25 21:37:20.956716+00:00
"""

from typing import Sequence, Union

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "e9fd2cdb9c12"
down_revision: Union[str, None] = "56077b746de8"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_unique_constraint(
"un_ccdexposure_exposure_id_detector", "ccdexposure", ["exposure_id", "detector"], schema="cdb_latiss"
)
op.create_foreign_key(
"fk_ccdexposure_exposure_id",
"ccdexposure",
"exposure",
["exposure_id"],
["exposure_id"],
source_schema="cdb_latiss",
referent_schema="cdb_latiss",
)
op.create_foreign_key(
"fk_exposure_flexdata_obs_id",
"exposure_flexdata",
"exposure",
["obs_id"],
["exposure_id"],
source_schema="cdb_latiss",
referent_schema="cdb_latiss",
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(
"fk_exposure_flexdata_obs_id", "exposure_flexdata", schema="cdb_latiss", type_="foreignkey"
)
op.drop_constraint("fk_ccdexposure_exposure_id", "ccdexposure", schema="cdb_latiss", type_="foreignkey")
op.drop_constraint(
"un_ccdexposure_exposure_id_detector", "ccdexposure", schema="cdb_latiss", type_="unique"
)
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""Add foreign keys and unique constraint for exposure.exposure_id
Revision ID: 0490d793fc1a
Revises: 67319407b5fc
Create Date: 2024-09-25 21:37:22.445341+00:00
"""

from typing import Sequence, Union

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "0490d793fc1a"
down_revision: Union[str, None] = "67319407b5fc"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_unique_constraint(
"un_ccdexposure_exposure_id_detector",
"ccdexposure",
["exposure_id", "detector"],
schema="cdb_lsstcomcam",
)
op.create_foreign_key(
"fk_ccdexposure_exposure_id",
"ccdexposure",
"exposure",
["exposure_id"],
["exposure_id"],
source_schema="cdb_lsstcomcam",
referent_schema="cdb_lsstcomcam",
)
op.create_foreign_key(
"fk_exposure_flexdata_obs_id",
"exposure_flexdata",
"exposure",
["obs_id"],
["exposure_id"],
source_schema="cdb_lsstcomcam",
referent_schema="cdb_lsstcomcam",
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(
"fk_exposure_flexdata_obs_id", "exposure_flexdata", schema="cdb_lsstcomcam", type_="foreignkey"
)
op.drop_constraint(
"fk_ccdexposure_exposure_id", "ccdexposure", schema="cdb_lsstcomcam", type_="foreignkey"
)
op.drop_constraint(
"un_ccdexposure_exposure_id_detector", "ccdexposure", schema="cdb_lsstcomcam", type_="unique"
)
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""Add foreign keys and unique constraint for exposure.exposure_id
Revision ID: cff7da7ec8ed
Revises: 02f64409522c
Create Date: 2024-09-25 21:37:23.993294+00:00
"""

from typing import Sequence, Union

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "cff7da7ec8ed"
down_revision: Union[str, None] = "02f64409522c"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_unique_constraint(
"un_ccdexposure_exposure_id_detector",
"ccdexposure",
["exposure_id", "detector"],
schema="cdb_lsstcomcamsim",
)
op.create_foreign_key(
"fk_ccdexposure_exposure_id",
"ccdexposure",
"exposure",
["exposure_id"],
["exposure_id"],
source_schema="cdb_lsstcomcamsim",
referent_schema="cdb_lsstcomcamsim",
)
op.create_foreign_key(
"fk_exposure_flexdata_obs_id",
"exposure_flexdata",
"exposure",
["obs_id"],
["exposure_id"],
source_schema="cdb_lsstcomcamsim",
referent_schema="cdb_lsstcomcamsim",
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(
"fk_exposure_flexdata_obs_id", "exposure_flexdata", schema="cdb_lsstcomcamsim", type_="foreignkey"
)
op.drop_constraint(
"fk_ccdexposure_exposure_id", "ccdexposure", schema="cdb_lsstcomcamsim", type_="foreignkey"
)
op.drop_constraint(
"un_ccdexposure_exposure_id_detector", "ccdexposure", schema="cdb_lsstcomcamsim", type_="unique"
)
# ### end Alembic commands ###

0 comments on commit 8cd8957

Please sign in to comment.