mirror of
https://github.com/aquatix/digimarks.git
synced 2025-12-07 06:05:10 +01:00
Fix migration to actually rename sqlite columns
This commit is contained in:
@@ -48,6 +48,7 @@ def run_migrations_offline() -> None:
|
|||||||
target_metadata=target_metadata,
|
target_metadata=target_metadata,
|
||||||
literal_binds=True,
|
literal_binds=True,
|
||||||
dialect_opts={'paramstyle': 'named'},
|
dialect_opts={'paramstyle': 'named'},
|
||||||
|
render_as_batch=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
with context.begin_transaction():
|
with context.begin_transaction():
|
||||||
@@ -55,7 +56,11 @@ def run_migrations_offline() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def do_run_migrations(connection: Connection) -> None:
|
def do_run_migrations(connection: Connection) -> None:
|
||||||
context.configure(connection=connection, target_metadata=target_metadata)
|
context.configure(
|
||||||
|
connection=connection,
|
||||||
|
target_metadata=target_metadata,
|
||||||
|
render_as_batch=True,
|
||||||
|
)
|
||||||
|
|
||||||
with context.begin_transaction():
|
with context.begin_transaction():
|
||||||
context.run_migrations()
|
context.run_migrations()
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Revision ID: b8cbc6957df5
|
Revision ID: b8cbc6957df5
|
||||||
Revises: a8d8e45f60a1
|
Revises: a8d8e45f60a1
|
||||||
Create Date: 2025-09-12 20:05:03.507816
|
Create Date: 2025-09-12 22:26:38.684120
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from typing import Sequence, Union
|
from typing import Sequence, Union
|
||||||
@@ -22,38 +22,46 @@ depends_on: Union[str, Sequence[str], None] = None
|
|||||||
def upgrade() -> None:
|
def upgrade() -> None:
|
||||||
"""Upgrade schema."""
|
"""Upgrade schema."""
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
op.add_column('bookmark', sa.Column('user_key', sqlmodel.sql.sqltypes.AutoString(), nullable=False))
|
with op.batch_alter_table('bookmark', schema=None) as batch_op:
|
||||||
op.drop_constraint(op.f('bookmark_user'), 'bookmark', type_='foreignkey')
|
batch_op.drop_constraint(batch_op.f('bookmark_user'), type_='foreignkey')
|
||||||
op.create_foreign_key(None, 'bookmark', 'user', ['user_key'], ['key'])
|
#batch_op.add_column(sa.Column('user_key', sqlmodel.sql.sqltypes.AutoString(), nullable=False))
|
||||||
op.drop_column('bookmark', 'userkey')
|
#batch_op.alter_column(sa.Column('userkey'), new_column_name='user_key')
|
||||||
op.add_column('publictag', sa.Column('tag_key', sqlmodel.sql.sqltypes.AutoString(), nullable=False))
|
batch_op.alter_column('userkey', new_column_name='user_key')
|
||||||
op.add_column('publictag', sa.Column('user_key', sqlmodel.sql.sqltypes.AutoString(), nullable=False))
|
batch_op.create_foreign_key('bookmark_user', 'user', ['user_key'], ['key'])
|
||||||
op.alter_column('publictag', 'created_date',
|
#batch_op.drop_column('userkey')
|
||||||
existing_type=sa.DATETIME(),
|
|
||||||
nullable=False,
|
with op.batch_alter_table('publictag', schema=None) as batch_op:
|
||||||
existing_server_default=sa.text('(null)'))
|
#batch_op.add_column(sa.Column('tag_key', sqlmodel.sql.sqltypes.AutoString(), nullable=False))
|
||||||
op.drop_constraint(op.f('publictag_user'), 'publictag', type_='foreignkey')
|
#batch_op.add_column(sa.Column('user_key', sqlmodel.sql.sqltypes.AutoString(), nullable=False))
|
||||||
op.create_foreign_key(None, 'publictag', 'user', ['user_key'], ['key'])
|
batch_op.drop_constraint(batch_op.f('publictag_user'), type_='foreignkey')
|
||||||
op.drop_column('publictag', 'tagkey')
|
batch_op.alter_column('userkey', new_column_name='user_key')
|
||||||
op.drop_column('publictag', 'userkey')
|
batch_op.alter_column('tagkey', new_column_name='tag_key')
|
||||||
|
batch_op.create_foreign_key('publictag_user', 'user', ['user_key'], ['key'])
|
||||||
|
#batch_op.drop_column('tagkey')
|
||||||
|
#batch_op.drop_column('userkey')
|
||||||
|
|
||||||
# ### end Alembic commands ###
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
def downgrade() -> None:
|
||||||
"""Downgrade schema."""
|
"""Downgrade schema."""
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
op.add_column('publictag', sa.Column('userkey', sa.VARCHAR(length=255), nullable=False))
|
with op.batch_alter_table('publictag', schema=None) as batch_op:
|
||||||
op.add_column('publictag', sa.Column('tagkey', sa.VARCHAR(length=255), nullable=False))
|
batch_op.add_column(sa.Column('userkey', sa.VARCHAR(length=255), nullable=False))
|
||||||
op.drop_constraint(None, 'publictag', type_='foreignkey')
|
batch_op.add_column(sa.Column('tagkey', sa.VARCHAR(length=255), nullable=False))
|
||||||
op.create_foreign_key(op.f('publictag_user'), 'publictag', 'user', ['userkey'], ['key'])
|
batch_op.drop_constraint(None, type_='foreignkey')
|
||||||
op.alter_column('publictag', 'created_date',
|
batch_op.create_foreign_key(batch_op.f('publictag_user'), 'user', ['userkey'], ['key'])
|
||||||
|
batch_op.alter_column('created_date',
|
||||||
existing_type=sa.DATETIME(),
|
existing_type=sa.DATETIME(),
|
||||||
nullable=True,
|
nullable=True,
|
||||||
existing_server_default=sa.text('(null)'))
|
existing_server_default=sa.text('(null)'))
|
||||||
op.drop_column('publictag', 'user_key')
|
batch_op.drop_column('user_key')
|
||||||
op.drop_column('publictag', 'tag_key')
|
batch_op.drop_column('tag_key')
|
||||||
op.add_column('bookmark', sa.Column('userkey', sa.VARCHAR(length=255), nullable=False))
|
|
||||||
op.drop_constraint(None, 'bookmark', type_='foreignkey')
|
with op.batch_alter_table('bookmark', schema=None) as batch_op:
|
||||||
op.create_foreign_key(op.f('bookmark_user'), 'bookmark', 'user', ['userkey'], ['key'])
|
batch_op.add_column(sa.Column('userkey', sa.VARCHAR(length=255), nullable=False))
|
||||||
op.drop_column('bookmark', 'user_key')
|
batch_op.drop_constraint(None, type_='foreignkey')
|
||||||
|
batch_op.create_foreign_key(batch_op.f('bookmark_user'), 'user', ['userkey'], ['key'])
|
||||||
|
batch_op.drop_column('user_key')
|
||||||
|
|
||||||
# ### end Alembic commands ###
|
# ### end Alembic commands ###
|
||||||
|
|||||||
@@ -285,8 +285,8 @@ async def delete_bookmark(
|
|||||||
raise HTTPException(status_code=404, detail='Bookmark not found')
|
raise HTTPException(status_code=404, detail='Bookmark not found')
|
||||||
bookmark.deleted_date = datetime.now(UTC)
|
bookmark.deleted_date = datetime.now(UTC)
|
||||||
bookmark.status = Visibility.DELETED
|
bookmark.status = Visibility.DELETED
|
||||||
session.add(bookmark)
|
await session.add(bookmark)
|
||||||
session.commit()
|
await session.commit()
|
||||||
return {'ok': True}
|
return {'ok': True}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -72,12 +72,12 @@ class Bookmark(SQLModel, table=True):
|
|||||||
__tablename__ = 'bookmark'
|
__tablename__ = 'bookmark'
|
||||||
|
|
||||||
id: int = Field(primary_key=True)
|
id: int = Field(primary_key=True)
|
||||||
user_key: str = Field(foreign_key='user.key')
|
user_key: str = Field(foreign_key='user.key', nullable=False)
|
||||||
title: str = Field(default='')
|
title: str = Field(default='', nullable=False)
|
||||||
url: AnyUrl = Field(default='', sa_type=build_custom_type(AnyUrl))
|
url: AnyUrl = Field(default='', sa_type=build_custom_type(AnyUrl))
|
||||||
note: str = Field(default='', nullable=True)
|
note: str = Field(default='', nullable=True)
|
||||||
# image: str = Field(default='')
|
# image: str = Field(default='')
|
||||||
url_hash: str = Field(default='')
|
url_hash: str = Field(default='', nullable=False)
|
||||||
tags: str = Field(default='')
|
tags: str = Field(default='')
|
||||||
starred: bool = Field(default=False)
|
starred: bool = Field(default=False)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user