-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
## Summary Fixes #3446 ### Time to review: 10 mins ## Changes proposed Add user saved search model Add DB migration ## Context for reviewers This lays the groundwork for an API to save user searched. ## Additional information Generated table: <img width="1035" alt="Screenshot 2025-01-08 at 11 21 58 AM" src="https://github.com/user-attachments/assets/7d8c9f6c-2d72-4d2e-909e-f40178886837" />
- Loading branch information
1 parent
6f6fd88
commit 061c558
Showing
3 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
api/src/db/migrations/versions/2025_01_08_create_saved_searches_table.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
"""Create saved searches table | ||
Revision ID: cc2912373d5b | ||
Revises: 232a9223ed9b | ||
Create Date: 2025-01-08 16:20:40.898481 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "cc2912373d5b" | ||
down_revision = "232a9223ed9b" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"user_saved_search", | ||
sa.Column("saved_search_id", sa.UUID(), nullable=False), | ||
sa.Column("user_id", sa.UUID(), nullable=False), | ||
sa.Column("search_query", postgresql.JSONB(astext_type=sa.Text()), nullable=False), | ||
sa.Column("name", sa.Text(), nullable=False), | ||
sa.Column( | ||
"created_at", | ||
sa.TIMESTAMP(timezone=True), | ||
server_default=sa.text("now()"), | ||
nullable=False, | ||
), | ||
sa.Column( | ||
"updated_at", | ||
sa.TIMESTAMP(timezone=True), | ||
server_default=sa.text("now()"), | ||
nullable=False, | ||
), | ||
sa.ForeignKeyConstraint( | ||
["user_id"], ["api.user.user_id"], name=op.f("user_saved_search_user_id_user_fkey") | ||
), | ||
sa.PrimaryKeyConstraint("saved_search_id", name=op.f("user_saved_search_pkey")), | ||
schema="api", | ||
) | ||
op.create_index( | ||
op.f("user_saved_search_user_id_idx"), | ||
"user_saved_search", | ||
["user_id"], | ||
unique=False, | ||
schema="api", | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_index( | ||
op.f("user_saved_search_user_id_idx"), table_name="user_saved_search", schema="api" | ||
) | ||
op.drop_table("user_saved_search", schema="api") | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.