database setup for ocra compiled rails app

573 views Asked by At

I'm trying to package a rails (3.2) app to run on a windows machine and I'm using OCRA to 'compile' the app into an exe. After repeatedly banging my head on my desk I've managed to get the app to compile and run, but I have one problem remaining; The database for the app is also packaged inside the .exe so while the app runs and functions (new records can be created and retrieved) it is only temporary, when the exe is stopped any changes to the database are lost.

So I guess what I need to do is have the database external to the app so it will be external to the exe. But I haven't managed to make that work. I've tried changing the database path in database.yml to several different values but nothing I've tried works. The examples I've seen for connecting to an external database all show the connection being to a remote host and not for a local file.
What I want is the database file to be in the same folder as the exe.

The compiled app runs in production mode, this is the ocra command I used to build the exe;

ocra myapp\script\rails myapp --add-all-core --gemfile myapp\Gemfile --no-dep-run --gem-full --chdir-first -- server -e production

The database.yml is basically as it was after creating the app

production:
  adapter: sqlite3
  database: db/production.sqlite3
  pool: 5
  timeout: 5000

I've tried setting database: to just production.sqlite and ../production.sqlite and then placing the database file in the same folder as the compiled exe before running it but that hasn't worked.
I've very unfamiliar with setting up different databases so I'm sure that I'm missing some key point here!

1

There are 1 answers

0
Sujimichi On BEST ANSWER

I finally found the answer to this in a google-groups discussion about another ORCA related question, it just happened to include the database.yml config that I needed.

To have the database external to the OCRA compiled exe, such that the database file resides in the same directory as the .exe, set the database: parameter in database.yml to this;

<%= File.expand_path('../production.sqlite3', ENV["OCRA_EXECUTABLE"]) %>

My compiled app runs in production mode so this is now how that part of my database.yml looks;

production:
  adapter: sqlite3
  database: <%= File.expand_path('../production.sqlite3', ENV["OCRA_EXECUTABLE"]) %>
  pool: 5
  timeout: 5000

This works perfectly now, I can run the app.exe make a new entry in the DB and then terminate app.exe. When I run app.exe again the changes to the data are still there.