Heroku with H2 Database - spring

This is related to running Craig Walls Spring Social Showcase on Heroku. This application runs fine locally using an H2 in memory database. When I deploy to Heroku, however, the database no longer works. Is there something else that needs to be configured on the Heroku server to get the in memory database to run?

To my knowledge there is no H2 support on the Heroku server. So you can't use H2 as an in memory database.
You can get a list of supported databases here
I would recommend you to use Postgres as a database. This is a good starting point.

Related

Replicate H2 in-memory database to postgresql (and vice versa)

I have a Java Spring project which does a lot of database reading. The database I have available is a shared postgresql database on a remote machine and it's quite slow to get data from it, especially when I'm doing a lot of back-and-forth.
When I'm doing local testing and development, I use the embedded H2 in-memory database. Things easily go 100 times faster.
This made me wonder. Is there a way to use the embedded H2 in-memory database so that:
Data manipulation (INSERT, UPDATE, DELETE) is ("eventually") replicated to the PostgreSQL database
Upon start/restart of the Spring project, the H2 database is automatically filled with the data of the PostgreSQL server
This would allow me to use the fast H2 to provide a seamless user experience while at the same time also storing the data in a longer-term data storage. In a way, I'd be using the H2 as a fully cached version of the PostgreSQL database.
Is there a known / standardized way to approach this? Google for H2 and PostgreSQL and replication gives me results on transitioning from one to the other, but I'm not finding much as to using one as a sort of cache for the other.
I remain on the lookout for a Spring / JPA / Hibernate focused answer, but if none comes: I may have found an alternative domain to investigate. Dedicated database replication software might be able to manage this. Specifically, I've discovered SymmetricDS, which seems (I've only given the documentation a cursory glance) like it might be able to be embedded into my Spring application, do an initial load of my embedded in-memory H2 database on startup and then trickle feed data changes to the remote database.
(I'm not in any way affiliated with SymmetricDS, it just looks like it might be a solution.)

Ruby & SQLite & Heroku & PostgreSQL

I've a simple Sinatra application which I've developed using SQLite. The database is a simple two-column table: an ID and a string entry.
I would like to deploy this app to Heroku. What's the least painful way to convert an SQLite database to PostgreSQL, understanding that PostgreSQL is required to deploy to Heroku.
For simple use cases heroku db:push will push your local sqlite database into your Heroku Postgres database.
It's worth considering then switching to using Postgres locally and then use heroku db:pull to bring the database back from Heroku to your new local postgres instance.
I'll caveat to say that whilst heroku db:pull works for SIMPLE databases once you start using more complex Postgres datatypes then you need to use something like heroku pg:transger which is Postgres > Postgres only.
Use the taps gem, as shown in this Railscast.
First you'll want to install Postgres on your local machine so you can make changes and easily deploy to heroku. Second you'll want to migrate from SQLite to Postgres. I just did the migration for my own Rails app following Heroku's instructions and it took less 5 minutes. Seems simple enough.
The instructions to migrate are here (even has instructions on installing Postgres locally). Then you can follow the Heroku getting started guide for the rest.

Some help regarding Postgres on Heroku

i have just started working on an application in PHP. I have configured the Postgres add on in my application on Heroku. But i am still not sure how to start working on the DATABASE. what i mean is that there is a thing called DATACLIP on the POSTGRES DB window on Heroku and when i try to create a table there, it gives me some weird errors.
But no matter what query i write there, it always gives me some error. So, i am not sure whether i can create the Tables and insert my data from DATACLIP or not. and If not, from where can i do this?
Dataclips are only useful for read-only queries. Think gist for SQL and data.
To create data on your database, you can:
Use database migrations that run within the heroku platform itself
Connect to your database using the provided credentials from anywhere (you must use SSL). To get credentials, either run heroku pg:credentials <DATABASE_COLOR> --app <YOUR_APP>, or go to your database in http://postgres.heroku.com. You should be able to use pg_admin or any other postgres front end to connect and create tables.
You can connect directly using the heroku toolbelt (and assuming you have a proper psql installation in your dev box) with heroku pg:psql --app <YOUR_APP>. From there just use SQL to create your data (CREATE TABLE, etc)

Can't use PSQL with a Heroku shared database

I'm developing an application and hosting it on Heroku. For now, I want to use the free shared database solution.
My problem is that I can't access the database.
$ heroku pg:psql
! Cannot ingress to a shared database
I've read elsewhere that I can't connect to shared databases via psql.
I can't seem to find any information on that on Heroku's Dev Center, so this leaves me with the question - how can I edit or change or do anything with my database?
If you're happy to use a beta addon then there is the Heroku Shared PostgreSQL 9.1 addon (https://addons.heroku.com/heroku-shared-postgresql) which will permit you to ingress to your database.
However, any changes to your database are usually best done with scripted migrations (in the Ruby on Rails world) rather than connecting to your database to make changes.
If you're more familiar with mySQL then there are a number of mySQL addons which permit direct access also with normal mySQL tools.

Embedded or managed Oracle instance for integration tests

For MySQL, the MXJ connector makes it very easy to launch a managed MySQL instance.
I know that Oracle provides Oracle XE for quick setup, but I've only found an RPM distribution that needs to be installed. Is there a neatly packaged jar that I can just drop in the classpath and start up by calling a specific JDBC url, a la HSQLDB or MXJ?
I'm interested in having developers use this locally for running tests, as well as on our continuous integration server.
The short answer is No. Oracle is a big meaty chunk of database. Amongst other things, it generally expects itself to be run by its own special user rather than the client user.
For simplicity, your best bet is a separate DB server with each of your developers having their own username/password (and hence their own independent schema) in the database.
Although Oracle does not provide an embedded database, spinning up a local Docker container running Oracle XE might be an ideal way to accommodate Oracle-specific local integration tests. Since Docker containers are ephemeral in nature by design, the database could also be completely torn down as desired providing clean sandboxing.
The alexeiled/docker-oracle-xe-11g image on DockerHub I found has particularly clear setup and documentation instructions: https://hub.docker.com/r/alexeiled/docker-oracle-xe-11g/
After spinning up the Docker container, be sure to:
First connect to the APEX web console, login, as per the instructions
Then open Oracle SQL Developer and select Reset Password... first. Otherwise the following error may be thrown java.lang.ArithmeticException when attempting to get connection in Oracle 11.2.0.2.0 (64 bit)
As the documentation describes, the docker run command can also be designed to automatically run SQL scripts on the container's startup, which could also be very valuable in the CI/integration testing workflow.
Hope this helps!

Resources