Skip to content

Commit

Permalink
Quote indent DB name
Browse files Browse the repository at this point in the history
  • Loading branch information
shayonj committed Dec 13, 2023
1 parent 56169d9 commit 0f376ac
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 21 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,26 @@ jobs:
sudo su - postgres -c "createuser -p 5432 -d -s -e -l james-bond"
sudo -u postgres psql -p 5432 -c 'alter user "james-bond" with encrypted password '"'"''"$PGPASSWORD"''"'"';'
sudo su - postgres -c "createdb -p 5432 postgres-db"
sudo -u postgres psql -p 5432 -c "grant all privileges on database \"postgres-db\" to \"james-bond\";"
sudo su - postgres -c "createuser -p 5433 -d -s -e -l james-bond"
sudo -u postgres psql -p 5433 -c 'alter user "james-bond" with encrypted password '"'"''"$PGPASSWORD"''"'"';'
sudo su - postgres -c "createdb -p 5433 postgres-db"
sudo -u postgres psql -p 5433 -c "grant all privileges on database \"postgres-db\" to \"james-bond\";"
# Remove the escaped quote since we are passing the pwd to psql
# String: james-bond123@7!'3aaR
export PGPASSWORD='james-bond123@7!'"'"'3aaR'
psql -h localhost -d postgres -U james-bond -p 5432 -c 'ALTER SYSTEM SET wal_level = logical;'
psql -h localhost -d postgres -U james-bond -p 5433 -c 'ALTER SYSTEM SET wal_level = logical;'
psql -h localhost -d postgres-db -U james-bond -p 5432 -c 'ALTER SYSTEM SET wal_level = logical;'
psql -h localhost -d postgres-db -U james-bond -p 5433 -c 'ALTER SYSTEM SET wal_level = logical;'
sudo systemctl restart postgresql@${{ matrix.pg.from }}-main.service
sudo systemctl restart postgresql@${{ matrix.pg.to }}-main.service
sudo systemctl restart postgresql
psql -h localhost -d postgres -U james-bond -p 5432 -c 'show wal_level;'
psql -h localhost -d postgres -U james-bond -p 5433 -c 'show wal_level;'
psql -h localhost -d postgres-db -U james-bond -p 5432 -c 'show wal_level;'
psql -h localhost -d postgres-db -U james-bond -p 5433 -c 'show wal_level;'
- name: Run RSpec
run: bundle exec rspec
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/smoke.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,26 @@ jobs:
sudo su - postgres -c "createuser -p 5432 -d -s -e -l james-bond"
sudo -u postgres psql -p 5432 -c 'alter user "james-bond" with encrypted password '"'"''"$PGPASSWORD"''"'"';'
sudo su - postgres -c "createdb -p 5432 postgres-db"
sudo -u postgres psql -p 5432 -c "grant all privileges on database \"postgres-db\" to \"james-bond\";"
sudo su - postgres -c "createuser -p 5433 -d -s -e -l james-bond"
sudo -u postgres psql -p 5433 -c 'alter user "james-bond" with encrypted password '"'"''"$PGPASSWORD"''"'"';'
sudo su - postgres -c "createdb -p 5433 postgres-db"
sudo -u postgres psql -p 5433 -c "grant all privileges on database \"postgres-db\" to \"james-bond\";"
# Remove the escaped quote since we are passing the pwd to psql
# String: james-bond123@7!'3aaR
export PGPASSWORD='james-bond123@7!'"'"'3aaR'
psql -h localhost -d postgres -U james-bond -p 5432 -c 'ALTER SYSTEM SET wal_level = logical;'
psql -h localhost -d postgres -U james-bond -p 5433 -c 'ALTER SYSTEM SET wal_level = logical;'
psql -h localhost -d postgres-db -U james-bond -p 5432 -c 'ALTER SYSTEM SET wal_level = logical;'
psql -h localhost -d postgres-db -U james-bond -p 5433 -c 'ALTER SYSTEM SET wal_level = logical;'
sudo systemctl restart postgresql@${{ matrix.pg.from }}-main.service
sudo systemctl restart postgresql@${{ matrix.pg.to }}-main.service
sudo systemctl restart postgresql
psql -h localhost -d postgres -U james-bond -p 5432 -c 'show wal_level;'
psql -h localhost -d postgres -U james-bond -p 5433 -c 'show wal_level;'
psql -h localhost -d postgres-db -U james-bond -p 5432 -c 'show wal_level;'
psql -h localhost -d postgres-db -U james-bond -p 5433 -c 'show wal_level;'
- name: Run RSpec
run: bundle exec rspec spec/smoke_spec.rb
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
environment:
POSTGRES_USER: james-bond
POSTGRES_PASSWORD: james-bond123@7!'3aaR
POSTGRES_DB: postgres
POSTGRES_DB: postgres-db
command: >
-c wal_level=logical
-c ssl=on
Expand All @@ -23,7 +23,7 @@ services:
environment:
POSTGRES_USER: james-bond
POSTGRES_PASSWORD: james-bond123@7!'3aaR
POSTGRES_DB: postgres
POSTGRES_DB: postgres-db
command: >
-c wal_level=logical
-c ssl=on
Expand Down
2 changes: 1 addition & 1 deletion lib/pg_easy_replicate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def drop_user(conn_string:, user: internal_user_name)
return unless user_exists?(conn_string: conn_string, user: user)

