Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion docker-entrypoint-initdb.d/6-features.sql
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ CREATE TABLE public.togglz (
feature_name character varying(100) NOT NULL,
feature_enabled integer,
strategy_id character varying(200),
strategy_params character varying(2000)
strategy_params character varying(2000),
last_modified timestamp with time zone
);


Expand Down Expand Up @@ -181,6 +182,22 @@ OAUTH_DOMAINS_INTERSTITIAL 0 \N \N
ALTER TABLE ONLY public.togglz
ADD CONSTRAINT togglz_pkey PRIMARY KEY (feature_name);

-- Backfill last_modified for initial data
UPDATE public.togglz SET last_modified = NOW() WHERE last_modified IS NULL;

-- Trigger to track last modification date on enable/disable
CREATE OR REPLACE FUNCTION update_togglz_last_modified()
RETURNS TRIGGER AS $$
BEGIN
NEW.last_modified = NOW();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER togglz_last_modified_trigger
BEFORE INSERT OR UPDATE ON public.togglz
FOR EACH ROW
EXECUTE FUNCTION update_togglz_last_modified();

--
-- Name: SCHEMA public; Type: ACL; Schema: -; Owner: postgres
Expand Down
23 changes: 23 additions & 0 deletions docker-entrypoint-initdb.d/migrations/add_togglz_last_modified.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- Migration: Add last_modified column to togglz table
-- Run against the features database: psql -d features -f add_togglz_last_modified.sql
-- Safe to run on DBs that already have this column (uses IF NOT EXISTS)

\c features

ALTER TABLE public.togglz ADD COLUMN IF NOT EXISTS last_modified timestamp with time zone;

UPDATE public.togglz SET last_modified = NOW() WHERE last_modified IS NULL;

CREATE OR REPLACE FUNCTION update_togglz_last_modified()
RETURNS TRIGGER AS $$
BEGIN
NEW.last_modified = NOW();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS togglz_last_modified_trigger ON public.togglz;
CREATE TRIGGER togglz_last_modified_trigger
BEFORE INSERT OR UPDATE ON public.togglz
FOR EACH ROW
EXECUTE FUNCTION update_togglz_last_modified();