Skip to content

Commit

Permalink
[postgres] make init scripts idempotent
Browse files Browse the repository at this point in the history
This allows to attach a persistent volume to the PostgreSQL service and
still always run the init scripts on startup. For the first startup with
a fresh volume, the database will be initialized correctly; on
subsequent starts the init scripts will do nothing.
  • Loading branch information
basti1302 committed Feb 5, 2024
1 parent 6914c0f commit 6bd77d7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/ffspostgres/init-scripts/10-ffs_schema.sql
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
-- Copyright The OpenTelemetry Authors
-- SPDX-License-Identifier: Apache-2.0

CREATE TABLE public.featureflags (
CREATE TABLE IF NOT EXISTS public.featureflags (
name character varying(255),
description character varying(255),
enabled double precision DEFAULT 0.0 NOT NULL
);

ALTER TABLE ONLY public.featureflags DROP CONSTRAINT featureflags_pkey;
ALTER TABLE ONLY public.featureflags ADD CONSTRAINT featureflags_pkey PRIMARY KEY (name);

CREATE UNIQUE INDEX featureflags_name_index ON public.featureflags USING btree (name);
CREATE UNIQUE INDEX IF NOT EXISTS featureflags_name_index ON public.featureflags USING btree (name);

3 changes: 2 additions & 1 deletion src/ffspostgres/init-scripts/20-ffs_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ VALUES
('paymentServiceSimulateSlownessUpperBound', 'Maximum simulated delay in milliseconds in payment service, if enabled', 600),
('shippingServiceSimulateSlowness', 'Simulate slow response times in the shipping service', 0),
('shippingServiceSimulateSlownessLowerBound', 'Minimum simulated delay in milliseconds in shipping service, if enabled', 250),
('shippingServiceSimulateSlownessUpperBound', 'Maximum simulated delay in milliseconds in shipping service, if enabled', 400);
('shippingServiceSimulateSlownessUpperBound', 'Maximum simulated delay in milliseconds in shipping service, if enabled', 400)
ON CONFLICT DO NOTHING;

0 comments on commit 6bd77d7

Please sign in to comment.