From 16c56f9b44ec65627af38dbec928e7e352a1f45b Mon Sep 17 00:00:00 2001 From: Mads Bisgaard Date: Thu, 25 Apr 2024 16:03:21 +0200 Subject: [PATCH 1/3] add indices to postgress tables --- .../src/simcore_postgres_database/models/file_meta_data.py | 6 ++++-- .../src/simcore_postgres_database/models/projects.py | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/postgres-database/src/simcore_postgres_database/models/file_meta_data.py b/packages/postgres-database/src/simcore_postgres_database/models/file_meta_data.py index e2f09746923..9ece039863f 100644 --- a/packages/postgres-database/src/simcore_postgres_database/models/file_meta_data.py +++ b/packages/postgres-database/src/simcore_postgres_database/models/file_meta_data.py @@ -9,9 +9,9 @@ sa.Column("location", sa.String()), sa.Column("bucket_name", sa.String()), sa.Column("object_name", sa.String()), - sa.Column("project_id", sa.String()), + sa.Column("project_id", sa.String(), index=True), sa.Column("node_id", sa.String()), - sa.Column("user_id", sa.String()), + sa.Column("user_id", sa.String(), index=True), sa.Column("file_id", sa.String(), primary_key=True), sa.Column("created_at", sa.String()), sa.Column("last_modified", sa.String()), @@ -46,6 +46,7 @@ nullable=False, server_default=sa.text("false"), doc="Set True when file_id is a directory", + index=True, ), sa.Column( "sha256_checksum", @@ -53,5 +54,6 @@ nullable=True, server_default=sa.null(), doc="SHA256 checksum of the file content", + index=True, ), ) diff --git a/packages/postgres-database/src/simcore_postgres_database/models/projects.py b/packages/postgres-database/src/simcore_postgres_database/models/projects.py index 31292b14540..a280ac9e622 100644 --- a/packages/postgres-database/src/simcore_postgres_database/models/projects.py +++ b/packages/postgres-database/src/simcore_postgres_database/models/projects.py @@ -69,6 +69,7 @@ class ProjectType(enum.Enum): ), nullable=True, doc="Project's owner", + index=True, ), sa.Column( "creation_date", From ccaf1bf4d9f63cb1c3c12b41d4ed28ace4499456 Mon Sep 17 00:00:00 2001 From: Mads Bisgaard Date: Fri, 26 Apr 2024 09:55:40 +0200 Subject: [PATCH 2/3] dont index sha256 --- .../src/simcore_postgres_database/models/file_meta_data.py | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/postgres-database/src/simcore_postgres_database/models/file_meta_data.py b/packages/postgres-database/src/simcore_postgres_database/models/file_meta_data.py index 9ece039863f..9bb6eb654d7 100644 --- a/packages/postgres-database/src/simcore_postgres_database/models/file_meta_data.py +++ b/packages/postgres-database/src/simcore_postgres_database/models/file_meta_data.py @@ -54,6 +54,5 @@ nullable=True, server_default=sa.null(), doc="SHA256 checksum of the file content", - index=True, ), ) From 5b5cf0e1b12729270a4c7416280d1d2d86db8a2d Mon Sep 17 00:00:00 2001 From: Mads Bisgaard Date: Fri, 26 Apr 2024 10:13:02 +0200 Subject: [PATCH 3/3] add migration script --- ...7ef8_add_indices_to_file_meta_data_and_.py | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 packages/postgres-database/src/simcore_postgres_database/migration/versions/b13ca15c7ef8_add_indices_to_file_meta_data_and_.py diff --git a/packages/postgres-database/src/simcore_postgres_database/migration/versions/b13ca15c7ef8_add_indices_to_file_meta_data_and_.py b/packages/postgres-database/src/simcore_postgres_database/migration/versions/b13ca15c7ef8_add_indices_to_file_meta_data_and_.py new file mode 100644 index 00000000000..72d02792ab2 --- /dev/null +++ b/packages/postgres-database/src/simcore_postgres_database/migration/versions/b13ca15c7ef8_add_indices_to_file_meta_data_and_.py @@ -0,0 +1,46 @@ +"""add indices to file_meta_data and projects tables + +Revision ID: b13ca15c7ef8 +Revises: 0ed9f6eabeba +Create Date: 2024-04-26 08:11:52.163445+00:00 + +""" +from alembic import op + +# revision identifiers, used by Alembic. +revision = "b13ca15c7ef8" +down_revision = "0ed9f6eabeba" +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_index( + op.f("ix_file_meta_data_is_directory"), + "file_meta_data", + ["is_directory"], + unique=False, + ) + op.create_index( + op.f("ix_file_meta_data_project_id"), + "file_meta_data", + ["project_id"], + unique=False, + ) + op.create_index( + op.f("ix_file_meta_data_user_id"), "file_meta_data", ["user_id"], unique=False + ) + op.create_index( + op.f("ix_projects_prj_owner"), "projects", ["prj_owner"], unique=False + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f("ix_projects_prj_owner"), table_name="projects") + op.drop_index(op.f("ix_file_meta_data_user_id"), table_name="file_meta_data") + op.drop_index(op.f("ix_file_meta_data_project_id"), table_name="file_meta_data") + op.drop_index(op.f("ix_file_meta_data_is_directory"), table_name="file_meta_data") + # ### end Alembic commands ###