removing postgres database on ubuntu from commandline - ruby-on-rails

I am working on a rails app. Due to some messing up with the code I deleted the app from my local development machine and cloned the previous commit from the git repo.
Now i want to delete the db file(postgres) of the deleted one from the local machine as well. I had issues in the past that made me unable to access several features due to database conflicts(due to same db name). So i fixed that by removing the database and recreating with the cloned app. I had done it before from commandline but i forget now on how to do it. Could some one tell me where is the postgres database file located in ubuntu or how to remove from commandline? Thanks in advance.

There is a postgresql shell command dropdb which you can use.

After a bit of searching i found that doing this will remove the database. From the commandline just cd into your app directory and run this command
rake RAILS_ENV='development' db:drop
This will remove the database(although am still unable to find the exact location where its stored physically in hard drive). This is the solution if you cant access rails console, or some rake commands.
After that we can just recreate the database using
rake db:create

Related

rails db migrate locally-Multiple migrations have the version number

I'm using docker, and I'm trying to run migrations locally using
docker-compose run app rails db:migrate
I'm getting an error though:
Multiple migrations have the version number 20211230114441.
I tried searching for this migration in db/migrate but nothing's there. I also tried checking out different versions of schema.rb but this fixed nothing.
Since I'm running using docker, and even though, my files are attached to a volume, I tried using docker-compose build before running again to make sure that the migration files are udpated. Again fixed nothing.
Any ideas on how this can be fixed?

Heroku missing last 4 migrations. Migration files do exist in Git

Heroku is missing the last 4 migrations for a RoR app. The files exist in the git repository and are named/numbered accordingly. I tried manually forcing that version to run, but it simply can't find it. I tried this:
heroku run rake db:migrate:up VERSION=20190328183515
and the result was
ActiveRecord::UnknownMigrationVersionError: No migration with version number 20190328183515
Trying to redeploy from local to heroku stage does nothing since it states everything is up to date. I tried touching the files in case they weren't included in the deployed files, but looking at the git repository confirmed that's not the case.
Any ideas on what's going on here and how to get heroku to recognize that it is missing 4 migration files that still need to be processed? Resetting the database is not an option. I tried rolling back the database and running the migrations again but it stops on the migration file for 3/27/2019

Rails - Cant run any rake commands db is messed up

Everything was working fine yesterday and all of a sudden when i tried to run my server or run any rake tasks i get this error
Mysql2::Error: Table 'myapp_development.key_value_stores' doesn't exist: SHOW FULL FIELDS FROM `key_value_stores`
I've tried google searching and searching on stackoverflow all morning and cant find a solution to this
Try to rollback your migration file (take backup of the migration file will help while creating new ),
rake db:migrate:down VERSION=migrations's_version
and then try to restart the rails server.If you face same problem then with same migration number search in schema_migrations table in database delete that record and make new migration again.
I was struggling with this for a while but what i ended up doing
update xcode and update command line tools
uninstall then install mysql via homebrew
then i ended up manually removing my database folder in
usr/local/var/mysql/myapp
then i did a
rake:create
and then i just pulled my production database and copied it to my development database
rake db:backup_and_load
then I was up and running again
dont know which one of that fixed it specifically but thats what i did

how to relaunch rails app on heroku

My app runs properly locally and has a crash when it runs on Heroku. The app does fine until I run a new_post_path call. I tried git push to see if a change to the new.html.erb file or the _form.html.erb file was the issue - but I think during the last push to heroku - my database may have taken a hit. At the time I was adding a t.text field (longtext) and it seems to be the issue.
So I wanted to roll back or totally re-start at heroku. But I have not found anyway to do it. Since this is not near production yet. Is there anyway to just create a new instance at heroku and push up to it?
Again, local version runs perfect. Thanks in advance for any ideas.
I would say there are several ways to handle this problem
restarting heroku
Run $ heroku restart in the rails dir. Sometimes I believe in magic.
debugging
Use $ heroku log to debug what is causing the error.
migrate database
Perhaps you made a database change in local rails, while heroku rails didn't.
Run heroku run rake db:migrate
drop database and remigrate database
See this thread. Sometimes old migration might be in conflict with current migration. Do a clean migration, if the data in your database isn't important.
recreate heroku instance
run $ heroku apps:destroy –app appname and replace appname with your appname. Then delete the current heroku remote repository location from git. git remote rm heroku. Then recreate heroku. run $ heroku create. go through pushing your code and migrating database like usual.
Relaunching might be the least of your problems, so I suggest a few things:
Review this Heroku article on releases, including the Heroku rollback feature.
Add the PG Backups add-on to your app.
I also recommend using something like the exception_notification gem in combination with the SendGrid add-on, so that you can get an email with details on the error as well.

How to push a Git update for my Rails app on DotCloud.com without loosing the SQLite prod db

This could be a noob problem but I couldn't find a solution so far.
I'm developing a Rails app locally that uses SQLite, I've set up a local Git repo, and the dotcloud push command is using this. Locally I use the dev environment and on DotCloud it automatically uses the prod env, which is great. The problem is that each time I do a push my prod db on DotCloud gets lost, no matter how minor the changes are to the codebase, and I have to run 'rake db:migrate' to set it up again. I don't have a prod db locally, only the dev and test dbs.
Put your DB in ~/data/ as described here and create a symbolic link at deploy time:
ln -s ~/data/production.sqlite3 ~/current/db/production.sqlite3
You should not have your SQLite database file in version control. If you had multiple developers it would conflict every single time somebody merges the latest changes. And as you've noticed, it will also be pushed up to production.
You should add the db file to .gitignore. If it's already in version control, you'll probably have to git rm the file first.
The problem is that every time you deploy, the old version of your deployed app is wiped, and replaced with the new code, and your sqlite db is usually within your app files. I'm not a dotcloud user I don't know it it works, but you can try to setup a shared folder, where you put the production database on the server, which is outside of your rails app.
Not really sure how git is setup on DotCloud.com, but I'm assuming there is a bare repo that you push to and another repo that pull from the bare when a suitable git hook has been executed. You need to find out if you can configure that last pull to use the ours merge strategy.

Resources