Skip to content

Commit

Permalink
Add unique constraint in flexdata table
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrondel committed Sep 16, 2024
1 parent d2fcde9 commit 8f45734
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@

def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint("fk_exposure_id", "ccdexposure", schema="cdb_latiss", type_="foreignkey")
op.drop_constraint("fk_obs_id", "exposure_flexdata", schema="cdb_latiss", type_="foreignkey")
op.drop_constraint("un_exposure_id_detector", "ccdexposure", schema="cdb_latiss", type_="unique")
op.drop_constraint("un_day_obs_seq_num", "exposure", schema="cdb_latiss", type_="unique")
op.add_column(
"ccdexposure",
sa.Column(
Expand All @@ -41,7 +45,6 @@ def upgrade() -> None:
),
schema="cdb_latiss",
)
op.drop_constraint("un_exposure_id_detector", "ccdexposure", schema="cdb_latiss", type_="unique")
op.create_unique_constraint(
"un_ccdexposure_ccdexposure_id", "ccdexposure", ["ccdexposure_id"], schema="cdb_latiss"
)
Expand All @@ -51,17 +54,6 @@ def upgrade() -> None:
["day_obs", "seq_num", "detector"],
schema="cdb_latiss",
)
op.drop_constraint("fk_exposure_id", "ccdexposure", schema="cdb_latiss", type_="foreignkey")
op.create_foreign_key(
"fk_ccdexposure_day_obs_seq_num",
"ccdexposure",
"exposure",
["day_obs", "seq_num"],
["day_obs", "seq_num"],
source_schema="cdb_latiss",
referent_schema="cdb_latiss",
)
op.drop_constraint("un_day_obs_seq_num", "exposure", schema="cdb_latiss", type_="unique")
op.create_unique_constraint(
"un_exposure_day_obs_seq_num", "exposure", ["day_obs", "seq_num"], schema="cdb_latiss"
)
Expand All @@ -86,7 +78,6 @@ def upgrade() -> None:
),
schema="cdb_latiss",
)
op.drop_constraint("fk_obs_id", "exposure_flexdata", schema="cdb_latiss", type_="foreignkey")
op.create_foreign_key(
"fk_exposure_flexdata_day_obs_seq_num",
"exposure_flexdata",
Expand Down Expand Up @@ -135,6 +126,15 @@ def upgrade() -> None:
source_schema="cdb_latiss",
referent_schema="cdb_latiss",
)
op.create_foreign_key(
"fk_ccdexposure_day_obs_seq_num",
"ccdexposure",
"exposure",
["day_obs", "seq_num"],
["day_obs", "seq_num"],
source_schema="cdb_latiss",
referent_schema="cdb_latiss",
)
# ### end Alembic commands ###

# Added by hand: copy day_obs and seq_num into the ccdexposure,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""add unique constraint for day obs seq num key
Revision ID: 56077b746de8
Revises: 53707815663e
Create Date: 2024-09-16 17:31:22.643951+00:00
"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision: str = "56077b746de8"
down_revision: Union[str, None] = "53707815663e"
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_exposure_flexdata_day_obs_seq_num_key",
"exposure_flexdata",
["day_obs", "seq_num", "key"],
schema="cdb_latiss",
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(
"un_exposure_flexdata_day_obs_seq_num_key", "exposure_flexdata", schema="cdb_latiss", type_="unique"
)
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""add unique constraint for day obs seq num key
Revision ID: 67319407b5fc
Revises: bf7ed261cc12
Create Date: 2024-09-16 17:31:24.124147+00:00
"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision: str = "67319407b5fc"
down_revision: Union[str, None] = "bf7ed261cc12"
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_exposure_flexdata_day_obs_seq_num_key",
"exposure_flexdata",
["day_obs", "seq_num", "key"],
schema="cdb_lsstcomcam",
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(
"un_exposure_flexdata_day_obs_seq_num_key",
"exposure_flexdata",
schema="cdb_lsstcomcam",
type_="unique",
)
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@

