Skip to content

Commit

Permalink
style: reorder table and column operations to minimize SQL diff
Browse files Browse the repository at this point in the history
The SQL statements generated by "sqlite3 svs.sqlite .dump" replicate the
database's tables and columns in the order in which they were originally
added.  For the current database schema, that's a hybrid of the order in
which they're defined in securedrop_client.db and subsequent additions
in migrations; in the new database schema, that's strictly their
ordering in securedrop_client.db.  The latter artificially inflates the
diff of comparing "sqlite3 svs.sqlite .dump" for the old and new
schemas.

For ease of review, here we attempt to replicate the current SQL
statements as closely as possible, for as small a diff as possible.
  • Loading branch information
cfm committed Jul 1, 2022
1 parent 03f063a commit 3211967
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions alembic/versions/d7c8af95bc8e_.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,6 @@

def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"deletedconversation",
sa.Column("uuid", sa.String(length=36), nullable=False),
sa.PrimaryKeyConstraint("uuid", name=op.f("pk_deletedconversation")),
)
op.create_table(
"deletedsource",
sa.Column("uuid", sa.String(length=36), nullable=False),
sa.PrimaryKeyConstraint("uuid", name=op.f("pk_deletedsource")),
)
op.create_table(
"downloaderrors",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("name", sa.String(length=36), nullable=False),
sa.PrimaryKeyConstraint("id", name=op.f("pk_downloaderrors")),
sa.UniqueConstraint("name", name=op.f("uq_downloaderrors_name")),
)
op.create_table(
"replysendstatuses",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("name", sa.String(length=36), nullable=False),
sa.PrimaryKeyConstraint("id", name=op.f("pk_replysendstatuses")),
sa.UniqueConstraint("name", name=op.f("uq_replysendstatuses_name")),
)
op.create_table(
"sources",
sa.Column("id", sa.Integer(), nullable=False),
Expand Down Expand Up @@ -71,6 +47,13 @@ def upgrade():
sa.PrimaryKeyConstraint("id", name=op.f("pk_users")),
sa.UniqueConstraint("uuid", name=op.f("uq_users_uuid")),
)
op.create_table(
"replysendstatuses",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("name", sa.String(length=36), nullable=False),
sa.PrimaryKeyConstraint("id", name=op.f("pk_replysendstatuses")),
sa.UniqueConstraint("name", name=op.f("uq_replysendstatuses_name")),
)
op.create_table(
"draftreplies",
sa.Column("id", sa.Integer(), nullable=False),
Expand All @@ -81,6 +64,10 @@ def upgrade():
sa.Column("file_counter", sa.Integer(), nullable=False),
sa.Column("content", sa.Text(), nullable=True),
sa.Column("send_status_id", sa.Integer(), nullable=True),
sa.UniqueConstraint("uuid", name=op.f("uq_draftreplies_uuid")),
sa.ForeignKeyConstraint(
["source_id"], ["sources.id"], name=op.f("fk_draftreplies_source_id_sources")
),
sa.ForeignKeyConstraint(
["journalist_id"], ["users.id"], name=op.f("fk_draftreplies_journalist_id_users")
),
Expand All @@ -89,11 +76,14 @@ def upgrade():
["replysendstatuses.id"],
name=op.f("fk_draftreplies_send_status_id_replysendstatuses"),
),
sa.ForeignKeyConstraint(
["source_id"], ["sources.id"], name=op.f("fk_draftreplies_source_id_sources")
),
sa.PrimaryKeyConstraint("id", name=op.f("pk_draftreplies")),
sa.UniqueConstraint("uuid", name=op.f("uq_draftreplies_uuid")),
)
op.create_table(
"downloaderrors",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("name", sa.String(length=36), nullable=False),
sa.PrimaryKeyConstraint("id", name=op.f("pk_downloaderrors")),
sa.UniqueConstraint("name", name=op.f("uq_downloaderrors_name")),
)
op.create_table(
"files",
Expand Down Expand Up @@ -124,6 +114,9 @@ def upgrade():
),
sa.Column("source_id", sa.Integer(), nullable=False),
sa.Column("last_updated", sa.DateTime(), nullable=False),
sa.PrimaryKeyConstraint("id", name=op.f("pk_files")),
sa.UniqueConstraint("source_id", "file_counter", name="uq_messages_source_id_file_counter"),
sa.UniqueConstraint("uuid", name=op.f("uq_files_uuid")),
sa.ForeignKeyConstraint(
["download_error_id"],
["downloaderrors.id"],
Expand All @@ -132,9 +125,6 @@ def upgrade():
sa.ForeignKeyConstraint(
["source_id"], ["sources.id"], name=op.f("fk_files_source_id_sources")
),
sa.PrimaryKeyConstraint("id", name=op.f("pk_files")),
sa.UniqueConstraint("source_id", "file_counter", name="uq_messages_source_id_file_counter"),
sa.UniqueConstraint("uuid", name=op.f("uq_files_uuid")),
)
op.create_table(
"messages",
Expand Down Expand Up @@ -174,6 +164,9 @@ def upgrade():
),
sa.Column("source_id", sa.Integer(), nullable=False),
sa.Column("last_updated", sa.DateTime(), nullable=False),
sa.PrimaryKeyConstraint("id", name=op.f("pk_messages")),
sa.UniqueConstraint("source_id", "file_counter", name="uq_messages_source_id_file_counter"),
sa.UniqueConstraint("uuid", name=op.f("uq_messages_uuid")),
sa.ForeignKeyConstraint(
["download_error_id"],
["downloaderrors.id"],
Expand All @@ -182,20 +175,15 @@ def upgrade():
sa.ForeignKeyConstraint(
["source_id"], ["sources.id"], name=op.f("fk_messages_source_id_sources")
),
sa.PrimaryKeyConstraint("id", name=op.f("pk_messages")),
sa.UniqueConstraint("source_id", "file_counter", name="uq_messages_source_id_file_counter"),
sa.UniqueConstraint("uuid", name=op.f("uq_messages_uuid")),
)
op.create_table(
"replies",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("uuid", sa.String(length=36), nullable=False),
sa.Column("source_id", sa.Integer(), nullable=False),
sa.Column("journalist_id", sa.Integer(), nullable=True),
sa.Column("filename", sa.String(length=255), nullable=False),
sa.Column("file_counter", sa.Integer(), nullable=False),
sa.Column("size", sa.Integer(), nullable=True),
sa.Column("is_downloaded", sa.Boolean(name="is_downloaded"), nullable=True),
sa.Column(
"content",
sa.Text(),
Expand All @@ -214,7 +202,9 @@ def upgrade():
),
nullable=True,
),
sa.Column("is_downloaded", sa.Boolean(name="is_downloaded"), nullable=True),
sa.Column("download_error_id", sa.Integer(), nullable=True),
sa.Column("journalist_id", sa.Integer(), nullable=True),
sa.Column("last_updated", sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(
["download_error_id"],
Expand Down Expand Up @@ -275,6 +265,16 @@ def upgrade():
sa.PrimaryKeyConstraint("id", name=op.f("pk_seen_replies")),
sa.UniqueConstraint("reply_id", "journalist_id", name=op.f("uq_seen_replies_reply_id")),
)
op.create_table(
"deletedconversation",
sa.Column("uuid", sa.String(length=36), nullable=False),
sa.PrimaryKeyConstraint("uuid", name=op.f("pk_deletedconversation")),
)
op.create_table(
"deletedsource",
sa.Column("uuid", sa.String(length=36), nullable=False),
sa.PrimaryKeyConstraint("uuid", name=op.f("pk_deletedsource")),
)
# ### end Alembic commands ###

# Set enum values:
Expand Down

0 comments on commit 3211967

Please sign in to comment.