Which database is used when play test? - scala

My application.conf:
### default #conf/evolutions/default/1.sql
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/test"
### test #conf/evolutions/test/1.sql
db.test.driver=org.h2.Driver
db.test.url="jdbc:h2:mem:play"
I run run command in play console, is db.default used?
When I run test command in play console, is still db.default used? How can I use db.test when I run test?
And when will conf/evolutions/default/1.sql and #conf/evolutions/test/1.sql be executed?

It will use the default database. Specifying the environment in the parameter key was a Play1 specific feature.

Related

Run init script on datasource devservice in quarkus?

I have a Quarkus project that uses a postgresql datasource. In production, we create the necessary schemas on the db manually before.
When I run quarkusDev mode and use the devservices, I therefor would like to run an init script on the testcontainer to create the schemas before liquibase does its migrations, which otherwise will fail.
I tried this without success
quarkus.datasource.jdbc.url=jdbc:tc:postgresql:13:///quarkus?TC_INITSCRIPT=testcontainer/schema-init.sql
quarkus.datasource.jdbc.driver=org.testcontainers.jdbc.ContainerDatabaseDriver
Nothing got picked up by the postgres testcontainer.
How can I run a init script on a datasource testcontainer with quarkus?
As stated here: https://quarkus.io/guides/databases-dev-services#database-vendor-specific-configuration
specific properties supported by the Testcontainers JDBC driver such as TC_INITSCRIPT, TC_INITFUNCTION, TC_DAEMON, TC_TMPFS are not supported.
So this simply does not work

Spring Boot: move command line arguments to property files

We are making mongodb connection with X509.
We have added below propertied in application.properties.
spring.data.mongodb.uri
spring.data.mongodb.host
But for keystore location and password we do not want to send using command line.
if we send using command line it works
but after removing it fails to start.
We set the property in SprintApplication class using #POstConstruct but that did not solved the issue.
Inject properties such as password using the jvm option or environment value.
Enter at run java
java -Dspring.data.mongodb.password=your_password ...
or Set MONGODB_PASSWORD to an environment variable.
spring.data.mongodb.password=${MONGODB_PASSWORD}
You can also encrypt using jasypt.
see https://www.jasypt.org

Loopback 4: Debug SQL Statements

I'm new to Loopback. I have used Sequelize ORM in the past, and I'm used to seeing Sequelize output the SQL statements to the Console. How can I do the same with Loopback 4? I've done extensive searching on the web, and I found a place where they suggested to add debug: true to the datasource config json file. However, this change had no effect.
Any help is greatly appreciated.
Hello from the LoopBack team 👋
We use debug module to deal with debug logging and most connectors print SQL statements in their debug log.
You can enable debug logs by setting the environment variable DEBUG. For example, on a Unix system (Unix, MacOS), you can run the following command:
DEBUG=loopback:connector* npm start
On Windows, you have to set the variable in a standalone command.
set DEBUG=loopback:connector*
npm start

MeteorJS: use mongo shell without building meteor app [duplicate]

I would like to find out how to connect to an external MongoDB instance in Meteor.
I have added this environment
Meteor.startup(function () {
process.env.MONGO_URL = 'mongodb://[UN]:PW]#[host]:[port]/meteorTest'
});
but still the data is coming from the local database.
I want to move all the collections from my local db to this external db. I read all the tutorials, its all telling me to setup this evn variable but nothing really working. How do I test whether its connected or not?
In my own experience; I have needed to set the environment variable before starting the meteorjs server app. To do this you will need to pass the environment variable on the command-line as you invoke meteor or preset the environment for the profile that is running the meteor app on your system.
So you would start your app with this kind of a command:
MONGO_URL='mongodb://user:password#remote.domain.com:12345/' meteor
You should also make sure that the mongodb is reachable and that your user credentials are correct! I am assuming you are trying to run meteor on your local machine using a remote mongodb instance.
On Windows
You will have to create a batch file in your meteor application folder to invoke the environment variable. There is an example of this here: https://stackoverflow.com/a/29833177/1997579
I don't like to use big repeating command and I was searching for a solution where I will be setting a variable embedded with something so every time I start my meteor app; the MONGO_URL will set to environment automatically. So this what I did:
In the package.json file I replaced the start parameter as below:
"scripts": {
"start": "MONGO_URL=mongodb://username:password#host_url:portnumber/dbname meteor run"
},
Now every time I want to run my app; I run npm start instead of meteor or meteor run
Note: there is a disadvantage with that. Your db credentials will be exposed if you put your db credentials to package.json file and add this file to version control.
run it in command prompt:
"MONGO_URL=mongodb://<USER>:<PASSWORD>#<SERVER>:<PORT>/<DB> meteor"
or
save this url in run.sh file in project folder and run meteor
On windows, I set MONGO_URL in my system's environment variable and it worked fine for me.
I have created a new environment variable and it's value as MONGO_URL=mongodb://username:password#host_url:portnumber/dbname
And in path variable, I have added %MONGO_URL%
Then in meteor app root folder, I have run $meteor

Run Evolutions in Command Line

It's my first day tinkering with the Play framework, and I'm having a hard time with evolutions. I'm using Play 2.4.
I picked a sample app from the many that come up in activator ui, it uses play-slick and play-slick-evolutions for DB connection and evolutions.
I've perused the docs, but I can't seem to find a way to run the evolutions from the command line. When I run activator on bash I get thrown into a shell, and the help doesn't bring up anything about running evolutions, or slick.
I've been doing PHP for a while, so I'm used to being able to run these up/down from the command line. I can drop the tables from the database client and do activator run which should prompt me to run the evolutions, but I'm looking for the right, manual way to do this. I imagine it's possible since it would need to be done on deploy.
As far as I know, they are not designed to be run manually. In development, Play asks you to run them:
In Production I trigger the evolutions by starting my server with the parameter -DapplyEvolutions.default=true. You can write this (without -D of course) also to the application.conf-file to run them always. You can also use only the down- or up-evolutions with -DapplyUpEvolutions.default=true or -DapplyDownEvolutions.default=true.
And of course there is always the option to just copy the part of the script you need manually and apply it with your favorite database tool. However, you then need to tell Play what you did by manually altering the table play_evolutions. An easier solution then would be to not use the evolutions mechanism provided by the Play Framework at all.
A quick hack that works for me and doesn't involve bringing up a play instance:
export PGPASSWORD=<password>
for SQL_FILE in $(ls <path-to-evolution-files>); do
psql -h localhost -U <username> -c "$(sed '1,/Ups/d' <path-to-evolution-files>/$SQL_FILE | sed -n '/Downs/q;p')";
done
Removes everything up to and include Ups and everything after and including Downs, and runs the commands on the Postgres instance.