rake db:create:test
rake db:build
rake db:rebuild
The first creates your test database. The second, creates your
development database, migrates it, creates the test database and then
clones the development database to the test database.a
Lastly, the third drops your database (dev), creates it, migrates it,
and clones it for your test database.
For a few projects, I've gotten tired of doing: rake db:drop && rake
db:create && rake db:migrate && rake db:test:clone
link: http://dev.rubyonrails.org/ticket/10316
What do you guys think, +1's?
--
Posted via http://www.ruby-forum.com/.
rake db:test:clone clones your test database from your schema (same as
rake db:reset - from schema)
I prefer to have a test database up from the get go (which is why I have
it in rake db:build) and when I remigrate.
The reason I prefer migrations over the schema is that I usually have
some data in my migrations, e.g. admin user, that I'd like to have
setup. I'm sure I'm not the only one who has some data in the
migrations.
The rake db:create:test came about because I wanted to have rake
db:build and have my test database setup(with the current schema). You
can't do rake :build => ["rake db:create RAILS_ENV=test"], it will fail
and rake db:create:all will create all databases defined in your yaml
file - I didn't want that either.
Those were my reasons why these came about and why I've been using them
for a while now. Am I missing something or doing something here that
shouldn't be done?
--
Posted via http://www.ruby-forum.com/.
I think, it does make sense to run migrations in the continuous
integration loop (but not in the local build). Reason: you want to
test them, but you don't want to slow down the local build. A fairly
common practice is to use 001_initial_schema migration as the only
migration on the project for as long as there is no valuable
production data to preserve.
> But it seems that this misuse of migrations highlights something that might be lacking: a data seeding system.
Yup. Another common practice is db/dataload.rb, a script of
ActiveRecord operations to put some data into the database, with the
corresponding db:dataload Rake task. Using AR and domain to create
this data is much easier than doing the same thing with YAML-based
fixtures.
--
Alexey Verkhovsky
CruiseControl.rb [http://cruisecontrolrb.thoughtworks.com]
RubyWorks [http://rubyworks.thoughtworks.com]
Mephisto uses fixtures in a special db/bootstrap dir, and inserts them
with a db:bootstrap task. db:bootstrap includes schema:load and the
custom data. Though I agree that doing this in ruby would be
simpler...
--
Rick Olson
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com
I'm not sure the "continuous" that Alexey was referring to was the CI
process (as in: it is always running), or a repeated run of every
migration each time the test suite is run.
The former certainly makes sense; you'd want to test that a migration
can successfully run based solely on the contents of the SVN
repository and other expected artefacts; verifying that it won't fail
because a developer has failed to commit or add a particular file
before you try and run that migration on the production system.
That is, you'd want to test that any new migrations don't cause a
system failure - not that every migration can be run, each time the CI
system runs against a new build.
--
* J *
~
Granted that my case may be one of few. With that said, what do you
think about my proposed rake tasks, minus the db:test:clone? That way,
we can build the test db with a rake task, and can rebuild from
migrations as well? Or am I still off the mark?
--
Posted via http://www.ruby-forum.com/.
+1
I would like to see a way to test migration, especially those
involving substantive changes to the data, in the framework. And
being able to run them against a large enough dataset, preferably a
copy of the production database. But I don't see testing migrations
being the same thing as running test cases against the test database.
Assaf
Would something like the Scenarios plugin solve your problem?
http://faithfulcode.rubyforge.org/docs/scenarios/
--
John Long
http://wiseheartdesign.com
> Again, I think this is a mistake and it was certainly not what
> migrations were designed for. They lead to all the pains and problems
> you're describing with migrations.
>
> I fully realize that people are misusing migrations in this way
> because they were missing a seed system and just grabbed something
> that had the same vague outline. But I think the problem then is to
> consider how to best do seeding. Not to twist migrations into a seed
> system.
I'm one of the people misusing migrations in this way, and a seed
system could fulfill part of the problem, but not all of it.
I often use migrations for creating data that needs to be present in
every environment. For example, a new account in an accounting table.
I want to add that to an existing production application without
reloading all of the data. By including it in a migration, I'm sure
that it will exist in the database of every developer, our integration
environment, and finally production. It keeps me from having to track
down data bugs.
Of course, the fact that I also have to encode that data into my
fixtures isn't very DRY. I'd love to have some way of specifying the
data only once, I just don't have any brilliant ideas about how to do
it.
[snip]
Mike Mangino
http://www.elevatedrails.com
IMO, I'd love to see a seed system that mimics migrations a bit and
keeps the standard AR syntax that we are used to: Person.create(...).
http://svn.robertrevans.com/plugins/data_tasks/
Let me try to explain.
* there is no up-to-date development environment on the continuous
integration box
* but I do want to rebuild the database from scratch in every CI
build. From what?
* if I use db/schema.rb, I am relying on an artefact that was
automatically generated in somebody's development environment. Which
is not how it will be done in production. I also cannot expect
everybody to always pay attention when checking-in auto-generated
artefacts.
* running all migrations then looks like a better choice.
> Once everyone has been moved, the migrations are useless and could essentially be deleted.
Yeah, having many migrations floating around is awkward, too. One can
take schema dumper output and make a new baseline migration out of it,
with the same number as the DB_VERSION in the last prod release.
Yes, dropping the db and migrating everything is the sensible approach in CI.
> * if I use db/schema.rb, I am relying on an artefact that was
> automatically generated in somebody's development environment. Which
> is not how it will be done in production. I also cannot expect
> everybody to always pay attention when checking-in auto-generated
> artefacts.
Right. In general, I think it's bad practice to check in generated
artifacts. It's more work for everyone to remember to check in when
they change the schema. It's error prone and people often forget to
check in, which means the CI build breaks and you waste time figuring
out what broke, who forgot to check in, and blaming them. Better to
just always run the migrations in CI and svn:ignore schema.rb.
> * running all migrations then looks like a better choice.
>
> > Once everyone has been moved, the migrations are useless and could essentially be deleted.
> Yeah, having many migrations floating around is awkward, too. One can
> take schema dumper output and make a new baseline migration out of it,
> with the same number as the DB_VERSION in the last prod release.
Yep. Speeds up CI and clean DB setups too if there are fewer
migrations. If there were something to automate the collapse of
migrations into a schema dump up to a given version, that would be
great. It's easy to do manually, but it would be a nifty rake task
for someone to publish.
-- Chad