mirror of
https://github.com/aquatix/digimarks.git
synced 2025-12-06 22:05:09 +01:00
Renamed key properties
This commit is contained in:
59
migrations/versions/b8cbc6957df5_renamed_keys.py
Normal file
59
migrations/versions/b8cbc6957df5_renamed_keys.py
Normal file
@@ -0,0 +1,59 @@
|
||||
"""Renamed keys
|
||||
|
||||
Revision ID: b8cbc6957df5
|
||||
Revises: a8d8e45f60a1
|
||||
Create Date: 2025-09-12 20:05:03.507816
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
import sqlmodel
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'b8cbc6957df5'
|
||||
down_revision: Union[str, Sequence[str], None] = 'a8d8e45f60a1'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('bookmark', sa.Column('user_key', sqlmodel.sql.sqltypes.AutoString(), nullable=False))
|
||||
op.drop_constraint(op.f('bookmark_user'), 'bookmark', type_='foreignkey')
|
||||
op.create_foreign_key(None, 'bookmark', 'user', ['user_key'], ['key'])
|
||||
op.drop_column('bookmark', 'userkey')
|
||||
op.add_column('publictag', sa.Column('tag_key', sqlmodel.sql.sqltypes.AutoString(), nullable=False))
|
||||
op.add_column('publictag', sa.Column('user_key', sqlmodel.sql.sqltypes.AutoString(), nullable=False))
|
||||
op.alter_column('publictag', 'created_date',
|
||||
existing_type=sa.DATETIME(),
|
||||
nullable=False,
|
||||
existing_server_default=sa.text('(null)'))
|
||||
op.drop_constraint(op.f('publictag_user'), 'publictag', type_='foreignkey')
|
||||
op.create_foreign_key(None, 'publictag', 'user', ['user_key'], ['key'])
|
||||
op.drop_column('publictag', 'tagkey')
|
||||
op.drop_column('publictag', 'userkey')
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('publictag', sa.Column('userkey', sa.VARCHAR(length=255), nullable=False))
|
||||
op.add_column('publictag', sa.Column('tagkey', sa.VARCHAR(length=255), nullable=False))
|
||||
op.drop_constraint(None, 'publictag', type_='foreignkey')
|
||||
op.create_foreign_key(op.f('publictag_user'), 'publictag', 'user', ['userkey'], ['key'])
|
||||
op.alter_column('publictag', 'created_date',
|
||||
existing_type=sa.DATETIME(),
|
||||
nullable=True,
|
||||
existing_server_default=sa.text('(null)'))
|
||||
op.drop_column('publictag', 'user_key')
|
||||
op.drop_column('publictag', 'tag_key')
|
||||
op.add_column('bookmark', sa.Column('userkey', sa.VARCHAR(length=255), nullable=False))
|
||||
op.drop_constraint(None, 'bookmark', type_='foreignkey')
|
||||
op.create_foreign_key(op.f('bookmark_user'), 'bookmark', 'user', ['userkey'], ['key'])
|
||||
op.drop_column('bookmark', 'user_key')
|
||||
# ### end Alembic commands ###
|
||||
@@ -162,7 +162,7 @@ async def list_bookmarks(
|
||||
"""List all bookmarks in the database. By default 100 items are returned."""
|
||||
result = await session.exec(
|
||||
select(Bookmark)
|
||||
.where(Bookmark.userkey == user_key, Bookmark.status != Visibility.DELETED)
|
||||
.where(Bookmark.user_key == user_key, Bookmark.status != Visibility.DELETED)
|
||||
.offset(offset)
|
||||
.limit(limit)
|
||||
)
|
||||
@@ -179,7 +179,7 @@ async def get_bookmark(
|
||||
"""Show bookmark details."""
|
||||
result = await session.exec(
|
||||
select(Bookmark).where(
|
||||
Bookmark.userkey == user_key, Bookmark.url_hash == url_hash, Bookmark.status != Visibility.DELETED
|
||||
Bookmark.user_key == user_key, Bookmark.url_hash == url_hash, Bookmark.status != Visibility.DELETED
|
||||
)
|
||||
)
|
||||
bookmark = result.first()
|
||||
@@ -196,7 +196,7 @@ async def autocomplete_bookmark(
|
||||
strip_params: bool = False,
|
||||
):
|
||||
"""Autofill some fields for this (new) bookmark for user `user_key`."""
|
||||
bookmark.userkey = user_key
|
||||
bookmark.user_key = user_key
|
||||
|
||||
# Auto-fill title, fix tags etc.
|
||||
bookmarks_helpers.update_bookmark_with_info(bookmark, request, strip_params)
|
||||
@@ -204,7 +204,7 @@ async def autocomplete_bookmark(
|
||||
url_hash = utils.generate_hash(str(bookmark.url))
|
||||
result = await session.exec(
|
||||
select(Bookmark).where(
|
||||
Bookmark.userkey == user_key, Bookmark.url_hash == url_hash, Bookmark.status != Visibility.DELETED
|
||||
Bookmark.user_key == user_key, Bookmark.url_hash == url_hash, Bookmark.status != Visibility.DELETED
|
||||
)
|
||||
)
|
||||
bookmark_db = result.first()
|
||||
@@ -225,7 +225,7 @@ async def add_bookmark(
|
||||
strip_params: bool = False,
|
||||
):
|
||||
"""Add new bookmark for user `user_key`."""
|
||||
bookmark.userkey = user_key
|
||||
bookmark.user_key = user_key
|
||||
|
||||
# Auto-fill title, fix tags etc.
|
||||
bookmarks_helpers.update_bookmark_with_info(bookmark, request, strip_params)
|
||||
@@ -249,7 +249,7 @@ async def update_bookmark(
|
||||
"""Update existing bookmark `bookmark_key` for user `user_key`."""
|
||||
result = await session.exec(
|
||||
select(Bookmark).where(
|
||||
Bookmark.userkey == user_key, Bookmark.url_hash == url_hash, Bookmark.status != Visibility.DELETED
|
||||
Bookmark.user_key == user_key, Bookmark.url_hash == url_hash, Bookmark.status != Visibility.DELETED
|
||||
)
|
||||
)
|
||||
bookmark_db = result.first()
|
||||
@@ -298,13 +298,13 @@ async def bookmarks_changed_since(
|
||||
"""Last update on server, so the (browser) client knows whether to fetch an update."""
|
||||
result = await session.exec(
|
||||
select(Bookmark)
|
||||
.where(Bookmark.userkey == user_key, Bookmark.status != Visibility.DELETED)
|
||||
.where(Bookmark.user_key == user_key, Bookmark.status != Visibility.DELETED)
|
||||
.order_by(desc(Bookmark.modified_date))
|
||||
)
|
||||
latest_modified_bookmark = result.first()
|
||||
result = await session.exec(
|
||||
select(Bookmark)
|
||||
.where(Bookmark.userkey == user_key, Bookmark.status != Visibility.DELETED)
|
||||
.where(Bookmark.user_key == user_key, Bookmark.status != Visibility.DELETED)
|
||||
.order_by(desc(Bookmark.created_date))
|
||||
)
|
||||
latest_created_bookmark = result.first()
|
||||
@@ -326,7 +326,7 @@ async def list_tags_for_user(
|
||||
) -> list[str]:
|
||||
"""List all tags in use by the user."""
|
||||
result = await session.exec(
|
||||
select(Bookmark).where(Bookmark.userkey == user_key, Bookmark.status != Visibility.DELETED)
|
||||
select(Bookmark).where(Bookmark.user_key == user_key, Bookmark.status != Visibility.DELETED)
|
||||
)
|
||||
bookmarks = result.all()
|
||||
tags = []
|
||||
@@ -341,7 +341,7 @@ async def list_tags_for_user(
|
||||
user_key: str,
|
||||
) -> list[str]:
|
||||
"""List all tags in use by the user."""
|
||||
result = await session.exec(select(Bookmark).where(Bookmark.userkey == user_key))
|
||||
result = await session.exec(select(Bookmark).where(Bookmark.user_key == user_key))
|
||||
bookmarks = result.all()
|
||||
return tags_helpers.list_tags_for_bookmarks(bookmarks)
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ class Bookmark(SQLModel, table=True):
|
||||
__tablename__ = 'bookmark'
|
||||
|
||||
id: int = Field(primary_key=True)
|
||||
userkey: str = Field(foreign_key='user.key')
|
||||
user_key: str = Field(foreign_key='user.key')
|
||||
title: str = Field(default='')
|
||||
url: AnyUrl = Field(default='', sa_type=build_custom_type(AnyUrl))
|
||||
note: str = Field(default='', nullable=True)
|
||||
@@ -107,7 +107,7 @@ class PublicTag(SQLModel, table=True):
|
||||
__tablename__ = 'publictag'
|
||||
|
||||
id: int = Field(primary_key=True)
|
||||
tagkey: str
|
||||
userkey: str = Field(foreign_key='user.key')
|
||||
tag_key: str
|
||||
user_key: str = Field(foreign_key='user.key')
|
||||
tag: str
|
||||
created_date: datetime = Field(default=datetime.now(UTC))
|
||||
|
||||
Reference in New Issue
Block a user