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

Align Postgres tables/indexes/constraints with Django #1697

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Generated by Django 4.1.11 on 2023-10-04 15:34

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
('zarr', '0002_remove_zarruploadfile_zarr_archive_and_more'),
]

# This renaming is necessary as there is a mismatch between what Django thinks the name of
# database indexes/constraints are, and what they actually are.
operations = [
# Tables
migrations.AlterModelTable(name='zarrarchive', table=None),
migrations.AlterModelTable(name='embargoedzarrarchive', table=None),
# Sequences
migrations.RunSQL(
'ALTER SEQUENCE api_zarrarchive_id_seq RENAME to zarr_zarrarchive_id_seq;'
),
migrations.RunSQL(
'ALTER SEQUENCE api_embargoedzarrarchive_id_seq RENAME to '
'zarr_embargoedzarrarchive_id_seq;'
),
# zarr_id unique constraint
migrations.RunSQL(
'ALTER TABLE zarr_zarrarchive RENAME CONSTRAINT "api_zarrarchive_zarr_id_key" to '
'"zarr_zarrarchive_zarr_id_key";'
),
migrations.RunSQL(
'ALTER TABLE zarr_embargoedzarrarchive RENAME CONSTRAINT '
'"api_embargoedzarrarchive_zarr_id_key" to "zarr_embargoedzarrarchive_zarr_id_key";'
),
# primary key index
migrations.RunSQL('ALTER INDEX "api_zarrarchive_pkey" RENAME TO "zarr_zarrarchive_pkey";'),
migrations.RunSQL(
'ALTER INDEX "api_embargoedzarrarchive_pkey" RENAME TO '
'"zarr_embargoedzarrarchive_pkey";'
),
# dandiset_id index
migrations.RunSQL(
'ALTER INDEX "api_zarrarchive_dandiset_id_68510762" RENAME TO '
'"zarr_zarrarchive_dandiset_id_2fdb93be";'
),
migrations.RunSQL(
'ALTER INDEX "api_embargoedzarrarchive_dandiset_id_b61f0a08" RENAME TO '
'"zarr_embargoedzarrarchive_dandiset_id_9a6f3365";'
),
# dandiset_id foreign key constraint
migrations.RunSQL(
'ALTER TABLE zarr_zarrarchive RENAME CONSTRAINT '
'"api_zarrarchive_dandiset_id_68510762_fk" TO '
danlamanna marked this conversation as resolved.
Show resolved Hide resolved
'"zarr_zarrarchive_dandiset_id_2fdb93be_fk";'
),
migrations.RunSQL(
'ALTER TABLE zarr_embargoedzarrarchive RENAME CONSTRAINT '
'"api_embargoedzarrarchive_dandiset_id_b61f0a08_fk" TO '
'"zarr_embargoedzarrarchive_dandiset_id_9a6f3365_fk";'
),
# Constraints defined in Django
migrations.RunSQL(
'ALTER TABLE zarr_zarrarchive RENAME CONSTRAINT '
'"api-zarrarchive-consistent-checksum-status" TO '
'"zarr-zarrarchive-consistent-checksum-status";'
),
migrations.RunSQL(
'ALTER TABLE zarr_zarrarchive RENAME CONSTRAINT "api-zarrarchive-unique-name" TO '
'"zarr-zarrarchive-unique-name";'
),
migrations.RunSQL(
'ALTER TABLE zarr_embargoedzarrarchive RENAME CONSTRAINT '
'"api-embargoedzarrarchive-consistent-checksum-status" TO '
'"zarr-embargoedzarrarchive-consistent-checksum-status";'
),
migrations.RunSQL(
'ALTER TABLE zarr_embargoedzarrarchive RENAME CONSTRAINT '
'"api-embargoedzarrarchive-unique-name" TO "zarr-embargoedzarrarchive-unique-name";'
),
]
6 changes: 0 additions & 6 deletions dandiapi/zarr/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ def delete_files(self, paths: list[str]):


class ZarrArchive(BaseZarrArchive):
class Meta(BaseZarrArchive.Meta):
db_table = 'api_zarrarchive'

storage = get_storage()
dandiset = models.ForeignKey(Dandiset, related_name='zarr_archives', on_delete=models.CASCADE)

Expand All @@ -105,9 +102,6 @@ def s3_path(self, zarr_path: str | Path):


class EmbargoedZarrArchive(BaseZarrArchive):
class Meta(BaseZarrArchive.Meta):
db_table = 'api_embargoedzarrarchive'

storage = get_embargo_storage()
dandiset = models.ForeignKey(
Dandiset, related_name='embargoed_zarr_archives', on_delete=models.CASCADE
Expand Down