sql = <<~SQL
revoke all privileges on database #{db_name(conn_string)} from #{quote_ident(user)};
revoke all privileges on database #{quote_ident(db_name(conn_string))} from #{quote_ident(user)};
SQL

Query.run(
Expand Down
2 changes: 1 addition & 1 deletion scripts/e2e-bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ export SOURCE_DB_URL="postgres://james-bond:james-bond123%407%21%273aaR@localhos
export TARGET_DB_URL="postgres://james-bond:james-bond123%407%21%273aaR@localhost:5433/postgres"
export PGPASSWORD='james-bond123@7!'"'"'3aaR'

pgbench --initialize -s 5 --foreign-keys --host localhost -U james-bond -d postgres
pgbench --initialize -s 5 --foreign-keys --host localhost -U james-bond -d postgres-db

bundle exec bin/pg_easy_replicate config_check --copy-schema
18 changes: 9 additions & 9 deletions spec/database_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ def test_schema
# We are use url encoded password below.
# Original password is james-bond123@7!'3aaR
def connection_url(user = "james-bond")
"postgres://#{user}:james-bond123%407%21%273aaR@localhost:5432/postgres"
"postgres://#{user}:james-bond123%407%21%273aaR@localhost:5432/postgres-db"
end

def target_connection_url(user = "james-bond")
"postgres://#{user}:james-bond123%407%21%273aaR@localhost:5433/postgres"
"postgres://#{user}:james-bond123%407%21%273aaR@localhost:5433/postgres-db"
end

def docker_compose_target_connection_url(user = "james-bond")
"postgres://#{user}:james-bond123%407%21%273aaR@target_db/postgres"
"postgres://#{user}:james-bond123%407%21%273aaR@target_db/postgres-db"
end

def docker_compose_source_connection_url(user = "james-bond")
return connection_url(user) if ENV["GITHUB_WORKFLOW"] # if running in CI/github actions
"postgres://#{user}:james-bond123%407%21%273aaR@source_db/postgres"
"postgres://#{user}:james-bond123%407%21%273aaR@source_db/postgres-db"
end

def setup_tables(user = "james-bond", setup_target_db: true)
Expand Down Expand Up @@ -57,7 +57,7 @@ def setup_roles
sql = <<~SQL
drop role if exists #{PG::Connection.quote_ident("james-bond_role_regular")};
create role #{PG::Connection.quote_ident("james-bond_role_regular")} WITH createrole createdb replication LOGIN PASSWORD 'james-bond123@7!''3aaR'; grant #{PG::Connection.quote_ident("james-bond_super_role")} to #{PG::Connection.quote_ident("james-bond_role_regular")};
grant all privileges on database postgres TO #{PG::Connection.quote_ident("james-bond_role_regular")};
grant all privileges on database #{PG::Connection.quote_ident("postgres-db")} TO #{PG::Connection.quote_ident("james-bond_role_regular")};
SQL
PgEasyReplicate::Query.run(
query: sql,
Expand All @@ -77,14 +77,14 @@ def cleanup_roles
if role == "james-bond_role_regular"
PgEasyReplicate::Query.run(
query:
"revoke all privileges on database postgres from #{PG::Connection.quote_ident("james-bond_role_regular")};",
"revoke all privileges on database #{PG::Connection.quote_ident("postgres-db")} from #{PG::Connection.quote_ident("james-bond_role_regular")};",
connection_url: connection_url,
user: "james-bond",
)

PgEasyReplicate::Query.run(
query:
"revoke all privileges on database postgres from #{PG::Connection.quote_ident("james-bond_role_regular")};",
"revoke all privileges on database #{PG::Connection.quote_ident("postgres-db")} from #{PG::Connection.quote_ident("james-bond_role_regular")};",
connection_url: target_connection_url,
user: "james-bond",
)
Expand Down Expand Up @@ -214,9 +214,9 @@ def vacuum_stats(url:, schema:)
def self.populate_env_vars
ENV[
"SOURCE_DB_URL"
] = "postgres://james-bond:james-bond123%407%21%273aaR@localhost:5432/postgres"
] = "postgres://james-bond:james-bond123%407%21%273aaR@localhost:5432/postgres-db"
ENV[
"TARGET_DB_URL"
] = "postgres://james-bond:james-bond123%407%21%273aaR@localhost:5433/postgres"
] = "postgres://james-bond:james-bond123%407%21%273aaR@localhost:5433/postgres-db"
end
end

0 comments on commit 0f376ac

Please sign in to comment.