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.
Related
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
I need some help to consume another .yml file that complement the original one in the application. Then I have a file filled by me(dev) however some configuration(as database infos) should be inserted by our clients.
The one which is in the application(application.yml) have general configs, the other on path C:\Users\Public\ datasource.yml have:
spring:
datasource:
platform: postgres
driverClassName: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/mydb
username: foo
password: bar
Has anyone done this before?
configure the below annotation at your main configuration class
#PropertySource("classpath:datasource.yml")
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.
I've just enabled query caching on my symfony application using the following configuration:
Doctine cache config
doctrine_cache:
providers:
cache:
namespace: '%cache_namespace%'
chain:
providers:
- array_cache
- redis_cache
- file_cache
redis_cache:
namespace: '%cache_namespace%'
predis:
host: "%redis_host%"
port: "%redis_port%"
password: "%redis_password%"
timeout: "%redis_timeout%"
array_cache:
namespace: '%cache_namespace%'
array: ~
file_cache:
namespace: '%cache_namespace%'
file_system:
directory: "%kernel.cache_dir%/application"
Doctrine ORM config
orm:
auto_generate_proxy_classes: "%kernel.debug%"
entity_managers:
an_entity_manager:
connection: connection
mappings:
AppBundle: ~
naming_strategy: doctrine.orm.naming_strategy.underscore
metadata_cache_driver:
type: service
id: "doctrine_cache.providers.cache"
query_cache_driver:
type: service
id: "doctrine_cache.providers.cache"
result_cache_driver:
type: service
id: "doctrine_cache.providers.cache"
I'm also having functional tests that populate a local sqlite database instead of the real one. What I'm seeing is the following:
Every time I run my tests, I see the Redis cache creating new keys even for identical records. I'm guessing this must be because the database gets re-created before every test gets executed, and the contents of the newly created rows don't matter as far as caching is concerned, but I can't be sure.
Does anyone know if this expected behaviour?
You should disable Redis (and all unecessary external dependencies) in you test environment. This could be done overriding your configuration in the test env, using the in-memory cache only.
To read more abound environments and configuration, you can look into the Symfony docs: http://symfony.com/doc/current/book/configuration.html#environment-configuration
I am trying to cf push this code from this github repo after running mvn package, but I get a failed app deployment.
I have created a user defined service for mysql since cleardb is not available on my bosh-lite local vm. I created the mysql service and named it as 'mysql' as well as guided by this.
The application.yml in this spring boot app points to localhost. That doesn't work even for a local (non cf) build without corrrecting the jdbc url. Here is the stack trace from the bosh-lite vm when I try to cf push this app and read the logs using cf logs springpong --recent.
Also, why do we need both, the manifest.yml and the application.yml providing database details ?
vagrant#vagrant-ubuntu-trusty-64:~$ cat pong_matcher_spring/src/main/resources/application.yml
---
spring:
datasource:
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost/pong_matcher_spring_development
username: springpong
password: springpong
jpa:
hibernate.ddl-auto: none
show_sql: false
vagrant#vagrant-ubuntu-trusty-64:~$ cat pong_matcher_spring/manifest.yml
---
applications:
- name: springpong
buildpack: java_buildpack
path: target/pong-matcher-spring-1.0.0.BUILD-SNAPSHOT.jar
services:
- mysql
vagrant#vagrant-ubuntu-trusty-64:~$
Can someone help me fix this ?
TIA
This was happening as the security groups were not setup to allow for network access. A sample gist of commands can be seen here -> https://gist.github.com/menicosia/2e9c414430138064f945
Caveat: This is only for bosh-lite and development purposes.