AlchemyCMS / alchemy_cms

Alchemy is the Open Source Rails CMS framework for the component based web that can be used as classic server side rendered or headless CMS.
https://www.alchemy-cms.com
BSD 3-Clause "New" or "Revised" License
846 stars 315 forks source link

Upgrading from 2.7 to 3.0 causes user data loss #440

Closed robinboening closed 10 years ago

robinboening commented 10 years ago

I just upgraded an existing app running with alchemy 2.7 to rails4 and alchemy 3.0.

Running the migrations (i.e. from the upgrader) the alchemy_users table is being dropped. That means we loose all our user data.

Considering this migration will also run on a production server, we loose all the users there.

I spent some time of thinking on this issue and I think I came to a good solution.

It would be better to remove the alchemy_users table creation from the merged migration. Additionally to remove the migration that drops the alchemy_users table. On alchemy-devise side we just have to upgrade the roles column if the table exists and we have a legacy-column.

That changes mean we will let an existing alchemy_users table untouched, but we would never create a new one. This is important to support all three ways of using Alchemy 3.0:

  1. In a new created Alchemy 3.0 app. With the change I mentioned above, there is no alchemy_users table created.
  2. Within an upgrade from an older alchemy version. There is an existing alchemy_users table and its important that it still exists.
  3. Alchemy is newly mounted into an existing app. With the change I mentioned above, there is no alchemy_users table created.

I have prepared the mentioned changes, but its not 100% completed yet and needs some love. I will send a Pull request tonight or tomorrow.

tvdeyen commented 10 years ago

Yes, we should definitely remove the user table creation and removal migrations from alchemy core (alchemy_cms).

The alchemy-devise gem then should only create the alchemy_users table if the table does not already exist. A second migration in the alchemy-devise gem then needs to add the necessary roles columns to the alchemy_users table.

That should do the trick.

robinboening commented 10 years ago

Merged PR: https://github.com/magiclabs/alchemy_cms/pull/441 Merged PR: https://github.com/magiclabs/alchemy-devise/pull/1