Skip to content

Commit

Permalink
Merge pull request #34 from fabianoflorentino/development
Browse files Browse the repository at this point in the history
Development to Main
  • Loading branch information
fabianoflorentino authored Mar 31, 2024
2 parents 16cb6ab + 0aed25a commit 9d9a3c3
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 28 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
POSTGRES_PORT: '5432'
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
PGPASSFILE: /app/.pgpass
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
POSTGRES_MAX_CONNECTIONS: '30'
POSTGRES_RANDOM_PAGE_COST: '1.1'
Expand All @@ -71,6 +72,10 @@ jobs:

- name: Database Setup
run: |
psql "postgresql://${{ secrets.POSTGRES_USER }}:${{ secrets.POSTGRES_PASSWORD }}@localhost:5432" << EOF
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
EOF
bundle exec rails db:migrate
- name: Run RSpec
Expand Down
41 changes: 19 additions & 22 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ GEM
ast (2.4.2)
base64 (0.2.0)
bcrypt (3.1.20)
bigdecimal (3.1.6)
bigdecimal (3.1.7)
bootsnap (1.18.3)
msgpack (~> 1.2)
brakeman (6.0.1)
Expand All @@ -87,7 +87,7 @@ GEM
connection_pool (2.4.1)
crass (1.0.6)
date (3.3.4)
debug (1.9.1)
debug (1.9.2)
irb (~> 1.10)
reline (>= 0.3.8)
diff-lcs (1.5.1)
Expand All @@ -102,10 +102,10 @@ GEM
i18n (>= 1.8.11, < 2)
globalid (1.2.1)
activesupport (>= 6.1)
i18n (1.14.1)
i18n (1.14.4)
concurrent-ruby (~> 1.0)
io-console (0.7.2)
irb (1.11.2)
irb (1.12.0)
rdoc
reline (>= 0.4.2)
json (2.7.1)
Expand All @@ -124,7 +124,7 @@ GEM
net-smtp
marcel (1.0.4)
mini_mime (1.1.5)
minitest (5.22.2)
minitest (5.22.3)
msgpack (1.7.2)
mutex_m (0.2.0)
net-imap (0.4.10)
Expand All @@ -134,12 +134,10 @@ GEM
net-protocol
net-protocol (0.2.2)
timeout
net-smtp (0.4.0.1)
net-smtp (0.5.0)
net-protocol
nio4r (2.7.0)
nokogiri (1.16.2-aarch64-linux)
racc (~> 1.4)
nokogiri (1.16.2-x86_64-linux)
nio4r (2.7.1)
nokogiri (1.16.3-aarch64-linux)
racc (~> 1.4)
parallel (1.24.0)
parser (3.3.0.5)
Expand All @@ -151,7 +149,7 @@ GEM
puma (6.4.2)
nio4r (~> 2.0)
racc (1.7.3)
rack (3.0.9.1)
rack (3.0.10)
rack-session (2.0.0)
rack (>= 3.0.0)
rack-test (2.1.0)
Expand Down Expand Up @@ -190,10 +188,10 @@ GEM
zeitwerk (~> 2.6)
rainbow (3.1.1)
rake (13.1.0)
rdoc (6.6.2)
rdoc (6.6.3.1)
psych (>= 4.0.0)
regexp_parser (2.9.0)
reline (0.4.3)
reline (0.5.0)
io-console (~> 0.5)
rexml (3.2.6)
rspec (3.13.0)
Expand All @@ -208,14 +206,14 @@ GEM
rspec-mocks (3.13.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-rails (6.1.1)
rspec-rails (6.1.2)
actionpack (>= 6.1)
activesupport (>= 6.1)
railties (>= 6.1)
rspec-core (~> 3.12)
rspec-expectations (~> 3.12)
rspec-mocks (~> 3.12)
rspec-support (~> 3.12)
rspec-core (~> 3.13)
rspec-expectations (~> 3.13)
rspec-mocks (~> 3.13)
rspec-support (~> 3.13)
rspec-support (3.13.1)
rubocop (1.61.0)
json (~> 2.3)
Expand All @@ -228,7 +226,7 @@ GEM
rubocop-ast (>= 1.30.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.1)
rubocop-ast (1.31.2)
parser (>= 3.3.0.4)
rubocop-capybara (2.20.0)
rubocop (~> 1.41)
Expand All @@ -242,7 +240,7 @@ GEM
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop-ast (>= 1.30.0, < 2.0)
rubocop-rspec (2.27.0)
rubocop-rspec (2.27.1)
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
Expand All @@ -268,7 +266,6 @@ GEM
PLATFORMS
aarch64-linux
aarch64-linux-musl
x86_64-linux

DEPENDENCIES
bcrypt (~> 3.1, >= 3.1.20)
Expand Down Expand Up @@ -296,4 +293,4 @@ RUBY VERSION
ruby 3.2.3p157

BUNDLED WITH
2.5.6
2.5.7
9 changes: 6 additions & 3 deletions bin/initdb
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/usr/bin/env sh

set -e

sleep 5

psql \
--host="${POSTGRES_HOST}" \
--username="${POSTGRES_USER}" \
--dbname="${POSTGRES_DB}" \
--file=/app/db/init.sql \
--no-password
--no-password \
--dbname="${POSTGRES_DB}" --file=/app/db/init.sql && exit
2 changes: 2 additions & 0 deletions bin/migration
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

set -e

sleep 5

printf "Running migrations...\n"
bundle exec rails db:migrate
3 changes: 1 addition & 2 deletions db/init.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
TRUNCATE CUSTOMERS CASCADE;
TRUNCATE TRANSACTIONS CASCADE;
CREATE EXTENSION pgcrypto;
20 changes: 20 additions & 0 deletions db/migrate/20240331143457_add_supervisor_user_to_customers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

# This migration is used to create a supervisor user with admin role.
class AddSupervisorUserToCustomers < ActiveRecord::Migration[7.1]
SUPERVISOR_PASSWORD = SecureRandom.hex(16)
private_constant :SUPERVISOR_PASSWORD

def up
execute <<-SQL.squish
INSERT INTO customers (name, email, password, role, created_at, updated_at)
VALUES ('Supervisor', '[email protected]', crypt('#{SUPERVISOR_PASSWORD}', gen_salt('bf')), 'admin', now(), now())
SQL
end

def down
execute <<-SQL.squish
DELETE FROM customers WHERE email = '[email protected]' AND name = 'Supervisor'
SQL
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ services:
networks:
- dev

blackpearl-db-initialize:
container_name: blackpearl-db-initialize
image: fabianoflorentino/blackpearl:0.1-linux-arm64
hostname: blackpearl-db-initialize
volumes:
- .:/app
env_file: .env
depends_on:
- blackpearl-db
networks:
- dev
entrypoint: ["/bin/sh", "-c", "bin/initdb"]

blackpearl-migration:
container_name: blackpearl-migration
image: fabianoflorentino/blackpearl:0.1-linux-arm64
Expand All @@ -38,6 +51,7 @@ services:
- .:/app
env_file: .env
depends_on:
- blackpearl-db-initialize
- blackpearl-db
networks:
- dev
Expand Down

0 comments on commit 9d9a3c3

Please sign in to comment.