-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path0084_remove_datastream.sql
53 lines (50 loc) · 1.59 KB
/
0084_remove_datastream.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
-- +goose Up
-- +goose StatementBegin
DO
$$
BEGIN
IF EXISTS(SELECT * FROM pg_roles WHERE rolname = 'datastream') THEN
PERFORM pg_drop_replication_slot('ds_replication');
END IF;
END
$$ LANGUAGE 'plpgsql';
-- +goose StatementEnd
-- +goose StatementBegin
DO
$$
BEGIN
IF EXISTS(SELECT * FROM pg_roles WHERE rolname = 'datastream') THEN
ALTER USER "datastream" WITH NOREPLICATION;
REVOKE SELECT ON ALL TABLES IN SCHEMA PUBLIC FROM "datastream";
ALTER DEFAULT PRIVILEGES IN SCHEMA PUBLIC REVOKE SELECT ON TABLES FROM "datastream";
DROP PUBLICATION "ds_publication";
ALTER USER "nada-backend" WITH NOREPLICATION;
END IF;
END
$$ LANGUAGE 'plpgsql';
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
DO
$$
BEGIN
IF EXISTS(SELECT * FROM pg_roles WHERE rolname = 'datastream') THEN
PERFORM PG_CREATE_LOGICAL_REPLICATION_SLOT('ds_replication', 'pgoutput');
END IF;
END
$$ LANGUAGE 'plpgsql';
-- +goose StatementEnd
-- +goose StatementBegin
DO
$$
BEGIN
IF EXISTS(SELECT * FROM pg_roles WHERE rolname = 'datastream') THEN
ALTER USER "nada-backend" WITH REPLICATION;
CREATE PUBLICATION "ds_publication" FOR ALL TABLES;
ALTER DEFAULT PRIVILEGES IN SCHEMA PUBLIC GRANT SELECT ON TABLES TO "datastream";
GRANT SELECT ON ALL TABLES IN SCHEMA PUBLIC TO "datastream";
ALTER USER "datastream" WITH REPLICATION;
END IF;
END
$$ LANGUAGE 'plpgsql';
-- +goose StatementEnd