rails-migrations

Can I delete all migration files and start from scratch?

蓝咒 提交于 2019-12-02 06:45:20
I have a Rails-API app that I'm going to re-deploy after a long time. The app is non-production, but I am ready to deploy the production version. I want to basically delete all the migration files and start from scratch using the schema, is there any problem with this approach? Assuming I can do this, what do I need to alter the schema.rb to? Is this a common practice? Seems reasonable to me. # what do I change the version param value to? ActiveRecord::Schema.define(version: 20171129023538) Migrations are used to update your database or to rollback to previous versions. Once migrations have

Is it safe to reorder columns in schema.rb for Rails 4/Postgres?

不羁岁月 提交于 2019-12-01 11:26:07
Running Rails 4 with Postgres 9.4 in development and production. I've got a large table that has grown by migrations over time. Because of the many different columns on the table, I want to reorder things so that the columns are grouped more logically. In other words, some column elements naturally group together based on what information they capture. I found a discussion on using after: in a migration to reorder columns (using ALTER TABLE in SQL), at this stack overflow discussion . I then went ahead and set up a migration to do that. After running the migration I notice that my schema.rb

Is it safe to reorder columns in schema.rb for Rails 4/Postgres?

北城以北 提交于 2019-12-01 09:34:26
问题 Running Rails 4 with Postgres 9.4 in development and production. I've got a large table that has grown by migrations over time. Because of the many different columns on the table, I want to reorder things so that the columns are grouped more logically. In other words, some column elements naturally group together based on what information they capture. I found a discussion on using after: in a migration to reorder columns (using ALTER TABLE in SQL), at this stack overflow discussion. I then

Rails: rake db:create:all (could not connect to server)

橙三吉。 提交于 2019-12-01 09:05:12
follow the screencasts http://railscasts.com/episodes/342-migrating-to-postgresql?autoplay=true up to the steps of "rake db:create:all" and get error: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"? refer the question on Rails: rake db:create:all fails to connect to PostgreSQL database but still unable to resolve it. Not sure what is the problem. [database.yml] development: adapter: postgresql encoding: unicode database: store_development pool: 5 username: amysukumunu password: test:

Will removing a column with a Rails migration remove indexes associated with the column

北战南征 提交于 2019-12-01 02:02:51
In Rails 2, will removing a column with a Rails migration also change/remove indexes associated with the column? If not, and instead you have to also change/remove each index manually, shouldn't it instead be automated? Thanks (from a Rails newbie) No, unfortunately you have to remove the index manually from within your migration using the remove_index method. enter08 From Rails 4 upwards, the index removes automatically with the column removal. To clarify, inside a migration the syntax to remove a 2 column index is the following remove_index :actions, :column => [:user_id,:action_name] or by

'Connect' a rails app to an already existing MySQL DB?

孤街浪徒 提交于 2019-12-01 01:43:05
So in my company we are slowly moving to Rails instead of PHP(Code Igniter to be precise). So, our actual PHP App is using a Mysql DB and I'd like to connect a new Rails app to this DB but meanwhile our PHP is still running, so I can't change the DB. I don't really know where I should start to use all the rails features (Or at least as much as possible). There shouldn't be any harm in connecting your rails app to an existing database. You will need to watch for anything that goes against rails conventions (table names are plurals of models, for example) and either change the database (and your

Database Specific Migration Code [duplicate]

萝らか妹 提交于 2019-12-01 01:13:39
This question already has an answer here: How do I check the Database type in a Rails Migration? 5 answers I'm creating an application that needs to run under multiple databases. I currently have some code in a migration that I only want run under specific databases (postgresql and mysql). Any way of setting this up? Thanks. Your migration has access to a database connection in connection and the connection has an adapter_name method so you can just ask it what sort of connection it is: def self.up case connection.adapter_name when 'PostgreSQL' # Do PostgreSQL stuff when 'MySQL' # Do MySQL

How do I disable the migrations feature in a Rails app?

别说谁变了你拦得住时间么 提交于 2019-12-01 00:58:48
Background We engineer database models and application models separately (RDMBS architects vs OOP engineers). From what I've seen regarding Rails versus domain/key normal form, Rails migrations cannot easily duplicate all the features of a well-designed enterprise RDBMS (if at all) so we don't migrate and instead use other tools to build databases (nevermind the problem of object-relational impedance mismatch). Data integrity and DB performance are too valuable to us to risk RDBMS model changes by any developer. Question For whatever reason, we now have a Rails app that has made damaging DB

Will removing a column with a Rails migration remove indexes associated with the column

不打扰是莪最后的温柔 提交于 2019-11-30 22:18:22
问题 In Rails 2, will removing a column with a Rails migration also change/remove indexes associated with the column? If not, and instead you have to also change/remove each index manually, shouldn't it instead be automated? Thanks (from a Rails newbie) 回答1: No, unfortunately you have to remove the index manually from within your migration using the remove_index method. 回答2: From Rails 4 upwards, the index removes automatically with the column removal. 回答3: To clarify, inside a migration the

Why can't I create an array as a column in a table in Rails?

泪湿孤枕 提交于 2019-11-30 21:01:11
Why can't I do something like this: class CreateModels < ActiveRecord::Migration def self.up create_table :fruit do |t| t.array :apples end end end Is there some other way to make an array ("apples) be an attribute of an instance of the Fruit class? Check out the Rails guide on associations (pay particular attention to has_many). You can use any column type supported by your database (use t.column instead of t.type ), although if portability across DBs is a concern, I believe it's recommended to stick to the types explicitly supported by activerecord. It seems kind of funny for fruit to have