diff --git a/README.md b/README.md index 7d0381d..3eb9a2a 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,55 @@ In addition to the gems listed above, we need these to run the tests locally: - ruby-rspec - ruby-webmock +# Database Configuration + +This document provides instructions on how to configure the database for the GitHub Hook Server project. + +## Prerequisites + +Ensure you have the following installed on your system: +- PostgreSQL (any version) + +## Configuration Steps + +1. **Install PostgreSQL**: + 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/). + +2. **Create a Database**: + After installing PostgreSQL, create a new database for the project. You can do this using the `psql` command-line tool or any PostgreSQL client. + + ```bash + RAKE_ENV=development psql -c "CREATE DATABASE github_hook_server_development;" + ``` +3. **Configure Database Connection**: + Update the `config/database.yml` file with the database connection details. You can use the following configuration as a template: + + ```yaml + development: + adapter: postgresql + encoding: unicode + database: github_hook_server_development + pool: 5 + username: postgres + password: password + host: localhost + port: 5432 + ``` + + Replace the `username`, `password`, `host`, and `port` values with your PostgreSQL connection details. + +4. **Run Database Migrations**: +After configuring the database, run the database migrations to set up the necessary tables and schema. + ```bash + bundle exec rake db:migrate + ``` + +5. **Verify the Configuration**: + Start the application and verify that it can connect to the database without any errors. +```bash +RAILS_ENV=development rackup -o 0.0.0.0 -p 9292 config.ru +``` + # Usage ### Production diff --git a/database_loader.rb b/database_loader.rb index a75a2cf..52ba544 100644 --- a/database_loader.rb +++ b/database_loader.rb @@ -8,8 +8,22 @@ # # frozen_string_literal: true +require 'active_record' require 'otr-activerecord' +module OTR + module ActiveRecord + class << self + alias original_configure_from_file! configure_from_file! + + def configure_from_file!(file) + config = YAML.safe_load_file(file, permitted_classes: [Symbol], aliases: true) + ::ActiveRecord::Base.configurations = config + end + end + end +end + OTR::ActiveRecord.db_dir = 'db' OTR::ActiveRecord.migrations_paths = ['db/migrate'] OTR::ActiveRecord.configure_from_file! 'config/database.yml'