mirror of
https://github.com/zvx-echo6/central.git
synced 2026-05-21 18:14:44 +02:00
feat(db): add migration 002 for updated_at trigger and enabled index
Adds auto-update trigger for updated_at column on adapters table and partial index for efficient enabled adapter queries. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
3e392cad81
commit
166268a44e
1 changed files with 21 additions and 0 deletions
21
sql/migrations/002_add_updated_at_trigger_and_index.sql
Normal file
21
sql/migrations/002_add_updated_at_trigger_and_index.sql
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
-- Migration: 002_add_updated_at_trigger_and_index
|
||||
-- Adds auto-update trigger for updated_at column on adapters table
|
||||
-- Adds partial index for efficient enabled adapter queries
|
||||
|
||||
-- Auto-update trigger for updated_at
|
||||
CREATE OR REPLACE FUNCTION config.set_updated_at()
|
||||
RETURNS trigger AS $$
|
||||
BEGIN
|
||||
NEW.updated_at := now();
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE TRIGGER adapters_set_updated_at
|
||||
BEFORE UPDATE ON config.adapters
|
||||
FOR EACH ROW EXECUTE FUNCTION config.set_updated_at();
|
||||
|
||||
-- Partial index for enabled adapters (common query pattern)
|
||||
CREATE INDEX adapters_enabled_idx
|
||||
ON config.adapters (enabled)
|
||||
WHERE enabled = true;
|
||||
Loading…
Add table
Add a link
Reference in a new issue