aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/migrations/versions/f63641044cc1_initial_database_schema.py
diff options
context:
space:
mode:
authorDennis Fink2026-10-27 23:16:27 +0100
committerDennis Fink2026-10-27 23:18:45 +0100
commit17ab56a3c7d3dbb3d66edf380ab637a61cefe50c (patch)
tree1626e3e1d402a6614a1cec4c2c6719d301f39bac /webmentions_ssg/migrations/versions/f63641044cc1_initial_database_schema.py
parent5afb245d13b91047d68d7b7343245c41b6460953 (diff)
downloadwebmentions-ssg-17ab56a3c7d3dbb3d66edf380ab637a61cefe50c.tar.gz
webmentions-ssg-17ab56a3c7d3dbb3d66edf380ab637a61cefe50c.zip
feat(core): add database CLI
Make database initialization and upgrades explicit so new installations cannot silently modify an existing or unversioned schema. Keep Flask-Migrate commands available separately and package the migration environment with the application for reliable deployment.
Diffstat (limited to 'webmentions_ssg/migrations/versions/f63641044cc1_initial_database_schema.py')
-rw-r--r--webmentions_ssg/migrations/versions/f63641044cc1_initial_database_schema.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/webmentions_ssg/migrations/versions/f63641044cc1_initial_database_schema.py b/webmentions_ssg/migrations/versions/f63641044cc1_initial_database_schema.py
new file mode 100644
index 0000000..5017bc3
--- /dev/null
+++ b/webmentions_ssg/migrations/versions/f63641044cc1_initial_database_schema.py
@@ -0,0 +1,58 @@
+# SPDX-FileCopyrightText: 2026 Dennis Fink <me+coding@dennisfink.me>
+#
+# SPDX-License-Identifier: BSD-3-Clause
+
+"""Initial database schema
+
+Revision ID: f63641044cc1
+Revises:
+Create Date: 2026-08-09 11:18:10.051888
+
+"""
+
+import sqlalchemy as sa
+from alembic import op
+
+# revision identifiers, used by Alembic.
+revision = "f63641044cc1"
+down_revision = None
+branch_labels = None
+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(
+ "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
+ )
+
+ # ### 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"))
+
+ op.drop_table("users")
+ op.drop_table("received_webmentions")
+ # ### end Alembic commands ###