From b727e5375ce3f52daf5afcfb33906e5c7963c7bf Mon Sep 17 00:00:00 2001 From: Rodrigo Nardi Date: Mon, 5 Aug 2024 08:47:43 -0300 Subject: [PATCH 1/2] Database Doc Adding a basic doc to use configurate the database Signed-off-by: Rodrigo Nardi --- README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) 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 From 17f17f1f99642e9465e53c39a0cd11fa2f9581f1 Mon Sep 17 00:00:00 2001 From: Rodrigo Nardi Date: Mon, 5 Aug 2024 10:06:32 -0300 Subject: [PATCH 2/2] fix: correct argument usage in YAML.safe_load_file - Updated the `configure_from_file!` method to use `YAML.safe_load_file` with the correct arguments. - Ensured `ActiveRecord::Base.configurations` is set properly. Signed-off-by: Rodrigo Nardi --- database_loader.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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'