Project

General

Profile

Actions

Patch #11615

closed

Database setup and reset

Added by Alexander Markelov over 11 years ago. Updated over 11 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Database
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:

Description

According to the RailsGuides: There is no need (and it is error prone) to deploy a new instance of an app by replaying the entire migration history. It is much simpler and faster to just load into the database a description of the current schema.

The patch includes the latest database schema in schema.rb and the required initial data in seeds.rb. These files allow to setup (and reset) database without running through the whole set of migrations using rake db:migrate command. Use the built-in rake db:setup and rake db:reset instead.

Note: the patch also changes svn:ignore property on db directory.


Files

db_schema_and_seeds.diff (30 KB) db_schema_and_seeds.diff Alexander Markelov, 2012-08-09 21:58
Actions #1

Updated by Jean-Philippe Lang over 11 years ago

  • Status changed from New to Closed

I can't find the ticket but it has already been discussed in the past. Maintaining schema.rb + seeds.rb in addition to the migrations set adds extra work/testing.

For example, running rake db:setup on your schema.rb with PostgreSQL raises an error. I guess it has been dumped from a MySQL database, right?

-- create_table("wiki_content_versions", {:force=>true})
NOTICE:  CREATE TABLE will create implicit sequence "wiki_content_versions_id_se
q" for serial column "wiki_content_versions.id" 
rake aborted!
PG::Error: ERROR:  type "binary" does not exist
LINE 1: ...id" integer NOT NULL, "author_id" integer, "data" binary, "c...
                                                             ^
: CREATE TABLE "wiki_content_versions" ("id" serial primary key, "wiki_content_i
d" integer NOT NULL, "page_id" integer NOT NULL, "author_id" integer, "data" bin
ary, "compression" character varying(6) DEFAULT '', "comments" character varying
(255) DEFAULT '', "updated_on" timestamp NOT NULL, "version" integer NOT NULL)

And running rake db:setup is in no way easier than running rake db:migrate IMHO.

Actions #2

Updated by Jean-Philippe Lang over 11 years ago

Found the discussion in the forums: You should commit db/schema.rb in the repo!.

Actions #3

Updated by Alexander Markelov over 11 years ago

Ooops! My mistake. I didn't check it with PostgreSQL. But any way, I think it's better to use `db:setup` instead of `db:migrate`. I will make a deeper analysis and give you my thoughts in the forums. Thanks.

Actions

Also available in: Atom PDF