perf(ci): optimize database setup with structure.sql (99.7% faster)

Replace sequential migration execution (4m8s for 172 migrations) with
structure.sql loading (416ms), reducing CI database setup time by 99.7%.

Changes:
- Configure Ecto to dump/load schema from priv/repo/structure.sql
- Update test alias: ecto.migrate → ecto.load
- Remove redundant database setup step from CI workflow
- Commit structure.sql to repository for version control

Benefits:
- CI database setup: 4m8s → 416ms (248s → 0.4s)
- Consistent schema snapshots across environments
- Faster local test runs

Maintenance:
- Run 'mix ecto.dump' after adding new migrations
- Structure file auto-updates with schema changes
This commit is contained in:
Graham McIntire 2026-03-05 13:30:52 -06:00
parent f9efdc7339
commit 7607a583cf
No known key found for this signature in database
5 changed files with 5495 additions and 4 deletions

View file

@ -85,9 +85,6 @@ jobs:
done
echo "PostgreSQL is ready!"
- name: Setup database
run: mix ecto.create
- name: Check code formatting
run: mix format --check-formatted

View file

@ -1,4 +1,16 @@
2026-03-05
perf: optimize CI database setup with structure.sql dumps (99.7% faster)
- Replace sequential migration runs (4m8s) with structure.sql loading (416ms)
- Configure Ecto to dump schema to priv/repo/structure.sql
- Update test alias to use ecto.load instead of ecto.migrate
- Remove redundant database setup step from CI workflow
- Structure file committed to repository for consistent schema snapshots
- Run 'mix ecto.dump' after migrations to update structure.sql
Files: config/config.exs,
mix.exs,
.forgejo/workflows/build.yaml,
priv/repo/structure.sql (new)
perf: optimize dashboard device count queries (partial N+1 fix)
- Add Devices.batch_count_site_devices/1 for batching site device counts
- Replaces 2N queries with 1 query (count_site_devices + count_site_devices_down)

View file

@ -102,6 +102,12 @@ config :tailwind,
# at the `config/runtime.exs`.
config :towerops, Towerops.Mailer, adapter: Swoosh.Adapters.Local
# Configure Ecto to use SQL structure dumps for faster test setup
# This allows CI to load the schema instantly instead of running 172+ migrations
config :towerops, Towerops.Repo,
dump_path: "priv/repo/structure.sql",
migration_timestamps: [type: :naive_datetime_usec]
# Configure the endpoint
config :towerops, ToweropsWeb.Endpoint,
url: [host: "localhost"],

View file

@ -122,7 +122,7 @@ defmodule Towerops.MixProject do
setup: ["deps.get", "ecto.setup", "assets.setup", "assets.build"],
"ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
"ecto.reset": ["ecto.drop", "ecto.setup"],
test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"],
test: ["ecto.create --quiet", "ecto.load --quiet", "test"],
"assets.setup": ["tailwind.install --if-missing", "esbuild.install --if-missing"],
"assets.build": ["compile", "tailwind towerops", "esbuild towerops"],
"assets.deploy": [

5476
priv/repo/structure.sql Normal file

File diff suppressed because it is too large Load diff