Following on from my previous post (carrierwave image not loading into source code), I've added a new column (feature_image) to my table portfolios.
I would like to push this to my Heroku app however I already have a number of portfolio entries on the website that I don't want to lose.
Is there anyway I can push my database changes without losing the content already on there?
Thank you!
pushing it will not affect your records (unless you have some special code that resets the db each time you do a push - never heard of such cases, but who knows), only new migration will be executed to add new column so you'll end up having lots of portofolios with no image.
rails app saves all migrations numbers into schema_migration table in db, so next time you'll run a migration it will migrate only the ones that are not in schema_migration.
in my case if I'll run migration only 20140109214830_add_is_new_to_messages will be migrated as its number is not schema_migration, it works this way on local machine and the same when pushing.
after migrating it, migration number will be saved into schema_migration table (line 44):
git push heroku master && heroku run rake db:migrate && heroku restart
Related
I'm working on a migration using Sequelize. If the migration up method throws an error, the migration is not logged in the database as having completed. So, if I run db:migrate:undo, it instead runs down on the previous (and working) migration. As a result, I have a half executed migration where the schema for it remains in the database because the corresponding down method is never run by Sequelize. So, I need to either somehow force a single down method to run (which I'm not seeing an option for). Or, I need to manually clean up my database every time I run a failing migration, which can be a real pain for complicated migrations where I'm constantly going through trial and error. Is there an easier way to doing this?
sequelize db:migrate:undo --name 20200409091823-example_table.js
Use this command to undo any particular migration
manually insert the migration into your migrations table so that sequelize will think it has completed.
To verify check the status of your migrations before and after you edit the table.
db:migrate:status
Everything listed as "up" is something that can go "down" and vice versa.
There is no way to do it as of now... There is an open issue for this in Sequelize cli repo
I tried something and it worked for me:
rename your migration file and make sure it comes first alphabetically (make it the first one in migration files)
comment code in the second migration file
run sequelize db:migrate
This will run only the first migration file.
Don't forget to uncomment the migration file you commented before
In one of our apps db:migrate is not set to automatically run on every deploy to Heroku. It hasn't been Continuously Integrate yet.
We've ran into an issue and for debugging purposes I want to see when a particular migration ran.
Is this possible?
Rails does not give such feature, when you run migration, time_stamp of migration is added in an array , to remember which migration is executed and which is not.
so what you can do is , log in to your database (psql if using postgres) and find created time or updated time of table manually .
this may help you do so https://stackoverflow.com/a/11868687/1970061 .
sometimes when working in rails, I work on several things at once using git branches
sometimes, I'd like to test new ideas by implementing them and testing how and if they work accordingly. This involves sometimes adding models and migrations.
When switching branches, however, the migrations were already migrated to the DB and they stay, causing problems later on..
Is there a way to work with several branches and each to have different migration files, and before starting to work on a branch to "soft reset" the db only to the current migration files without losing data?
Normally, in development, I need some sample data that I keep in seed.rb which enables me to recreate the db, its structure and the sample data with a rake task.
Another thing I did was to keep more than one database. I would then just manually change the entry in database.yml according to the current git branch.
I'm working on an application which uses data from db which has to be populated prior to the application being able to run. What I have to do is to populate few tables with few thousand rows but I'm not sure how I would do that in heroku because I have limited access to db for loading data.
What is the preferred way to do this?
Regards,
Johann
You can populate a Postgres database locally and then push it to heroku with heroku db:push see heroku help db:push
You may want to look into seeds, there's also a Railscast. I've never used this before, so you may alternately want to…
Create a rake task to suit your specific need. That way you can add the task to your Rails application and run heroku rake mytask. Here's a rake tutorial, and a Railscast on rake tasks to help get you started.
My app is in beta, and I've been doing limited testing of a feature that involves a new model. After a fair amount of testing I had to make a structural change that makes the old data non-functional.
What I need to do is just drop and recreate one table. I know that I could do this in a migration, but that seems like such a hack. In a local dev copy I would just use db:reset, but in the beta app I don't want to lose data in any tables except this one.
Is this a simple way to instruct a production app to drop and recreate a single table. In my case, I'm deploying with Heroku, in case that affects how you would solve this issue.
To empty a table on Heroku without changing the schema, in your application's directory:
$ heroku run console
Ruby console for myap.heroku.com
>> ModelName.delete_all
>> exit
I know that I could do this in a migration, but that seems like such a hack.
It's not a hack. It's precisely what migrations are designed to do.
You need to rerun the migration for that table to make structural changes. I haven't used ActiveRecord before, but I'd also delete the data in the table using ModelName.delete_all from heroku console.
heroku run console
irb(main):001:0> ModelName.delete_all
And you are done.