Migration issue


#1

I was following this set of instructions from the “Cookie overflow?”
thread:

Your sessions (by default in cookie) needs to be moved to Active record
store or memcache store to fix this issue.

For Databased sessions:
config.action_controller.session_store = :active_record_store
You need to create the session table as below
rake db:sessions:create
rake db:migrate

I added the config line to environment.rb; is that the approriate place?

When I ran the migration, I got

rake aborted!
An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: table “artists” already exists: [etc]

So I removed the existing, populated database (to a safe place, since I
do not want to have to create it again unless necessary) and ran the
rake db:migrate again…clearly there is something I don’t understand
because most sane people would want to preserve the contents of an
existing db when they modify it.

Now I have a problem, because of course the new (empty) database has an
extra table in it. Before I go and write a ruby script to create a
database containing my old records + the new table as it appears in
schema.rb, is there not a simpler, more sensible way to do this?

If I do have to remake the db manually, can anyone answer a questions
for me regarding the session table: Does it also use a column “id” as
the INTEGER PRIMARY KEY? I suppose it won’t matter if it doesn’t and I
put one in anyway…


#2

On Wed, May 27, 2009 at 7:34 AM, Mk 27
removed_email_address@domain.invalid wrote:

because most sane people would want to preserve the contents of an
existing db when they modify it.

Erm, so maybe the most appropriate (“sane”) thing to do at that
point would be to figure out why you’re (apparently) repeating a
migration that’s already been done?

Just sayin’ … :slight_smile:

Hassan S. ------------------------ removed_email_address@domain.invalid


#3

This would suggest that the migration you were running was attempting to
add
the artists table. I think this is nothing to do with rake
db:sessions:create. Have a look in the migration made by the rake to
see
what it is doing. I imagine that you have an earlier migration that
created
the artists table and for some reason that is running again.

Colin

2009/5/27 Mk 27 removed_email_address@domain.invalid


#4

And check the schema_migrations table in the database. Maybe an older
database was restored from a backup for some reason.


#5

Also, check the schema_migrations table in your database to see what
migration it thinks you last ran.


#6

Hassan S. wrote:

On Wed, May 27, 2009 at 7:34 AM, Mk 27
removed_email_address@domain.invalid wrote:

because most sane people would want to preserve the contents of an
existing db when they modify it.

Erm, so maybe the most appropriate (“sane”) thing to do at that
point would be to figure out why you’re (apparently) repeating a
migration that’s already been done?

There was an existing database, yes, I thought that was clear. The
reason I did it again was (also clear if you can read, but to repeat)
because I wanted to move the session store to Active Record so I was
following this instruction:

You need to create the session table as below
rake db:sessions:create
rake db:migrate

Which I am grateful for that advice, because it worked; but I did have
to create the db manually (because I want it populated, and already have
a script to do that), add the session table myself (to the
aforementioned script), and insert it back in. So I guess I don’t get
the point of the migration thing yet: is it more for people who don’t
want to create a db themself, or what?

Nb, this is my second casual week using rails. If all I want to do is
add a table to the database, why would it want to rebuild the whole
thing, ie, why not just add the new table and leave the existing tables
alone? I presume there is away to do this and I haven’t read enough of
the API docs yet. Is this going against “the convention”, hence I
needed to do some more “configuration”?


#7

On Wed, May 27, 2009 at 3:35 PM, Mk 27
removed_email_address@domain.invalid wrote:

There was an existing database, yes, I thought that was clear. The
reason I did it again was

Yes, yes, entirely clear, and totally irrelevant to the issue.

Which I am grateful for that advice, because it worked; but I did have
to create the db manually (because I want it populated, and already have
a script to do that), add the session table myself (to the
aforementioned script), and insert it back in.

No, you didn’t - that’s the whole point :slight_smile:

So I guess I don’t get the point of the migration thing yet:

Apparently – so, seriously, read up on migrations before you go any
further. You’ll save yourself a lot of headaches down the road.


Hassan S. ------------------------ removed_email_address@domain.invalid


#8

Hassan S. wrote:

nothing of interest to me either

Thanks for your non-advice!

:wink:


#9

On Wed, May 27, 2009 at 4:03 PM, Mk 27
removed_email_address@domain.invalid wrote:

nothing of interest to me either

Thanks for your non-advice!

Where did I say that? Must be some cross-talk in your mail client :slight_smile:


Hassan S. ------------------------ removed_email_address@domain.invalid


#10

2009/5/27 Mk 27 removed_email_address@domain.invalid

migration that’s already been done?
Which I am grateful for that advice, because it worked; but I did have
the API docs yet.
You have hit the nail on the head here, that is exactly what migrations
will
do for you (ie “add the new table and leave the existing tables alone”)
in
addition to other things of course.

Colin


#11

Mk 27 wrote:

Hassan S. wrote:

nothing of interest to me either

Thanks for your non-advice!

:wink:

Hassan gave you some excellent advice. Read it again – and this time,
if you want to learn, I suggest that you ask instead of hurling insults.
(I also suggest that an apology to Hassan might be in order, but that’s
between you and him.)

Best,

Marnen Laibow-Koser
http://www.marnen.org
removed_email_address@domain.invalid