def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint("fk_obs_id", "exposure_flexdata", schema="cdb_lsstcomcam", type_="foreignkey")
op.drop_constraint("fk_exposure_id", "ccdexposure", schema="cdb_lsstcomcam", type_="foreignkey")
op.drop_constraint("un_exposure_id_detector", "ccdexposure", schema="cdb_lsstcomcam", type_="unique")
op.drop_constraint("un_day_obs_seq_num", "exposure", schema="cdb_lsstcomcam", type_="unique")
op.create_unique_constraint(
"un_ccdexposure_ccdexposure_id", "ccdexposure", ["ccdexposure_id"], schema="cdb_lsstcomcam"
)
op.add_column(
"ccdexposure",
sa.Column(
Expand All @@ -41,26 +48,12 @@ def upgrade() -> None:
),
schema="cdb_lsstcomcam",
)
op.drop_constraint("un_exposure_id_detector", "ccdexposure", schema="cdb_lsstcomcam", type_="unique")
op.create_unique_constraint(
"un_ccdexposure_ccdexposure_id", "ccdexposure", ["ccdexposure_id"], schema="cdb_lsstcomcam"
)
op.create_unique_constraint(
"un_ccdexposure_day_obs_seq_num_detector",
"ccdexposure",
["day_obs", "seq_num", "detector"],
schema="cdb_lsstcomcam",
)
op.drop_constraint("fk_exposure_id", "ccdexposure", schema="cdb_lsstcomcam", type_="foreignkey")
op.create_foreign_key(
"fk_ccdexposure_day_obs_seq_num",
"ccdexposure",
"exposure",
["day_obs", "seq_num"],
["day_obs", "seq_num"],
source_schema="cdb_lsstcomcam",
referent_schema="cdb_lsstcomcam",
)
op.add_column(
"ccdvisit1_quicklook",
sa.Column(
Expand All @@ -71,7 +64,6 @@ def upgrade() -> None:
),
schema="cdb_lsstcomcam",
)
op.drop_constraint("un_day_obs_seq_num", "exposure", schema="cdb_lsstcomcam", type_="unique")
op.create_unique_constraint(
"un_exposure_day_obs_seq_num", "exposure", ["day_obs", "seq_num"], schema="cdb_lsstcomcam"
)
Expand All @@ -98,7 +90,6 @@ def upgrade() -> None:
),
schema="cdb_lsstcomcam",
)
op.drop_constraint("fk_obs_id", "exposure_flexdata", schema="cdb_lsstcomcam", type_="foreignkey")
op.create_foreign_key(
"fk_exposure_flexdata_day_obs_seq_num",
"exposure_flexdata",
Expand Down Expand Up @@ -167,6 +158,15 @@ def upgrade() -> None:
source_schema="cdb_lsstcomcam",
referent_schema="cdb_lsstcomcam",
)
op.create_foreign_key(
"fk_ccdexposure_day_obs_seq_num",
"ccdexposure",
"exposure",
["day_obs", "seq_num"],
["day_obs", "seq_num"],
source_schema="cdb_lsstcomcam",
referent_schema="cdb_lsstcomcam",
)
# ### end Alembic commands ###

# Added by hand: copy day_obs and seq_num into the ccdexposure,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""add unique constraint for day obs seq num key
Revision ID: 02f64409522c
Revises: 5f50b32c44fc
Create Date: 2024-09-16 17:31:25.545455+00:00
"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision: str = "02f64409522c"
down_revision: Union[str, None] = "5f50b32c44fc"
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_exposure_flexdata_day_obs_seq_num_key",
"exposure_flexdata",
["day_obs", "seq_num", "key"],
schema="cdb_lsstcomcamsim",
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(
"un_exposure_flexdata_day_obs_seq_num_key",
"exposure_flexdata",
schema="cdb_lsstcomcamsim",
type_="unique",
)
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ def upgrade() -> None:
),
schema="cdb_lsstcomcamsim",
)
op.drop_constraint("fk_obs_id", "exposure_flexdata", schema="cdb_lsstcomcamsim", type_="foreignkey")
op.drop_constraint("fk_exposure_id", "ccdexposure", schema="cdb_lsstcomcamsim", type_="foreignkey")
op.drop_constraint("un_exposure_id_detector", "ccdexposure", schema="cdb_lsstcomcamsim", type_="unique")
op.drop_constraint("un_day_obs_seq_num", "exposure", schema="cdb_lsstcomcamsim", type_="unique")
op.create_unique_constraint(
"un_ccdexposure_ccdexposure_id", "ccdexposure", ["ccdexposure_id"], schema="cdb_lsstcomcamsim"
)
Expand All @@ -51,16 +54,6 @@ def upgrade() -> None:
["day_obs", "seq_num", "detector"],
schema="cdb_lsstcomcamsim",
)
op.drop_constraint("fk_exposure_id", "ccdexposure", schema="cdb_lsstcomcamsim", type_="foreignkey")
op.create_foreign_key(
"fk_ccdexposure_day_obs_seq_num",
"ccdexposure",
"exposure",
["day_obs", "seq_num"],
["day_obs", "seq_num"],
source_schema="cdb_lsstcomcamsim",
referent_schema="cdb_lsstcomcamsim",
)
op.add_column(
"ccdvisit1_quicklook",
sa.Column(
Expand All @@ -71,7 +64,6 @@ def upgrade() -> None:
),
schema="cdb_lsstcomcamsim",
)
op.drop_constraint("un_day_obs_seq_num", "exposure", schema="cdb_lsstcomcamsim", type_="unique")
op.create_unique_constraint(
"un_exposure_day_obs_seq_num", "exposure", ["day_obs", "seq_num"], schema="cdb_lsstcomcamsim"
)
Expand All @@ -98,7 +90,6 @@ def upgrade() -> None:
),
schema="cdb_lsstcomcamsim",
)
op.drop_constraint("fk_obs_id", "exposure_flexdata", schema="cdb_lsstcomcamsim", type_="foreignkey")
op.create_foreign_key(
"fk_exposure_flexdata_day_obs_seq_num",
"exposure_flexdata",
Expand Down Expand Up @@ -167,6 +158,15 @@ def upgrade() -> None:
source_schema="cdb_lsstcomcamsim",
referent_schema="cdb_lsstcomcamsim",
)
op.create_foreign_key(
"fk_ccdexposure_day_obs_seq_num",
"ccdexposure",
"exposure",
["day_obs", "seq_num"],
["day_obs", "seq_num"],
source_schema="cdb_lsstcomcamsim",
referent_schema="cdb_lsstcomcamsim",
)
# ### end Alembic commands ###

# Added by hand: copy day_obs and seq_num into the ccdexposure,
Expand Down

0 comments on commit 8f45734

Please sign in to comment.