Skip to content

Commit

Permalink
Format code using black
Browse files Browse the repository at this point in the history
  • Loading branch information
cary-rowen committed Mar 2, 2025
1 parent b748ee3 commit 0b40c2d
Show file tree
Hide file tree
Showing 37 changed files with 433 additions and 295 deletions.
14 changes: 8 additions & 6 deletions alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
from bookworm.database import *



# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config

# Interpret the config file for Python logging.
# This line sets up loggers basically.
if config.config_file_name is not None and config.attributes.get('configure_logger', True):
if config.config_file_name is not None and config.attributes.get(
"configure_logger", True
):
fileConfig(config.config_file_name, disable_existing_loggers=False)

# add your model's MetaData object here
Expand All @@ -34,13 +35,13 @@

writer = rewriter.Rewriter()


@writer.rewrites(ops.MigrationScript)
def add_imports(context, revision, op):
op.imports.add("import bookworm")
return [op]



def run_migrations_offline() -> None:
"""Run migrations in 'offline' mode.
Expand Down Expand Up @@ -73,11 +74,12 @@ def run_migrations_online() -> None:
"""
connectable = create_engine(config.get_main_option("sqlalchemy.url"))

with connectable.connect() as connection:
context.configure(
connection=connection, target_metadata=target_metadata,
process_revision_directives=writer
connection=connection,
target_metadata=target_metadata,
process_revision_directives=writer,
)

with context.begin_transaction():
Expand Down
276 changes: 168 additions & 108 deletions alembic/versions/28099038d8d6_initial_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,142 +5,202 @@
Create Date: 2024-09-23 00:10:33.591108
"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
import bookworm

