How to transfer development database to production? - database

I made a Sinatra app and now I'm trying to deploy it to Heroku.
My app works with PostgreSQL database. There is data in my tables that I scraped during development. It is rendered just fine when I run it locally. However, when I deploy my app, my records do not get transferred. I know this behavior is normal, but I can't find how to transfer my records to production (database is set up correctly, you can add content through forms interactively).
This is my environment.rb:
configure :production, :development do
db = URI.parse(ENV['DATABASE_URL'] || 'postgres://localhost/lakesare')
ActiveRecord::Base.establish_connection(
:adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
:host => db.host,
:username => db.user,
:password => db.password,
:database => db.path[1..-1],
:encoding => 'utf8'
)
end
I have tried
heroku pg:push $my_db_name HEROKU_POSTGRESQL_OLIVE_URL
and it ran successfully, but my records are still not present in production db. Did I do something wrong?
I would use seeds.rb kind of thing, but how to configure it in Sinatra?

If you had a seeds file you could do heroku run ruby seeds.rb. That is assuming that the seeds file is in the root of your application. You can run pretty much any command that you can run locally on the heroku servers by prepending it with heroku run.

The only solution that worked for me is to write a few functions that fill up your database, add them to seeds.rb in db folder, deploy this to Heroku and run
heroku run rake db:schema:load
heroku run rake db:seed

Related

Configure Postgre DB in docker project

I'm very new to docker and docker-compose things. I have tried to use Kiwi TCMS open source project which supposed to use with Docker.
My question is can I run the projects on docker on the same server, I'm supposed to configure my development and production sites on the same server (CentOS)?
I'm following the below link to install docker and configure the kiwitcms application for the first time, I read the basics about the docker and how its working and all.
https://kiwitcms.readthedocs.io/en/latest/installing_docker.html#
I want to use PostgreSQL as my Database, but the existing latest docker image has MariaDB. So after I pulled latest version of kiwitcms from docker hub using the following command,
docker pull kiwitcms/kiwi
Should I change to "docker-compose.yml" file db image value, and save it to a local new directory,
https://raw.githubusercontent.com/kiwitcms/Kiwi/master/docker-compose.yml
[![enter image description here][1]][1]
Also there can we edit use our own DB name, user name passwords right?
then execute the following command.
docker-compose up -d
I'm very new to this model and read most of the articles related to docker, but this leads me few of these doubts, hence asking for these clarifications.
Thanks,
Karthik.
The web app and the DB server are 2 different images (aka 2 different servers). For example how we use Postgres in testing see:
https://github.com/kiwitcms/Kiwi/blob/master/docker-compose.postgres

Heroku and Rails issue; database not working in production mode

I'm having an issue when deploying my app to Heroku. The page works flawlessly in local mode (localhost:3000), but when I visit the same page with heroku, I get a "We're sorry, but something went wrong." error.
The heroku logs states the following:
ActionView::Template::Error (undefined method `name' for nil:NilClass)
The code in the controller:
def week
#bestbuy = Retailer.find_by(name: "bestbuy")
end
The code in routes.rb:
match '/week', to: 'static_pages#week', via: 'get'
The code in the view:
<%= #bestbuy.name.upcase %>
I ran the following commands:
git commit -a -m "message"
git push heroku
heroku run rake db:migrate
heroku restart
heroku open
I do have the gem 'rails_12factor' in my Gemfile
Any help appreciated. Thanks!
The find_by method will return nil if no records are found that match the condition (docs). In this case it looks as though your production database contains no retailer with the name "bestbuy".
I'd start debugging this by looking directly in the database to check that it contains the data you're expecting (see https://devcenter.heroku.com/articles/heroku-postgresql#using-the-cli for how to do this with Heroku).

Heroku. Django. South. Database column does not exist

I am new to Heroku. I just migrated my django models using south:
sudo heroku run python manage.py migrate
I get the message "Nothing to migrate" in all of my six apps.
Then when I try to visit the website I get the error:
ProgrammingError "column X does not exist".
Everything works fine locally. What should I do, drop the database and recreate it again? If that is the answer, how do I do that on Heroku?
Thanks for you help.
To drop the database on heroku, run:
heroku pg:psql
as per https://devcenter.heroku.com/articles/heroku-postgresql#pg-psql.
Then do:
drop database <database name>;
create database <database name>;
Then you can try and run your migrations again.

Heroku database push operation

To load a database which runs now on the my computer, SQL Server 2012 and Windows, I have installed Git Bash, taps and Heroku.
Now, whenever I wrote the command
heroku db:push --app myapp
it gives the same error
Invalid database ur
I think I miss something, I have not declared which database should be pushed to the Heroku.
Can you help me with this problem ? how can I use heroku db:push, are there any other steps like creating something ? Why I get this error ? Maybe you will say that "have you read documentation or have you searched google?", Yes
EDIT: What I have know is
Local database
Server name Heroku database
Database name application name
username | or windows authentication postgres database
password | username and password
aws address
Should I put/load some file/gem into the Git ?
EDIT 2:
I have test this command but it gives other error.
heroku db:push postgres://localdbUSERNAME:localdbpassword#localdbDATABASENAME/localdbSERVERNAME --app myapp
Error
Failed to connect to database:
Sequel::AdapterNotFound -> LoadError: cannot load such file -- pg
Heroku db:push does not work with SQL Server, it works with MySQL and/or Postgres. You'll need to switch to running one of these database servers, run your migrations/seeds and then use heroku db:push to push your local database to Herokul

Google App Engine: How to perform a remote deploy to dev app server?

I am in the process of setting up a "QA environment" for my GAE app. This QA environment will simply be a small server on my home network with a dedicated IP address. I'm writing an Ant script to check the project out of my SVN repo, build it on my build server, and then deploy it "remotely" (across my home LAN) to the QA app server.
With Tomcat, I would just scp the web archive to the machine's webapps/ directory, and since it can be configured to hot-deploy, that is all I usually need for a QA deploy.
But I'm new to GAE, and so I'm not seeing how I can achieve such a remote deployment via Ant. The best I can think of (although somewhat convoluted) would be:
Checkout and build the WAR on the buildserver, like I normally would
scp the WAR to a staging directory, somewhere on the QA machine; say 192.168.1.55:/opt/gae/staging
Have a lightweight RESTful web service running on that machine (maybe hosted by Tomcat or Jetty) listening for a client to hit a certain API, say http://192.168.1.55:8080/GaeRemoteApi/deploy; when the request handler gets a request for this URL, it kicks off a shell command to copy the WAR into the correct directory and then execute appcfg.sh -upload to actually deploy the WAR to my QA app server
I'm pretty sure I could get this working within a day or two, but was wondering if the GAE ships with an easier (baked in) solution; or if a fresh set of eyes can think of something even simpler. Thanks in advance!
I think you should just keep it simple:
Since you are on Ubuntu, you can write a shell script that will:
ssh to the remote server
stop the current gae dev appserver
rename the existing war directory
scp the new deployment to the QA server war directory
ssh to the QA server and start the gae dev appserver
You can call a shell script from ant using: http://sumedha.blogspot.com.au/2008/06/how-to-call-shell-script-from-ant.html
To stop the dev appserver:
killall -e ./appengine-java-sdk/bin/dev_appserver.sh
To run the dev appserver:
nohup ./appengine-java-sdk/bin/dev_appserver.sh you/war/directory &
Run the development server?
https://developers.google.com/appengine/docs/java/tools/devserver

Resources