Skip to content
This repository was archived by the owner on Oct 11, 2024. It is now read-only.

Commit f047948

Browse files
committed
Added rollout.sh + made all script executable on their own
1 parent ed370bb commit f047948

27 files changed

+82
-12
lines changed

00_create_database.sql

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,3 @@ In case of multiple environments (enterprize scenario) it is highly recommended
1515
minimize chances of executing things on the wrong DB - e.g. dev_app1_db, prod_app1_db.
1616
1717
*/
18-
19-
-- assuming "psql" as execution environment here
20-
\c pg_features_demo

01_create_role.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
-- assuming "psql" as execution environment here
2+
\c pg_features_demo
3+
14
-- Create a role (a.k.a: user, login, group) that is allowed to log in.
25
-- NB! By default roles are allowed to connect to all databases of a cluster. This does not mean that they can automatically access tables though.
36
-- But if this is not wanted, per DB connections can be set up with "REVOKE/GRANT CONNECT ON DATABASE"
47

58
CREATE ROLE demorole WITH LOGIN; -- create a normal(unprivileged) user
9+
-- NB! when seeing ERRORs during re-rollout it's normal here as role are "global" objects
610

711
-- Will later be set up to only allow selecting data
812
CREATE ROLE demorole_ro WITH LOGIN;

02_create_schema.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
RESET ROLE;
1+
\c pg_features_demo
2+
23
/*
34
Schemas in Postgres are basically "namespaces", allowing tables with same names within one DB, if schema names differ.
45
By default there is always one "public" schema pre-created with every database, but for bigger applications it is usually

02_search_path.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
\c pg_features_demo
2+
13
/*
24
35
Important concept tied to schemas is "search_path". Basically it's a priority list of schemas,

03_make_public_schema_secure.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
\c pg_features_demo
2+
13
/*
24
35
For sensitive environments it is recommended to avoid creating object in the "public" schema or even better to secure
@@ -17,4 +19,3 @@ GRANT USAGE ON SCHEMA public TO demorole_ro;
1719
ALTER DEFAULT PRIVILEGES
1820
IN SCHEMA public
1921
GRANT SELECT ON TABLES TO demorole_ro;
20-

04_alter_role.sql

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1+
\c pg_features_demo
2+
13
-- It's possible to set global, or per user or per user/db settings. Most used such settings are search_path and statement_timeout.
24
-- Changes are effective with next login.
35

4-
RESET ROLE;
5-
66
ALTER ROLE demorole IN DATABASE pg_features_demo SET search_path TO public, banking;
77
ALTER ROLE demorole_ro IN DATABASE pg_features_demo SET search_path TO public, banking;
88
ALTER ROLE demorole_ro IN DATABASE pg_features_demo SET statement_timeout TO '5s';
9-
10-
SET ROLE TO demorole;
11-

05_create_table.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
\c pg_features_demo
2+
13
-- assume "application" role
24
-- it's a good practice to own all objects by one "application" role, so that changes could be done using the same role,
35
-- not requiring the samewhat dangerous "superuser".

06_create_table_options.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
\c pg_features_demo
2+
SET ROLE TO demorole;
3+
14
/*
25
Other ways of creating tables are:
36
1) using LIKE to use existing tables as a templates and selecting (or leaving out) some constraints/checks/indexes

07_alter_table.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
\c pg_features_demo
2+
SET ROLE TO demorole;
3+
14
/*
25
ALTER TABLE is mostly commonly used to:
36
1) add/drop/rename columns

09_data_type_showcase.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
\c pg_features_demo
2+
SET ROLE TO demorole;
3+
14
CREATE TABLE public.main_datatypes (
25
/* serials aka sequences */
36
id bigserial PRIMARY KEY, -- serial/bigserial corresponds to int4/int8 and will just auto-attach a DEFAULT sequence

0 commit comments

Comments
 (0)