C
C
caution2014-06-07 14:21:32
PostgreSQL
caution, 2014-06-07 14:21:32

What is the correct way to use PostgreSQL in Rails?

There is a rail project and a PG database. A test branch was created based on the development branch, in which migrations to the database were made. After deleting this branch without merging it into the development branch, all changes from the test branch remained in the database, and when trying to create tables in the development branch that were in the test branch, it gives an error about the existence of such a table.
As far as I understand, the reason is that the PG database is not located in the project's db/ folder, and is not tracked by git.
How to properly organize everything to avoid such problems?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Kirill Platonov, 2014-06-07
@caution

The standard way to work with PG in development with branches that have a different database structure is:
At the same time, do not forget to add the minimum set of database records necessary for development in db/seeds.rb
And if you want to simplify life, then install zsh and a plugin for rake, rails and use aliases:
rdd; rdc; rdm; rds

V
Viktor Vsk, 2014-06-07
@viktorvsk

the reason is that the PG database is not in the project's db/ folder, and is not tracked by git.

Understand how postgres (mongo, macuel) works without ruby ​​and RoR. Then - how they differ from sqlite
Then get used to never manually climb into db/migrate and schema.
Understand what migrations are and how they are stored in the database (and why you need them in your project in the db/migrate folder, written in ruby)

S
Sergey Toy, 2014-06-07
@Toy

Manually delete these tables (whose migrations occurred in another branch). Or if you need them along with the data and you have migrations written for them in development, then you can manually mark these migrations as completed in the schema_migrations table .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question