Adds a kind-pluggable backups plugin. Configuration captured from a PC is filed against the MACHINE it controls, with a revision history and download back to the native format. NTLARS/DNC is the first kind. Settings live in the controlling PC's registry but describe the machine, so revisions attach to the machine's asset and carry no foreign key to the PC: history survives a PC being replaced or deleted, and sourcehostname records the handover. Storage splits by kind. Parseable kinds store a dialect-neutral JSON projection in ShopDB and re-render on download; opaque vendor formats (part marker and similar) keep their bytes on the SFLD share with ShopDB holding metadata and the UNC pointer. Two .reg dialects exist in the wild: NTLARS's own Save... export omits the WOW6432Node path segment, scripted exports include it. Parsing strips whichever root matched, so a stored revision commits to neither and download offers both (NTLARS Load... by default, WOW6432Node for direct reg import). Getting this backwards is silent, so the dedup hash deliberately excludes sourcedialect and both dialects of one config dedup to a single revision. Dedup is load-bearing: the collector runs every GE-Enforce cycle across the fleet, so a revision is inserted only when the content hash differs from that asset's latest for that kind. A freshly imaged PC opens NTLARS with a blank General tab. Recording that would make an empty config the newest revision exactly when someone needs the last good one, so a blank MachineNo is rejected rather than accepted as a change. Two of the 320 known-good backups on the share already have that shape. DNC Info card summarises the latest revision on the machine page: General (Cnc, NcIF, HostType), eFocas, Serial, NTSHR when populated (only 18 of 147 machines), and MARK when the machine is a marker. MARK is gated on Cnc=MARKER or the ShopDB machine type, not on the MARK key having content: MARK carries serial defaults on 145 of 147 machines and DncPatterns reads YES on 103 including ordinary lathes, so neither identifies a marker. The info card is owned by the kind (BackupKind.infopanel/buildinfo) and served by a generic endpoint, so the expected successor to DNC ships its own card by adding a class rather than changing the plugin or the panel wiring. Also: schedule and retention settings with a prune that never drops the newest or the oldest revision, and scripts/import_ntlars_backups.py to seed history from the existing per-machine .reg files (144 of 147 resolve to assets). Codec verified against all 320 real backups: round-trips clean through both dialects. Bay-side generation verified on Windows against reg.exe export.
62 lines
2.9 KiB
Python
62 lines
2.9 KiB
Python
"""backups plugin baseline (real create).
|
|
|
|
Built after the ADR-008 ownership cutover, so unlike the ten cutover plugins
|
|
whose 0001 is a stamp-only anchor, this baseline genuinely CREATES the table.
|
|
The core chain never knew about backuprevisions, so this per-plugin chain is its
|
|
sole authoritative creator.
|
|
|
|
Emits explicit Alembic ops rather than using the create_plugin_tables helper:
|
|
the helper builds a per-plugin MetaData filtered to the plugin's own tables, so
|
|
the foreign key to the core assets table cannot resolve at CreateTable-compile
|
|
time (NoReferencedTableError). Same shape autogenerate produces. Tables inherit
|
|
the connection's default charset, matching how the core chain creates its own.
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = 'backups0001baseline'
|
|
down_revision = None
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
op.create_table(
|
|
'backuprevisions',
|
|
sa.Column('backuprevisionid', sa.Integer(), nullable=False),
|
|
sa.Column('assetid', sa.Integer(), nullable=False),
|
|
sa.Column('backupkind', sa.String(length=50), nullable=False),
|
|
sa.Column('storagebackend', sa.String(length=20), nullable=False,
|
|
server_default='shopdb'),
|
|
sa.Column('contenthash', sa.String(length=64), nullable=False),
|
|
sa.Column('payloadjson', sa.Text(length=16777215), nullable=True),
|
|
sa.Column('sharepath', sa.String(length=500), nullable=True),
|
|
sa.Column('sourcefilename', sa.String(length=255), nullable=True),
|
|
sa.Column('bytesize', sa.Integer(), nullable=True),
|
|
sa.Column('sourcehostname', sa.String(length=255), nullable=True),
|
|
sa.Column('collectedat', sa.DateTime(), nullable=True),
|
|
sa.Column('createdat', sa.DateTime(), nullable=False),
|
|
sa.ForeignKeyConstraint(['assetid'], ['assets.assetid'],
|
|
ondelete='CASCADE'),
|
|
sa.PrimaryKeyConstraint('backuprevisionid'),
|
|
)
|
|
op.create_index('ixbackuprevisionsassetid', 'backuprevisions', ['assetid'])
|
|
op.create_index('ixbackuprevisionsbackupkind', 'backuprevisions',
|
|
['backupkind'])
|
|
op.create_index('ixbackuprevisionscontenthash', 'backuprevisions',
|
|
['contenthash'])
|
|
# The dedup read path is "latest revision for this asset+kind", so the
|
|
# composite index is the one that actually gets used on every collector post.
|
|
op.create_index('ixbackuprevisionsassetkind', 'backuprevisions',
|
|
['assetid', 'backupkind'])
|
|
|
|
|
|
def downgrade():
|
|
op.drop_index('ixbackuprevisionsassetkind', table_name='backuprevisions')
|
|
op.drop_index('ixbackuprevisionscontenthash', table_name='backuprevisions')
|
|
op.drop_index('ixbackuprevisionsbackupkind', table_name='backuprevisions')
|
|
op.drop_index('ixbackuprevisionsassetid', table_name='backuprevisions')
|
|
op.drop_table('backuprevisions')
|