Merge pull request #1678 from Rjevski/idempotent-database-migrations
Make DB migrations idempotent.
This commit is contained in:
commit
347c189f3f
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
-- DROP TABLE public.annotations;
|
-- DROP TABLE public.annotations;
|
||||||
|
|
||||||
CREATE TABLE public.annotations
|
CREATE TABLE IF NOT EXISTS public.annotations
|
||||||
(
|
(
|
||||||
id text NOT NULL,
|
id text NOT NULL,
|
||||||
annotations xml,
|
annotations xml,
|
||||||
CONSTRAINT annotations_id_key UNIQUE (id)
|
CONSTRAINT annotations_id_key UNIQUE (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
GRANT ALL ON TABLE public.annotations TO kemal;
|
GRANT ALL ON TABLE public.annotations TO current_user;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
-- DROP TABLE public.channel_videos;
|
-- DROP TABLE public.channel_videos;
|
||||||
|
|
||||||
CREATE TABLE public.channel_videos
|
CREATE TABLE IF NOT EXISTS public.channel_videos
|
||||||
(
|
(
|
||||||
id text NOT NULL,
|
id text NOT NULL,
|
||||||
title text,
|
title text,
|
||||||
@ -17,13 +17,13 @@ CREATE TABLE public.channel_videos
|
|||||||
CONSTRAINT channel_videos_id_key UNIQUE (id)
|
CONSTRAINT channel_videos_id_key UNIQUE (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
GRANT ALL ON TABLE public.channel_videos TO kemal;
|
GRANT ALL ON TABLE public.channel_videos TO current_user;
|
||||||
|
|
||||||
-- Index: public.channel_videos_ucid_idx
|
-- Index: public.channel_videos_ucid_idx
|
||||||
|
|
||||||
-- DROP INDEX public.channel_videos_ucid_idx;
|
-- DROP INDEX public.channel_videos_ucid_idx;
|
||||||
|
|
||||||
CREATE INDEX channel_videos_ucid_idx
|
CREATE INDEX IF NOT EXISTS channel_videos_ucid_idx
|
||||||
ON public.channel_videos
|
ON public.channel_videos
|
||||||
USING btree
|
USING btree
|
||||||
(ucid COLLATE pg_catalog."default");
|
(ucid COLLATE pg_catalog."default");
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
-- DROP TABLE public.channels;
|
-- DROP TABLE public.channels;
|
||||||
|
|
||||||
CREATE TABLE public.channels
|
CREATE TABLE IF NOT EXISTS public.channels
|
||||||
(
|
(
|
||||||
id text NOT NULL,
|
id text NOT NULL,
|
||||||
author text,
|
author text,
|
||||||
@ -12,13 +12,13 @@ CREATE TABLE public.channels
|
|||||||
CONSTRAINT channels_id_key UNIQUE (id)
|
CONSTRAINT channels_id_key UNIQUE (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
GRANT ALL ON TABLE public.channels TO kemal;
|
GRANT ALL ON TABLE public.channels TO current_user;
|
||||||
|
|
||||||
-- Index: public.channels_id_idx
|
-- Index: public.channels_id_idx
|
||||||
|
|
||||||
-- DROP INDEX public.channels_id_idx;
|
-- DROP INDEX public.channels_id_idx;
|
||||||
|
|
||||||
CREATE INDEX channels_id_idx
|
CREATE INDEX IF NOT EXISTS channels_id_idx
|
||||||
ON public.channels
|
ON public.channels
|
||||||
USING btree
|
USING btree
|
||||||
(id COLLATE pg_catalog."default");
|
(id COLLATE pg_catalog."default");
|
||||||
|
@ -2,20 +2,20 @@
|
|||||||
|
|
||||||
-- DROP TABLE public.nonces;
|
-- DROP TABLE public.nonces;
|
||||||
|
|
||||||
CREATE TABLE public.nonces
|
CREATE TABLE IF NOT EXISTS public.nonces
|
||||||
(
|
(
|
||||||
nonce text,
|
nonce text,
|
||||||
expire timestamp with time zone,
|
expire timestamp with time zone,
|
||||||
CONSTRAINT nonces_id_key UNIQUE (nonce)
|
CONSTRAINT nonces_id_key UNIQUE (nonce)
|
||||||
);
|
);
|
||||||
|
|
||||||
GRANT ALL ON TABLE public.nonces TO kemal;
|
GRANT ALL ON TABLE public.nonces TO current_user;
|
||||||
|
|
||||||
-- Index: public.nonces_nonce_idx
|
-- Index: public.nonces_nonce_idx
|
||||||
|
|
||||||
-- DROP INDEX public.nonces_nonce_idx;
|
-- DROP INDEX public.nonces_nonce_idx;
|
||||||
|
|
||||||
CREATE INDEX nonces_nonce_idx
|
CREATE INDEX IF NOT EXISTS nonces_nonce_idx
|
||||||
ON public.nonces
|
ON public.nonces
|
||||||
USING btree
|
USING btree
|
||||||
(nonce COLLATE pg_catalog."default");
|
(nonce COLLATE pg_catalog."default");
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
-- DROP TABLE public.playlist_videos;
|
-- DROP TABLE public.playlist_videos;
|
||||||
|
|
||||||
CREATE TABLE playlist_videos
|
CREATE TABLE IF NOT EXISTS playlist_videos
|
||||||
(
|
(
|
||||||
title text,
|
title text,
|
||||||
id text,
|
id text,
|
||||||
@ -16,4 +16,4 @@ CREATE TABLE playlist_videos
|
|||||||
PRIMARY KEY (index,plid)
|
PRIMARY KEY (index,plid)
|
||||||
);
|
);
|
||||||
|
|
||||||
GRANT ALL ON TABLE public.playlist_videos TO kemal;
|
GRANT ALL ON TABLE public.playlist_videos TO current_user;
|
||||||
|
@ -13,7 +13,7 @@ CREATE TYPE public.privacy AS ENUM
|
|||||||
|
|
||||||
-- DROP TABLE public.playlists;
|
-- DROP TABLE public.playlists;
|
||||||
|
|
||||||
CREATE TABLE public.playlists
|
CREATE TABLE IF NOT EXISTS public.playlists
|
||||||
(
|
(
|
||||||
title text,
|
title text,
|
||||||
id text primary key,
|
id text primary key,
|
||||||
@ -26,4 +26,4 @@ CREATE TABLE public.playlists
|
|||||||
index int8[]
|
index int8[]
|
||||||
);
|
);
|
||||||
|
|
||||||
GRANT ALL ON public.playlists TO kemal;
|
GRANT ALL ON public.playlists TO current_user;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
-- DROP TABLE public.session_ids;
|
-- DROP TABLE public.session_ids;
|
||||||
|
|
||||||
CREATE TABLE public.session_ids
|
CREATE TABLE IF NOT EXISTS public.session_ids
|
||||||
(
|
(
|
||||||
id text NOT NULL,
|
id text NOT NULL,
|
||||||
email text,
|
email text,
|
||||||
@ -10,13 +10,13 @@ CREATE TABLE public.session_ids
|
|||||||
CONSTRAINT session_ids_pkey PRIMARY KEY (id)
|
CONSTRAINT session_ids_pkey PRIMARY KEY (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
GRANT ALL ON TABLE public.session_ids TO kemal;
|
GRANT ALL ON TABLE public.session_ids TO current_user;
|
||||||
|
|
||||||
-- Index: public.session_ids_id_idx
|
-- Index: public.session_ids_id_idx
|
||||||
|
|
||||||
-- DROP INDEX public.session_ids_id_idx;
|
-- DROP INDEX public.session_ids_id_idx;
|
||||||
|
|
||||||
CREATE INDEX session_ids_id_idx
|
CREATE INDEX IF NOT EXISTS session_ids_id_idx
|
||||||
ON public.session_ids
|
ON public.session_ids
|
||||||
USING btree
|
USING btree
|
||||||
(id COLLATE pg_catalog."default");
|
(id COLLATE pg_catalog."default");
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
-- DROP TABLE public.users;
|
-- DROP TABLE public.users;
|
||||||
|
|
||||||
CREATE TABLE public.users
|
CREATE TABLE IF NOT EXISTS public.users
|
||||||
(
|
(
|
||||||
updated timestamp with time zone,
|
updated timestamp with time zone,
|
||||||
notifications text[],
|
notifications text[],
|
||||||
@ -16,13 +16,13 @@ CREATE TABLE public.users
|
|||||||
CONSTRAINT users_email_key UNIQUE (email)
|
CONSTRAINT users_email_key UNIQUE (email)
|
||||||
);
|
);
|
||||||
|
|
||||||
GRANT ALL ON TABLE public.users TO kemal;
|
GRANT ALL ON TABLE public.users TO current_user;
|
||||||
|
|
||||||
-- Index: public.email_unique_idx
|
-- Index: public.email_unique_idx
|
||||||
|
|
||||||
-- DROP INDEX public.email_unique_idx;
|
-- DROP INDEX public.email_unique_idx;
|
||||||
|
|
||||||
CREATE UNIQUE INDEX email_unique_idx
|
CREATE UNIQUE INDEX IF NOT EXISTS email_unique_idx
|
||||||
ON public.users
|
ON public.users
|
||||||
USING btree
|
USING btree
|
||||||
(lower(email) COLLATE pg_catalog."default");
|
(lower(email) COLLATE pg_catalog."default");
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
-- DROP TABLE public.videos;
|
-- DROP TABLE public.videos;
|
||||||
|
|
||||||
CREATE TABLE public.videos
|
CREATE TABLE IF NOT EXISTS public.videos
|
||||||
(
|
(
|
||||||
id text NOT NULL,
|
id text NOT NULL,
|
||||||
info text,
|
info text,
|
||||||
@ -10,13 +10,13 @@ CREATE TABLE public.videos
|
|||||||
CONSTRAINT videos_pkey PRIMARY KEY (id)
|
CONSTRAINT videos_pkey PRIMARY KEY (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
GRANT ALL ON TABLE public.videos TO kemal;
|
GRANT ALL ON TABLE public.videos TO current_user;
|
||||||
|
|
||||||
-- Index: public.id_idx
|
-- Index: public.id_idx
|
||||||
|
|
||||||
-- DROP INDEX public.id_idx;
|
-- DROP INDEX public.id_idx;
|
||||||
|
|
||||||
CREATE UNIQUE INDEX id_idx
|
CREATE UNIQUE INDEX IF NOT EXISTS id_idx
|
||||||
ON public.videos
|
ON public.videos
|
||||||
USING btree
|
USING btree
|
||||||
(id COLLATE pg_catalog."default");
|
(id COLLATE pg_catalog."default");
|
||||||
|
@ -5,12 +5,12 @@ psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-E
|
|||||||
CREATE USER postgres;
|
CREATE USER postgres;
|
||||||
EOSQL
|
EOSQL
|
||||||
|
|
||||||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/channels.sql
|
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/channels.sql
|
||||||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/videos.sql
|
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/videos.sql
|
||||||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/channel_videos.sql
|
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/channel_videos.sql
|
||||||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/users.sql
|
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/users.sql
|
||||||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/session_ids.sql
|
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/session_ids.sql
|
||||||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/nonces.sql
|
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/nonces.sql
|
||||||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/annotations.sql
|
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/annotations.sql
|
||||||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/playlists.sql
|
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/playlists.sql
|
||||||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/playlist_videos.sql
|
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/playlist_videos.sql
|
||||||
|
Loading…
Reference in New Issue
Block a user