Skip to content

Commit 6ffea21

Browse files
Merge pull request #87 from RodrigoMNardi/hotfix/debian12
Correct argument usage in YAML.safe_load_file
2 parents 776d3b8 + 42f9304 commit 6ffea21

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,55 @@ In addition to the gems listed above, we need these to run the tests locally:
4444
- ruby-rspec
4545
- ruby-webmock
4646

47+
# Database Configuration
48+
49+
This document provides instructions on how to configure the database for the GitHub Hook Server project.
50+
51+
## Prerequisites
52+
53+
Ensure you have the following installed on your system:
54+
- PostgreSQL (any version)
55+
56+
## Configuration Steps
57+
58+
1. **Install PostgreSQL**:
59+
Follow the instructions for your operating system to install PostgreSQL. You can find the installation guide on the [official PostgreSQL website](https://www.postgresql.org/download/).
60+
61+
2. **Create a Database**:
62+
After installing PostgreSQL, create a new database for the project. You can do this using the `psql` command-line tool or any PostgreSQL client.
63+
64+
```bash
65+
RAKE_ENV=development psql -c "CREATE DATABASE github_hook_server_development;"
66+
```
67+
3. **Configure Database Connection**:
68+
Update the `config/database.yml` file with the database connection details. You can use the following configuration as a template:
69+
70+
```yaml
71+
development:
72+
adapter: postgresql
73+
encoding: unicode
74+
database: github_hook_server_development
75+
pool: 5
76+
username: postgres
77+
password: password
78+
host: localhost
79+
port: 5432
80+
```
81+
82+
Replace the `username`, `password`, `host`, and `port` values with your PostgreSQL connection details.
83+
84+
4. **Run Database Migrations**:
85+
After configuring the database, run the database migrations to set up the necessary tables and schema.
86+
```bash
87+
bundle exec rake db:migrate
88+
```
89+
90+
5. **Verify the Configuration**:
91+
Start the application and verify that it can connect to the database without any errors.
92+
```bash
93+
RAILS_ENV=development rackup -o 0.0.0.0 -p 9292 config.ru
94+
```
95+
4796
# Usage
4897

4998
### Production

database_loader.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,22 @@
88
#
99
# frozen_string_literal: true
1010

11+
require 'active_record'
1112
require 'otr-activerecord'
1213

14+
module OTR
15+
module ActiveRecord
16+
class << self
17+
alias original_configure_from_file! configure_from_file!
18+
19+
def configure_from_file!(file)
20+
config = YAML.safe_load_file(file, permitted_classes: [Symbol], aliases: true)
21+
::ActiveRecord::Base.configurations = config
22+
end
23+
end
24+
end
25+
end
26+
1327
OTR::ActiveRecord.db_dir = 'db'
1428
OTR::ActiveRecord.migrations_paths = ['db/migrate']
1529
OTR::ActiveRecord.configure_from_file! 'config/database.yml'

0 commit comments

Comments
 (0)