How to use a Postgres DataBase to develop with JHipster? - postgresql

My problem is that I'm new in JHipster. I can construct a basic application using the H2 disk persistance method to develop and it works fine, but when I try to build a new project using the Postgres db as development method, and I configure de database attributes in the application-dev.yml file, it just doesn't work, I can't even log in.
Can anyone help me with this?
Here is the fragment of the application-dev.yml file where I configure the access db. Of course I've already created the database (ControlAcceso), but it's empty, I thought the tables creation will be automatic, please correct me if I'm wrong.
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:postgresql://localhost:5432/ControlAcceso
username: postgres
password: root
hikari:
poolName: Hikari
auto-commit: false

If you are able to use docker you could add testcontainers when using psql also in dvelopment to get similar experience like using h2 https://atomfrede.gitlab.io/2019/05/jhipster-with-testcontainers/

Related

I can't connect to my DB. (PostgreSQL, Spring boot, JHipster)

I have a little issue. I was working on the dev mode in Jhipster with H2.
And now I'm trying the prod mode but there's an issue with the connection to the PostgreSQL server. I'm using pgAdmin4.
It says that the password can't be null and if I put a password it doesn't like to.
Its the first running, so I imagine that the application create the DB. Am'I wrong?
I'm new on Spring boot & JHipster.
Its the standard configuration.
there's the configuration:
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:postgresql://localhost:5432/KoseCleaning
username: KoseCleaning
password:
hikari:
poolName: Hikari
auto-commit: false
Edit:
Errors:
Without password:
Caused by: java.lang.IllegalArgumentException: Null value for 'password'
With password :
Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "XXX"
Thanks in advance.
The app does not create the db nor users, you must do it. Liquibase only creates the objects (tables, indexes, ...) in an existing schema.
As a side note, I'd recommend not using H2 in dev, rather use same db as in prod with testcontainers profile generated by JHipster to discover problems earlier and get access to the full power of your database rather than limiting you to a subset supported by H2.

Ansible 2.2 Create Postgresql Database

I am new to ansible (2.2.1) and have started to migrate from our fabric scripts to ansible which I find somewhat better regarding structure. I have run into an issue, it should be pretty straight forward but since I do not know ansible through and through I am not sure how to proceed. I am running this against a vagrant box as of now.
The issue is regarding user privileges and postgres.
Lets say I have this playbook
- hosts: web
become: yes
become_user: root
vars:
dbname: myapp
tasks:
- name: ensure database is created
postgresql_db: name={{dbname}}
I cannot make this simple example work! All dependencies are met. If I do the same thing with mysql this works fine but here I get issues with unable to connect to database: FATAL: Peer authentication failed for user "postgres".
In mysql I use the "root" user with a blank password, which works because I know that user is created upon install with a blank password.
There is a user postgres created when the installation of postgresql is completed so the user exists. And as root I should be able to login by saying I am the postgres user. Am I missing something in how this is done? It works just fine if log into the server and sudo -su postgres && psql.
I also tried to add become_user: postgres by the task I want to run but then I get unprivileged user issues.
Any ideas of what is missing?
Found a few workarounds and a solution, given you are ok with giving away some security (which makes sense, this being an issue just for that reason).
More people having this problem with the new ansible in this github issue thread
https://github.com/ansible/ansible/issues/16048
What I ended up doing was settings allow_world_readable_tmpfiles = True in the ansible.cfg file. Then this is not an issue anymore but you get warnings. I only need this setting for when handling the postgres role, so maybe I'll end up split it up or putting the setting somewhere less global.

Connecting Postgresql db with Sails.js

I am brand-new to Sails and I'm looking to build my first application in javascript land! I am currently trying to connect my sails application to a postgresql database and I want to make sure that I am doing this correctly.
I started by creating a postgresql db with dbName, userName, password. I have added all this information into my connections.js file:
somePostgresqlServer: {
adapter: 'sails-postgresql',
host: 'localhost',
user: '<username>', // optional
password: '<password>', // optional
database: '<databasename>' //optional
}
I want to be sure I can migrate and perform all operations on my own so my models.js is set to migrate: safe. I ran npm install sails-postgresql. Now, to my understanding if I have migrate set to safe I will need the sails-db-migrate module (https://github.com/building5/sails-db-migrate). I followed this module step by step. I generated a User model by running sails generate api user. After this I ran grunt db:migrate. After all this, I check my psql database and no User table has been created. I know there is something I am missing, or maybe there is a more simple way to see if my postgresql db is connected.
Any advice or suggestions on how I should approach this would be greatly appreciated.
I was able to connect my PSQL DB to my application by simply:
creating db in psql
configuring it in sails app/connections.js
running npm install sails-postgresql
Adding to config/env/development.js:
models: {
connection: 'somePostgresqlServer'
}
running sails generate api user
sails lift
When asked for migration mode I chose options 2 which is alter
Opened up psequal and sure enough there was my new user table.
I'm not sure which of these actually triggered it to working from adding my db name to development.js, leaving off a PW on my DB, or changing migration mode to alter. But these steps helped it to connect. Will look further into.

sailsjs on Heroku not creating model in postgresql

I am trying to use sails.js on Heroku. When I push my changes, the application starts, but when I try to run MyModel.find() methods, I receive an E_NOTFOUND error. When I log into the database with psql, I see that the tables have not been created automatically. I have the policy in models.js set to migrate: 'drop', so shouldn't I at least get empty tables made when I launch the application? Is there something going on on Heroku that it doesn't like me running sails?
edit:
I had previously been putting settings in development.js and production.js that were different settings (heroku postgresql settings in production). I took that out, and put the settings in connections.js, and it seems like I am able to do the queries and such on the Models, however, when I do heroku pg:psql to connect to my database, I don't see the tables if I do "select * mytable;" it tells me no relation is found.
I believe the problem was that even though I had separate settings for development or production databases, when NODE_ENV was set to production, sails defaults to "safe" and will not let you change it to alter or drop - silently. Changing NODE_ENV to something else allowed the tables to be created.

Mongoid: How to create separate database for every user in Rails 3.2

I am working on a new Rails application with MongoDB. Here I want to create a separate database for every user who registers into the application.
I am trying to create the database like this, here is my mongoid.yml configuration:
staging:
host: localhost
database: mongoid_<%= #user.username%>
Please help me to create separate database for every user in MongoDB.
I would prefer you to use separate collections for each registered user instead of separate dbs. But if you insist so use Moped session explained in this link http://mongoid.org/en/moped/docs/driver.html#behaviour