diff options
Diffstat (limited to '')
| -rw-r--r-- | migrations/env.py | 36 | ||||
| -rw-r--r-- | migrations/versions/681a2a9a1bc0_.py | 66 | ||||
| -rw-r--r-- | migrations/versions/681a2a9a1bc0_webmention_sender.py | 82 | ||||
| -rw-r--r-- | migrations/versions/be6e229d6a3d_do_not_limit_username_and_password_hash_.py | 52 | ||||
| -rw-r--r-- | migrations/versions/f63641044cc1_initial_database_schema.py | 52 |
5 files changed, 155 insertions, 133 deletions
diff --git a/migrations/env.py b/migrations/env.py index 4c97092..a5d762b 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -1,9 +1,8 @@ import logging from logging.config import fileConfig -from flask import current_app - from alembic import context +from flask import current_app # this is the Alembic Config object, which provides # access to the values within the .ini file in use. @@ -12,32 +11,31 @@ config = context.config # Interpret the config file for Python logging. # This line sets up loggers basically. fileConfig(config.config_file_name) -logger = logging.getLogger('alembic.env') +logger = logging.getLogger("alembic.env") def get_engine(): try: # this works with Flask-SQLAlchemy<3 and Alchemical - return current_app.extensions['migrate'].db.get_engine() - except (TypeError, AttributeError): + return current_app.extensions["migrate"].db.get_engine() + except TypeError, AttributeError: # this works with Flask-SQLAlchemy>=3 - return current_app.extensions['migrate'].db.engine + return current_app.extensions["migrate"].db.engine def get_engine_url(): try: - return get_engine().url.render_as_string(hide_password=False).replace( - '%', '%%') + return get_engine().url.render_as_string(hide_password=False).replace("%", "%%") except AttributeError: - return str(get_engine().url).replace('%', '%%') + return str(get_engine().url).replace("%", "%%") # add your model's MetaData object here # for 'autogenerate' support # from myapp import mymodel # target_metadata = mymodel.Base.metadata -config.set_main_option('sqlalchemy.url', get_engine_url()) -target_db = current_app.extensions['migrate'].db +config.set_main_option("sqlalchemy.url", get_engine_url()) +target_db = current_app.extensions["migrate"].db # other values from the config, defined by the needs of env.py, # can be acquired: @@ -46,7 +44,7 @@ target_db = current_app.extensions['migrate'].db def get_metadata(): - if hasattr(target_db, 'metadatas'): + if hasattr(target_db, "metadatas"): return target_db.metadatas[None] return target_db.metadata @@ -64,9 +62,7 @@ def run_migrations_offline(): """ url = config.get_main_option("sqlalchemy.url") - context.configure( - url=url, target_metadata=get_metadata(), literal_binds=True - ) + context.configure(url=url, target_metadata=get_metadata(), literal_binds=True) with context.begin_transaction(): context.run_migrations() @@ -84,13 +80,13 @@ def run_migrations_online(): # when there are no changes to the schema # reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html def process_revision_directives(context, revision, directives): - if getattr(config.cmd_opts, 'autogenerate', False): + if getattr(config.cmd_opts, "autogenerate", False): script = directives[0] if script.upgrade_ops.is_empty(): directives[:] = [] - logger.info('No changes in schema detected.') + logger.info("No changes in schema detected.") - conf_args = current_app.extensions['migrate'].configure_args + conf_args = current_app.extensions["migrate"].configure_args if conf_args.get("process_revision_directives") is None: conf_args["process_revision_directives"] = process_revision_directives @@ -98,9 +94,7 @@ def run_migrations_online(): with connectable.connect() as connection: context.configure( - connection=connection, - target_metadata=get_metadata(), - **conf_args + connection=connection, target_metadata=get_metadata(), **conf_args ) with context.begin_transaction(): diff --git a/migrations/versions/681a2a9a1bc0_.py b/migrations/versions/681a2a9a1bc0_.py deleted file mode 100644 index 2420b79..0000000 --- a/migrations/versions/681a2a9a1bc0_.py +++ /dev/null @@ -1,66 +0,0 @@ -"""empty message - -Revision ID: 681a2a9a1bc0 -Revises: f63641044cc1 -Create Date: 2026-08-14 13:40:55.149604 - -""" -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '681a2a9a1bc0' -down_revision = 'f63641044cc1' -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.create_table('sources', - sa.Column('uuid', sa.Uuid(), nullable=False), - sa.Column('path', sa.Text(), nullable=False), - sa.Column('url', sa.Text(), nullable=False), - sa.Column('content_hash', sa.String(length=32), nullable=False), - sa.Column('revision', sa.Integer(), nullable=False), - sa.Column('last_seen_at', sa.DateTime(timezone=True), nullable=False), - sa.Column('revised_at', sa.DateTime(timezone=True), nullable=False), - sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), - sa.PrimaryKeyConstraint('uuid'), - sa.UniqueConstraint('path'), - sa.UniqueConstraint('url') - ) - op.create_table('sent_webmentions', - sa.Column('uuid', sa.Uuid(), nullable=False), - sa.Column('source_id', sa.Uuid(), nullable=False), - sa.Column('target', sa.Text(), nullable=False), - sa.Column('active', sa.Boolean(), nullable=False), - sa.Column('desired_revision', sa.Integer(), nullable=False), - sa.Column('processed_revision', sa.Integer(), nullable=True), - sa.Column('sent_revision', sa.Integer(), nullable=True), - sa.Column('status', sa.Enum('sent', 'unsupported', 'failed', name='sent_webmention_status', native_enum=False), nullable=True), - sa.Column('failure_reason', sa.Text(), nullable=True), - sa.Column('endpoint', sa.Text(), nullable=True), - sa.Column('response_status', sa.Integer(), nullable=True), - sa.Column('status_url', sa.Text(), nullable=True), - sa.Column('last_attempted_at', sa.DateTime(timezone=True), nullable=True), - sa.Column('last_sent_at', sa.DateTime(timezone=True), nullable=True), - sa.ForeignKeyConstraint(['source_id'], ['sources.uuid'], ondelete='CASCADE'), - sa.PrimaryKeyConstraint('uuid'), - sa.UniqueConstraint('source_id', 'target', name='uq_sent_webmention_source_target') - ) - with op.batch_alter_table('sent_webmentions', schema=None) as batch_op: - batch_op.create_index(batch_op.f('ix_sent_webmentions_source_id'), ['source_id'], unique=False) - - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table('sent_webmentions', schema=None) as batch_op: - batch_op.drop_index(batch_op.f('ix_sent_webmentions_source_id')) - - op.drop_table('sent_webmentions') - op.drop_table('sources') - # ### end Alembic commands ### diff --git a/migrations/versions/681a2a9a1bc0_webmention_sender.py b/migrations/versions/681a2a9a1bc0_webmention_sender.py new file mode 100644 index 0000000..29142af --- /dev/null +++ b/migrations/versions/681a2a9a1bc0_webmention_sender.py @@ -0,0 +1,82 @@ +"""Webmention sender + +Revision ID: 681a2a9a1bc0 +Revises: f63641044cc1 +Create Date: 2026-08-14 13:40:55.149604 + +""" + +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = "681a2a9a1bc0" +down_revision = "f63641044cc1" +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + "sources", + sa.Column("uuid", sa.Uuid(), nullable=False), + sa.Column("path", sa.Text(), nullable=False), + sa.Column("url", sa.Text(), nullable=False), + sa.Column("content_hash", sa.String(length=32), nullable=False), + sa.Column("revision", sa.Integer(), nullable=False), + sa.Column("last_seen_at", sa.DateTime(timezone=True), nullable=False), + sa.Column("revised_at", sa.DateTime(timezone=True), nullable=False), + sa.Column("deleted_at", sa.DateTime(timezone=True), nullable=True), + sa.PrimaryKeyConstraint("uuid"), + sa.UniqueConstraint("path"), + sa.UniqueConstraint("url"), + ) + op.create_table( + "sent_webmentions", + sa.Column("uuid", sa.Uuid(), nullable=False), + sa.Column("source_id", sa.Uuid(), nullable=False), + sa.Column("target", sa.Text(), nullable=False), + sa.Column("active", sa.Boolean(), nullable=False), + sa.Column("desired_revision", sa.Integer(), nullable=False), + sa.Column("processed_revision", sa.Integer(), nullable=True), + sa.Column("sent_revision", sa.Integer(), nullable=True), + sa.Column( + "status", + sa.Enum( + "sent", + "unsupported", + "failed", + name="sent_webmention_status", + native_enum=False, + ), + nullable=True, + ), + sa.Column("failure_reason", sa.Text(), nullable=True), + sa.Column("endpoint", sa.Text(), nullable=True), + sa.Column("response_status", sa.Integer(), nullable=True), + sa.Column("status_url", sa.Text(), nullable=True), + sa.Column("last_attempted_at", sa.DateTime(timezone=True), nullable=True), + sa.Column("last_sent_at", sa.DateTime(timezone=True), nullable=True), + sa.ForeignKeyConstraint(["source_id"], ["sources.uuid"], ondelete="CASCADE"), + sa.PrimaryKeyConstraint("uuid"), + sa.UniqueConstraint( + "source_id", "target", name="uq_sent_webmention_source_target" + ), + ) + with op.batch_alter_table("sent_webmentions", schema=None) as batch_op: + batch_op.create_index( + batch_op.f("ix_sent_webmentions_source_id"), ["source_id"], unique=False + ) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table("sent_webmentions", schema=None) as batch_op: + batch_op.drop_index(batch_op.f("ix_sent_webmentions_source_id")) + + op.drop_table("sent_webmentions") + op.drop_table("sources") + # ### end Alembic commands ### diff --git a/migrations/versions/be6e229d6a3d_do_not_limit_username_and_password_hash_.py b/migrations/versions/be6e229d6a3d_do_not_limit_username_and_password_hash_.py index ac94095..5555ab9 100644 --- a/migrations/versions/be6e229d6a3d_do_not_limit_username_and_password_hash_.py +++ b/migrations/versions/be6e229d6a3d_do_not_limit_username_and_password_hash_.py @@ -5,42 +5,50 @@ Revises: 681a2a9a1bc0 Create Date: 2026-08-16 20:38:27.992624 """ -from alembic import op -import sqlalchemy as sa +import sqlalchemy as sa +from alembic import op # revision identifiers, used by Alembic. -revision = 'be6e229d6a3d' -down_revision = '681a2a9a1bc0' +revision = "be6e229d6a3d" +down_revision = "681a2a9a1bc0" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table('users', schema=None) as batch_op: - batch_op.alter_column('username', - existing_type=sa.VARCHAR(length=64), - type_=sa.Text(), - existing_nullable=False) - batch_op.alter_column('password_hash', - existing_type=sa.VARCHAR(length=256), - type_=sa.Text(), - nullable=False) + with op.batch_alter_table("users", schema=None) as batch_op: + batch_op.alter_column( + "username", + existing_type=sa.VARCHAR(length=64), + type_=sa.Text(), + existing_nullable=False, + ) + batch_op.alter_column( + "password_hash", + existing_type=sa.VARCHAR(length=256), + type_=sa.Text(), + nullable=False, + ) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table('users', schema=None) as batch_op: - batch_op.alter_column('password_hash', - existing_type=sa.Text(), - type_=sa.VARCHAR(length=256), - nullable=True) - batch_op.alter_column('username', - existing_type=sa.Text(), - type_=sa.VARCHAR(length=64), - existing_nullable=False) + with op.batch_alter_table("users", schema=None) as batch_op: + batch_op.alter_column( + "password_hash", + existing_type=sa.Text(), + type_=sa.VARCHAR(length=256), + nullable=True, + ) + batch_op.alter_column( + "username", + existing_type=sa.Text(), + type_=sa.VARCHAR(length=64), + existing_nullable=False, + ) # ### end Alembic commands ### diff --git a/migrations/versions/f63641044cc1_initial_database_schema.py b/migrations/versions/f63641044cc1_initial_database_schema.py index a3f0e40..c65af21 100644 --- a/migrations/versions/f63641044cc1_initial_database_schema.py +++ b/migrations/versions/f63641044cc1_initial_database_schema.py @@ -1,16 +1,16 @@ """Initial database schema Revision ID: f63641044cc1 -Revises: +Revises: Create Date: 2026-08-09 11:18:10.051888 """ -from alembic import op -import sqlalchemy as sa +import sqlalchemy as sa +from alembic import op # revision identifiers, used by Alembic. -revision = 'f63641044cc1' +revision = "f63641044cc1" down_revision = None branch_labels = None depends_on = None @@ -18,33 +18,37 @@ depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.create_table('received_webmentions', - sa.Column('uuid', sa.Uuid(), nullable=False), - sa.Column('source', sa.Text(), nullable=False), - sa.Column('target', sa.Text(), nullable=False), - sa.Column('status', sa.Text(), nullable=False), - sa.Column('failure_reason', sa.Text(), nullable=True), - sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False), - sa.PrimaryKeyConstraint('uuid'), - sa.UniqueConstraint('source', 'target', name='uq_webmention_source_target') + op.create_table( + "received_webmentions", + sa.Column("uuid", sa.Uuid(), nullable=False), + sa.Column("source", sa.Text(), nullable=False), + sa.Column("target", sa.Text(), nullable=False), + sa.Column("status", sa.Text(), nullable=False), + sa.Column("failure_reason", sa.Text(), nullable=True), + sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False), + sa.PrimaryKeyConstraint("uuid"), + sa.UniqueConstraint("source", "target", name="uq_webmention_source_target"), ) - op.create_table('users', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('username', sa.String(length=64), nullable=False), - sa.Column('password_hash', sa.String(length=256), nullable=True), - sa.PrimaryKeyConstraint('id') + op.create_table( + "users", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("username", sa.String(length=64), nullable=False), + sa.Column("password_hash", sa.String(length=256), nullable=True), + sa.PrimaryKeyConstraint("id"), ) - with op.batch_alter_table('users', schema=None) as batch_op: - batch_op.create_index(batch_op.f('ix_users_username'), ['username'], unique=True) + with op.batch_alter_table("users", schema=None) as batch_op: + batch_op.create_index( + batch_op.f("ix_users_username"), ["username"], unique=True + ) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table('users', schema=None) as batch_op: - batch_op.drop_index(batch_op.f('ix_users_username')) + with op.batch_alter_table("users", schema=None) as batch_op: + batch_op.drop_index(batch_op.f("ix_users_username")) - op.drop_table('users') - op.drop_table('received_webmentions') + op.drop_table("users") + op.drop_table("received_webmentions") # ### end Alembic commands ### |
