ruby sequel in sinatra framework add postgres schema search path - ruby

I have a sinatra service that reads from postgres and we changed the postgres schema of those models. How can I set the schema path.
In rails and active record you can do as follows:
performance_tracking:
adapter: postgresql
encoding: utf8
database: db_name
username: my_user
password: pass11121212
host: 172.30.1.12
schema_search_path: my_new_schema
So I am trying to do the same using sequel
But it ignores the field of schema_search_path
How can I set the schema_search_path for postgres

Related

How to connect Spring Boot application to a Postgres database that's in a Docker container

I'm working on a Spring Boot application and it has to use a database. I can run the database locally and connect to it without problems but now I'm trying to run just the database in a Docker container and connect to it with my Spring application and I can't get it to work.
This is the docker-compose file that is used to start the docker container with the postgres image
version: '3.8'
services:
db:
container_name: postgres-container
image: postgres:14.1-alpine
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
- POSTGRES_DB=shop
ports:
- '5432:5432'
volumes:
- db:/var/lib/postgresql/data
volumes:
db:
driver: local
This is the application.yml file
spring:
datasource:
url: jdbc:postgresql://localhost:5432/shop
username: postgres
password: password
This is the V1.0__init.sql file used to initiate a table in the database
CREATE TABLE IF NOT EXISTS igredient(
id SERIAL PRIMARY KEY NOT NULL,
name VARCHAR(50) NOT NULL,
price INTEGER NOT NULL,
is_healthy BOOL NOT NULL,
type VARCHAR(10)
);
I tried connecting to the database with DBeaver in the following way (can't upload an image):
Host: localhost
Port: 5432
Database: shop
Authentication: Database Native
Username: postgres
Password: password
Advanced:
Local Client: PostgreSQL 14
When I test the connection I get this "FATAL: database "shop" does not exist" and I don't understand what I'm missing. I have been googling for too long and I don't have a clue what else to do.
I tried running the Spring application but I get this error:
org.postgresql.util.PSQLException: FATAL: database "shop" does not exist
and this:
Message : FATAL: database "shop" does not exist
Also DB Browser in Intellij is giving me this error in the V1.0__init.sql file (I guess because I'm not connected to a database):
Invalid or incomplete statement
expected one of the following:
BITMAP CONTEXT DIRECTORY EDITIONABLE EDITIONING FORCE FUNCTION INDEX MATERIALIZED MULTIVALUE NO NONEDITIONABLE OR PACKAGE PROCEDURE PUBLIC ROLE SEQUENCE SYNONYM TRIGGER TYPE UNIQUE USER VIEW

Unable to create database with ActiveRecord from script

The commands I run:
config['development']
=> {"adapter"=>"mysql2", "encoding"=>"utf8mb4", "collation"=>"utf8mb4_bin", "pool"=>1, "username"=>"root", "password"=>nil, "host"=>"localhost", "database"=>"my_db"}
ActiveRecord::Base.establish_connection(config['development'])
=> #<ActiveRecord::ConnectionAdapters::ConnectionPool:0x007fe20592b348 ...
ActiveRecord::Base.connection.create_database(config['development']['database'])
ActiveRecord::NoDatabaseError: Unknown database 'my_db'
It says unknown database but I am actually trying to create the database with create_database and I follow the docs:
https://apidock.com/rails/ActiveRecord/ConnectionAdapters/PostgreSQLAdapter/create_database
Why is it not working?
Given database.yml:
database.yml
default: &default
adapter: mysql2
encoding: utf8mb4
collation: utf8mb4_bin
pool: 5
username: root
password:
host: localhost
development:
<<: *default
database: my_db
test:
<<: *default
database: my_db_test
I got it working by establishing a connection without the database and then creating the database:
#config = YAML.load(File.open(File.expand_path('../../lib/my_gem_config/database.yml', __FILE__)))
ActiveRecord::Base.establish_connection(config['default'])
ActiveRecord::Base.connection.create_database(#config['development']['database'])
When creating a database in postgres it will use a "template" database to make a copy. I haven't read the source code on how ActiveRecord::Base.connection.create_database actually works and if it indeed does the same. I was able to create the database with your code except that for my config hash I merged: database: 'postgres', schema_search_path: 'public' and that seemed to do the trick. In my case 'postgres' is my template database.

No configuration could be found for a session named 'dummy'

I have created a new session under staging in mongoid.yml as:
staging:
sessions:
dummy:
database: dummy_db
hosts:
- ipaddress:27017
default:
database: "dummy_db2"
hosts:
- 127.0.0.1:27017
options:
raise_not_found_error: false
And accessing two mongo instances using this method. But its giving error
Mongoid::Errors::NoSessionConfig:
Problem: No configuration could be found for a session named 'dummy'
on runtime. Its working fine for default case.. but couldn't find dummy session.
Here is my mongo class
module Mongo
class test
include Mongoid::Document
store_in session: 'dummy'
Please help anyone.

gitlab community unable to login

I followed the directions here https://github.com/gitlabhq/gitlab-recipes/blob/master/install/centos/README.md and have the gitlab community page up and running but I cannot login.
Someone suggested doing this:
bundle exec rake db:seed_fu RAILS_ENV=production
(in /home/git/gitlab)
I got a FATAL error suggesting no role for root, I then followed this:
FATAL: role "root" does not exist
and created a role, now I get this error:
[root#gitlab gitlab]# bundle exec rake db:seed_fu RAILS_ENV=production
== Seed from /home/git/gitlab/db/fixtures/production/001_admin.rb
rake aborted!
ActiveRecord::StatementInvalid: PG::Error: ERROR: permission denied for relation users
: SELECT 1 AS one FROM "users" WHERE "users"."email" = 'admin#example.com' LIMIT 1
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/seed-fu-2.3.1/lib/seed-fu/runner.rb:46:in `eval'
[root#gitlab gitlab]# sudo -u git -H cat config/database.yml
#
# PRODUCTION
#
production:
adapter: postgresql
encoding: unicode
database: gitlabhq_production
pool: 10
# username: git
# password:
# host: localhost
# port: 5432
#
# Development specific
#
development:
adapter: postgresql
encoding: unicode
database: gitlabhq_development
pool: 5
username: postgres
password:
#
# Staging specific
#
staging:
adapter: postgresql
encoding: unicode
database: gitlabhq_staging
pool: 5
username: postgres
password:
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test: &test
adapter: postgresql
encoding: unicode
database: gitlabhq_test
pool: 5
username: postgres
password:
Please help. I do not know ruby and I also don't know postgresql

Running both MongoDB and Mysql on Rails 2.3.6

In Rails 2.3.6 I'm trying to use both MongoDb via MongoMapper and Mysql on the same application.
I've seen several others question about this but I cannot find how to configure rails to use both database in the same app.
How should I configure my database.yml file?
Right now it is:
development:
adapter: mysql
encoding: utf8
reconnect: false
database: blinddog_development
pool: 5
username: root
password:
socket: /tmp/mysql.sock
test:
adapter: mysql
encoding: utf8
reconnect: false
database: blinddog_rails_test
pool: 5
username: root
password:
socket: /tmp/mysql.sock
production:
adapter: mysql
encoding: utf8
reconnect: false
database: blinddog_rails_production
pool: 5
username: root
password:
socket: /tmp/mysql.sock
Should I add some intializers?
Thanks in advance,
Augusto
So you would use active record and standard database.yml file. You would also run rails g mongo_mapper:config to create your mongo.yml file. These are seperate and should allow you to use both in your model. This would work for mongoid too.

Resources