Import the wilm agent store, WINC adoption work and batches CLI, with four fixes

This commit is contained in:
2026-09-03 08:16:38 -04:00
parent 4b21aa3887
commit b0bd73f62d
51 changed files with 5107 additions and 90 deletions

View File

@@ -0,0 +1,89 @@
"""Add importbatches and importjournalentries (reversible bulk imports)
Two additive, platform-level tables that let any bulk-import writer record what
it changed so the change can be reversed later. Import-agnostic: an importer
writes primitive mutations (update a cell, insert a row) tied to a batch id, and
a generic undo replays them in reverse.
importbatches one row per approved write (identity: batchid, the same
value the approval packet carries).
importjournalentries one row per reversible primitive mutation, ordered by
sequence so undo can walk them in reverse.
Idempotent guards and a real downgrade throughout; strict MySQL 8 clean.
Revision ID: 7d37_import_batches_and_journal
Revises: 7d36_scriptlibrary_and_app_installer_digest
Create Date: 2026-09-03
"""
from alembic import op
import sqlalchemy as sa
revision = '7d37_import_batches_and_journal'
down_revision = '7d36_scriptlibrary_and_app_installer_digest'
branch_labels = None
depends_on = None
def upgrade():
bind = op.get_bind()
insp = sa.inspect(bind)
tables = insp.get_table_names()
if 'importbatches' not in tables:
op.create_table(
'importbatches',
sa.Column('batchid', sa.String(length=36), primary_key=True),
sa.Column('kind', sa.String(length=64), nullable=False),
sa.Column('planhash', sa.String(length=64), nullable=False),
sa.Column('rowcount', sa.Integer(), nullable=False,
server_default='0'),
sa.Column('createdat', sa.DateTime(), nullable=False),
sa.Column('createdby', sa.String(length=100), nullable=True),
sa.Column('status', sa.String(length=16), nullable=False,
server_default='applied'),
sa.Column('undoneat', sa.DateTime(), nullable=True),
)
if 'importjournalentries' not in tables:
op.create_table(
'importjournalentries',
sa.Column('entryid', sa.BigInteger(), primary_key=True,
autoincrement=True),
sa.Column('batchid', sa.String(length=36), nullable=False),
sa.Column('sequence', sa.Integer(), nullable=False),
sa.Column('operation', sa.String(length=16), nullable=False),
sa.Column('targettable', sa.String(length=64), nullable=False),
sa.Column('targetid', sa.BigInteger(), nullable=False),
sa.Column('columnname', sa.String(length=64), nullable=True),
sa.Column('oldvalue', sa.Text(), nullable=True),
sa.Column('newvalue', sa.Text(), nullable=True),
sa.Column('isreverted', sa.Boolean(), nullable=False,
server_default=sa.text('0')),
sa.ForeignKeyConstraint(
['batchid'], ['importbatches.batchid'],
name='fk_importjournalentries_batchid',
ondelete='CASCADE'),
)
op.create_index(
'idx_importjournalentries_batchid',
'importjournalentries', ['batchid'])
def downgrade():
bind = op.get_bind()
insp = sa.inspect(bind)
tables = insp.get_table_names()
if 'importjournalentries' in tables:
existing = [ix['name'] for ix in
insp.get_indexes('importjournalentries')]
if 'idx_importjournalentries_batchid' in existing:
op.drop_index('idx_importjournalentries_batchid',
table_name='importjournalentries')
op.drop_table('importjournalentries')
if 'importbatches' in tables:
op.drop_table('importbatches')