2👍
If you hate on Migrations, try going NoSQL. No migrations!
So you’d just add properties to your document when you need them. In your code, handle the fact that they may not exist and bam!
I took the following model definition (notice you don’t inherit form activerecord) from a blog about tekpub Also recommend the Herding Code podcast
class Production
include MongoMapper::Document
key :title, String, :required => true
key :slug, String, :unique => true, :required => true, :index => true
key :description, String
key :notes, String
key :price, BigDecimal, :numeric => true
key :released_at, Date, :default => Date.today
key :default_height, String, :default => '600'
key :default_width, String, :default => '1000'
key :quotes, String
#royalty info
key :producers, String
timestamps!
end
1👍
Try the auto_migrations plugin. I don’t think it’s a bad idea for development, but I would switch to migrations after going to production when there is critical data in the database.
You may also be interested in replacing ActiveRecord with DataMapper, which works in Rails 3. It has the style you are talking about, with the description of the data fields of a model in the model code instead of a separate database schema file.
- [Django]-How do I treat django's TemporaryUploadedFile as a regular python file
- [Django]-Renderer returned unicode, and did not specify a charset value
- [Django]-Django, getting url parameter into view
- [Django]-Django.db.utils.NotSupportedError: FOR UPDATE cannot be applied to the nullable side of an outer join
- [Django]-How to use django-bootstrap3
1👍
I think DataMapper is what you are asking for. Once set up, you’d either use DataMapper.auto_migrate! or DataMapper.auto_upgrade!. The former will drop tables if they exists before creating them, thus destroying any data. That would be bad for production. The latter is how you avoid losing data, and should be just fine for production.
Without knowing exactly what its doing, I’d guess it’s inspecting tables during startup to determine whether to make database changes. That can drag down start up time, especially with a lot of models/tables. Which is actually one of the good reasons to consider NoSQL – specifically Mongo as mentioned above. It’s fast. Really fast, and thus the start up cost is much, much less. MongoMapper is the way to go. The tekpub blog post is a must read.
I first heard about DataMapper in reading about Merb, so it makes sense that it’s in rails 3. I don’t know whether you may be able to get it working in rails 2.x.