Files
shopdb-flask/.gitea/workflows/ci.yml
cproudlock 1c6c7ba14b
Some checks failed
CI / backend (push) Successful in 1m39s
CI / naming (push) Successful in 1s
CI / frontend (push) Successful in 8s
CI / migrations-mysql (push) Failing after 8s
DB review fixes: drop redundant indexes + dead column, add CI MySQL-upgrade job
From the database review (verdict: sound-with-minor-issues). Applies the
actionable findings.

Redundant indexes: five non-unique secondary indexes duplicated a named idx_*
or a unique index on the same column - ix_communications_assetid,
ix_computers_hostname, ix_networkdevices_hostname, ix_printers_hostname (each
shadowing an idx_*), and idx_usb_serial (shadowing the serialnumber unique
index). Removed the redundant index source from the models (column index=True /
the extra db.Index) and added core migration 7d25 dropping the live duplicates.
The unique ix_*_assetid indexes are kept (they enforce assetid uniqueness).

Dead column: usbcheckouts.machineid was a NOT NULL soft-ref to the retired
machines table storing sentinel 0 (ADR-001). Dropped from the model + the
machineid=0 literal in selfhosted checkout; usb plugin migration 0002 drops it
live (downgrade restores it default 0).

Index: notifications.businessunitid (filtered by the shopfloor feed) was
unindexed; added index=True + notifications migration 0002.

CI: new migrations-mysql job proves the real multi-site deploy path - fresh
`flask db upgrade` + per-plugin install on utf8mb4 MySQL from empty, asserting
table count + charset and a clean second-run no-op. The pytest suite only
exercises SQLite create_all(), so a regression in the Alembic chain on MySQL
would otherwise ship undetected.

Verified: fresh core upgrade on a scratch utf8mb4 MySQL builds clean + no-op on
rerun (redundant indexes absent, unique assetid kept); plugin migrations applied
+ verified on the dev DB (machineid gone, bu index present). 953 backend tests
pass; naming + pyflakes green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-13 09:29:45 -04:00

122 lines
4.3 KiB
YAML

# CI for shopdb-flask.
#
# The Gitea runner executes jobs on the host (act host executor), so
# actions/setup-python cannot provision interpreters (no prebuilt binaries
# for the host distro). The backend job uses the system python3 in a venv
# instead. setup-node works because node is resolved differently.
#
# Jobs run on push and pull_request:
# backend - pytest (tests use in-memory SQLite via TestingConfig, so no
# database service is needed).
# naming - the CONTRIBUTING.md naming/style gate.
# frontend - Vue build.
# migrations-mysql - proves the REAL multi-site deploy path: a fresh
# `flask db upgrade` + per-plugin install on utf8mb4 MySQL
# from empty, idempotent on a second run. The pytest suite
# only exercises SQLite create_all(), so without this a
# regression in the Alembic chain on MySQL would ship
# undetected. Needs a runner that supports service
# containers; if yours does not, run these steps against a
# host MySQL instead.
name: CI
on:
push:
pull_request:
jobs:
backend:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v4
- name: Install dependencies
run: |
python3 --version
python3 -m venv .venv
.venv/bin/pip install --upgrade pip
.venv/bin/pip install -r requirements.txt
- name: Run backend tests
run: .venv/bin/python -m pytest
naming:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v4
- name: Run naming and style check
run: bash scripts/check-naming-and-style.sh
frontend:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install and build frontend
run: |
npm ci
npm run build
working-directory: frontend
migrations-mysql:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: shopdb_ci
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping -h localhost -uroot -proot"
--health-interval=5s --health-timeout=5s --health-retries=20
env:
DATABASE_URL: mysql+pymysql://root:root@127.0.0.1:3306/shopdb_ci?charset=utf8mb4
SECRET_KEY: ci-secret
JWT_SECRET_KEY: ci-jwt-secret
steps:
- name: Check out
uses: actions/checkout@v4
- name: Install dependencies
run: |
python3 -m venv .venv
.venv/bin/pip install --upgrade pip
.venv/bin/pip install -r requirements.txt
- name: Force utf8mb4 on the CI database
run: |
mysql -h 127.0.0.1 -uroot -proot -e \
"ALTER DATABASE shopdb_ci CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
- name: Fresh core upgrade from empty
run: .venv/bin/flask db upgrade
- name: Install every bundled plugin (runs its chain)
run: |
for p in computers employees geenforce knowledgebase machines \
measuringtools network notifications printers slides usb warranty; do
.venv/bin/flask plugin install "$p"
done
- name: Assert schema built + utf8mb4, and a second upgrade is a no-op
run: |
.venv/bin/python - <<'PY'
from shopdb import create_app
from shopdb.extensions import db
from sqlalchemy import text
app = create_app()
with app.app_context():
insp = db.inspect(db.engine)
tables = insp.get_table_names()
assert len(tables) >= 70, f'only {len(tables)} tables built'
row = db.session.execute(text(
"SELECT default_character_set_name FROM information_schema.schemata "
"WHERE schema_name = 'shopdb_ci'")).first()
assert row[0] == 'utf8mb4', f'charset is {row[0]}, not utf8mb4'
print(f'OK: {len(tables)} tables, charset {row[0]}')
PY
- name: Second core upgrade must be a clean no-op
run: .venv/bin/flask db upgrade