# revision identifiers, used by Alembic.
revision: str = '28099038d8d6'
revision: str = "28099038d8d6"
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('book',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('title', sa.String(length=512), nullable=False),
sa.Column('uri', bookworm.database.models.DocumentUriDBType(length=1024), nullable=False),
sa.PrimaryKeyConstraint('id')
op.create_table(
"book",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("title", sa.String(length=512), nullable=False),
sa.Column(
"uri",
bookworm.database.models.DocumentUriDBType(length=1024),
nullable=False,
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(op.f("ix_book_uri"), "book", ["uri"], unique=True)
op.create_table(
"document_position_info",
sa.Column("last_page", sa.Integer(), nullable=True),
sa.Column("last_position", sa.Integer(), nullable=True),
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("title", sa.String(length=512), nullable=False),
sa.Column(
"uri",
bookworm.database.models.DocumentUriDBType(length=1024),
nullable=False,
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_document_position_info_uri"),
"document_position_info",
["uri"],
unique=True,
)
op.create_index(op.f('ix_book_uri'), 'book', ['uri'], unique=True)
op.create_table('document_position_info',
sa.Column('last_page', sa.Integer(), nullable=True),
sa.Column('last_position', sa.Integer(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('title', sa.String(length=512), nullable=False),
sa.Column('uri', bookworm.database.models.DocumentUriDBType(length=1024), nullable=False),
sa.PrimaryKeyConstraint('id')
op.create_table(
"note_tag",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("title", sa.String(length=512), nullable=False),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(op.f('ix_document_position_info_uri'), 'document_position_info', ['uri'], unique=True)
op.create_table('note_tag',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('title', sa.String(length=512), nullable=False),
sa.PrimaryKeyConstraint('id')
op.create_index(op.f("ix_note_tag_title"), "note_tag", ["title"], unique=True)
op.create_table(
"pinned_document",
sa.Column("last_opened_on", sa.DateTime(), nullable=True),
sa.Column("is_pinned", sa.Boolean(), nullable=True),
sa.Column("pinning_order", sa.Integer(), nullable=True),
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("title", sa.String(length=512), nullable=False),
sa.Column(
"uri",
bookworm.database.models.DocumentUriDBType(length=1024),
nullable=False,
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(op.f('ix_note_tag_title'), 'note_tag', ['title'], unique=True)
op.create_table('pinned_document',
sa.Column('last_opened_on', sa.DateTime(), nullable=True),
sa.Column('is_pinned', sa.Boolean(), nullable=True),
sa.Column('pinning_order', sa.Integer(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('title', sa.String(length=512), nullable=False),
sa.Column('uri', bookworm.database.models.DocumentUriDBType(length=1024), nullable=False),
sa.PrimaryKeyConstraint('id')
op.create_index(
op.f("ix_pinned_document_uri"), "pinned_document", ["uri"], unique=True
)
op.create_index(op.f('ix_pinned_document_uri'), 'pinned_document', ['uri'], unique=True)
op.create_table('quote_tag',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('title', sa.String(length=512), nullable=False),
sa.PrimaryKeyConstraint('id')
op.create_table(
"quote_tag",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("title", sa.String(length=512), nullable=False),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(op.f('ix_quote_tag_title'), 'quote_tag', ['title'], unique=True)
op.create_table('recent_document',
sa.Column('last_opened_on', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('title', sa.String(length=512), nullable=False),
sa.Column('uri', bookworm.database.models.DocumentUriDBType(length=1024), nullable=False),
sa.PrimaryKeyConstraint('id')
op.create_index(op.f("ix_quote_tag_title"), "quote_tag", ["title"], unique=True)
op.create_table(
"recent_document",
sa.Column("last_opened_on", sa.DateTime(), nullable=True),
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("title", sa.String(length=512), nullable=False),
sa.Column(
"uri",
bookworm.database.models.DocumentUriDBType(length=1024),
nullable=False,
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(op.f('ix_recent_document_uri'), 'recent_document', ['uri'], unique=True)
op.create_table('bookmark',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('title', sa.String(length=255), nullable=False),
sa.Column('page_number', sa.Integer(), nullable=False),
sa.Column('position', sa.Integer(), nullable=False),
sa.Column('section_title', sa.String(length=1024), nullable=False),
sa.Column('section_identifier', sa.String(length=1024), nullable=False),
sa.Column('date_created', sa.DateTime(), nullable=True),
sa.Column('date_updated', sa.DateTime(), nullable=True),
sa.Column('book_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['book_id'], ['book.id'], ),
sa.PrimaryKeyConstraint('id')
op.create_index(
op.f("ix_recent_document_uri"), "recent_document", ["uri"], unique=True
)
op.create_table('note',
sa.Column('content', sa.Text(), nullable=False),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('title', sa.String(length=255), nullable=False),
sa.Column('page_number', sa.Integer(), nullable=False),
sa.Column('position', sa.Integer(), nullable=False),
sa.Column('section_title', sa.String(length=1024), nullable=False),
sa.Column('section_identifier', sa.String(length=1024), nullable=False),
sa.Column('date_created', sa.DateTime(), nullable=True),
sa.Column('date_updated', sa.DateTime(), nullable=True),
sa.Column('book_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['book_id'], ['book.id'], ),
sa.PrimaryKeyConstraint('id')
op.create_table(
"bookmark",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("title", sa.String(length=255), nullable=False),
sa.Column("page_number", sa.Integer(), nullable=False),
sa.Column("position", sa.Integer(), nullable=False),
sa.Column("section_title", sa.String(length=1024), nullable=False),
sa.Column("section_identifier", sa.String(length=1024), nullable=False),
sa.Column("date_created", sa.DateTime(), nullable=True),
sa.Column("date_updated", sa.DateTime(), nullable=True),
sa.Column("book_id", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(
["book_id"],
["book.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_table('quote',
sa.Column('start_pos', sa.Integer(), nullable=False),
sa.Column('end_pos', sa.Integer(), nullable=False),
sa.Column('content', sa.Text(), nullable=False),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('title', sa.String(length=255), nullable=False),
sa.Column('page_number', sa.Integer(), nullable=False),
sa.Column('position', sa.Integer(), nullable=False),
sa.Column('section_title', sa.String(length=1024), nullable=False),
sa.Column('section_identifier', sa.String(length=1024), nullable=False),
sa.Column('date_created', sa.DateTime(), nullable=True),
sa.Column('date_updated', sa.DateTime(), nullable=True),
sa.Column('book_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['book_id'], ['book.id'], ),
sa.PrimaryKeyConstraint('id')
op.create_table(
"note",
sa.Column("content", sa.Text(), nullable=False),
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("title", sa.String(length=255), nullable=False),
sa.Column("page_number", sa.Integer(), nullable=False),
sa.Column("position", sa.Integer(), nullable=False),
sa.Column("section_title", sa.String(length=1024), nullable=False),
sa.Column("section_identifier", sa.String(length=1024), nullable=False),
sa.Column("date_created", sa.DateTime(), nullable=True),
sa.Column("date_updated", sa.DateTime(), nullable=True),
sa.Column("book_id", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(
["book_id"],
["book.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_table('notes_tags',
sa.Column('note_id', sa.Integer(), nullable=True),
sa.Column('note_tag_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['note_id'], ['note.id'], ),
sa.ForeignKeyConstraint(['note_tag_id'], ['note_tag.id'], )
op.create_table(
"quote",
sa.Column("start_pos", sa.Integer(), nullable=False),
sa.Column("end_pos", sa.Integer(), nullable=False),
sa.Column("content", sa.Text(), nullable=False),
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("title", sa.String(length=255), nullable=False),
sa.Column("page_number", sa.Integer(), nullable=False),
sa.Column("position", sa.Integer(), nullable=False),
sa.Column("section_title", sa.String(length=1024), nullable=False),
sa.Column("section_identifier", sa.String(length=1024), nullable=False),
sa.Column("date_created", sa.DateTime(), nullable=True),
sa.Column("date_updated", sa.DateTime(), nullable=True),
sa.Column("book_id", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(
["book_id"],
["book.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_table('quotes_tags',
sa.Column('quote_id', sa.Integer(), nullable=True),
sa.Column('quote_tag_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['quote_id'], ['quote.id'], ),
sa.ForeignKeyConstraint(['quote_tag_id'], ['quote_tag.id'], )
op.create_table(
"notes_tags",
sa.Column("note_id", sa.Integer(), nullable=True),
sa.Column("note_tag_id", sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(
["note_id"],
["note.id"],
),
sa.ForeignKeyConstraint(
["note_tag_id"],
["note_tag.id"],
),
)
op.create_table(
"quotes_tags",
sa.Column("quote_id", sa.Integer(), nullable=True),
sa.Column("quote_tag_id", sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(
["quote_id"],
["quote.id"],
),
sa.ForeignKeyConstraint(
["quote_tag_id"],
["quote_tag.id"],
),
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('quotes_tags')
op.drop_table('notes_tags')
op.drop_table('quote')
op.drop_table('note')
op.drop_table('bookmark')
op.drop_index(op.f('ix_recent_document_uri'), table_name='recent_document')
op.drop_table('recent_document')
op.drop_index(op.f('ix_quote_tag_title'), table_name='quote_tag')
op.drop_table('quote_tag')
op.drop_index(op.f('ix_pinned_document_uri'), table_name='pinned_document')
op.drop_table('pinned_document')
op.drop_index(op.f('ix_note_tag_title'), table_name='note_tag')
op.drop_table('note_tag')
op.drop_index(op.f('ix_document_position_info_uri'), table_name='document_position_info')
op.drop_table('document_position_info')
op.drop_index(op.f('ix_book_uri'), table_name='book')
op.drop_table('book')
op.drop_table("quotes_tags")
op.drop_table("notes_tags")
op.drop_table("quote")
op.drop_table("note")
op.drop_table("bookmark")
op.drop_index(op.f("ix_recent_document_uri"), table_name="recent_document")
op.drop_table("recent_document")
op.drop_index(op.f("ix_quote_tag_title"), table_name="quote_tag")
op.drop_table("quote_tag")
op.drop_index(op.f("ix_pinned_document_uri"), table_name="pinned_document")
op.drop_table("pinned_document")
op.drop_index(op.f("ix_note_tag_title"), table_name="note_tag")
op.drop_table("note_tag")
op.drop_index(
op.f("ix_document_position_info_uri"), table_name="document_position_info"
)
op.drop_table("document_position_info")
op.drop_index(op.f("ix_book_uri"), table_name="book")
op.drop_table("book")
# ### end Alembic commands ###
13 changes: 7 additions & 6 deletions alembic/versions/35f453946f1e_added_start_and_end_pos_to_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,29 @@
Create Date: 2024-12-01 11:46:44.985313
"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
import bookworm

# revision identifiers, used by Alembic.
revision: str = '35f453946f1e'
down_revision: Union[str, None] = '85028f013e6d'
revision: str = "35f453946f1e"
down_revision: Union[str, None] = "85028f013e6d"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('note', sa.Column('start_pos', sa.Integer(), nullable=True))
op.add_column('note', sa.Column('end_pos', sa.Integer(), nullable=True))
op.add_column("note", sa.Column("start_pos", sa.Integer(), nullable=True))
op.add_column("note", sa.Column("end_pos", sa.Integer(), nullable=True))
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('note', 'end_pos')
op.drop_column('note', 'start_pos')
op.drop_column("note", "end_pos")
op.drop_column("note", "start_pos")
# ### end Alembic commands ###
Loading

0 comments on commit 0b40c2d

Please sign in to comment.