winton / acts_as_archive

Don't delete your records, move them to a different table
MIT License
372 stars 87 forks source link

error in sqlite3 #14

Open yangjiandong opened 13 years ago

yangjiandong commented 13 years ago

use jruby1.6rc1,rails3.0.1,activerecord-jdbcsqlite3-adapter,in migrate use: ActsAsArchive.update Post it show: AlsoMigrate error: ActiveRecord::JDBCError: near "LIKE": syntax error: CREATE TABLE archived_posts LIKE posts;

echarp commented 13 years ago

It seems you need to add parenthesis around the sql "like xxx".

It's related to "also_migrate", see https://github.com/echarp/also_migrate

mjbeauregard commented 13 years ago

It seems that: CREATE TABLE

LIKE is not supported by sqlite. I also see this sqlite related commit from a fork https://github.com/foolabs/acts_as_archive/blob/b1b57e16b238602d25ee9bcdd0ca073519a9a037/require.rb.

Putting parens around the like clause allows the migration to proceed, but my schema.rb ends ups with the following comment:

# Could not dump table "archived_apps" because of following StandardError
#   Unknown type 'apps' for column 'LIKE'

Looking at the database itself, I see that sqlite is treating LIKE as a column name:

sqlite> select * from sqlite_master where name = 'archived_apps';
select * from sqlite_master where name = 'archived_apps';
table|archived_apps|archived_apps|45|CREATE TABLE archived_apps
                  (LIKE apps, "deleted_at" datetime)

This problem is not specific to jruby as my development environment is a stock rails 3.0.3 project.

It seems very odd that this projects seems fairly sophisticated and somewhat mature yet fails so miserably out of the box. How could this not work in the default rails dev environment? Seems like I must be missing something.

Any hints would be fabulous.

mjbeauregard commented 13 years ago

Looking at the code more closely, I worked around the borked table creation by specifying the :indexes option: acts_as_archive :indexes => [:id] which forces the code through a slightly different path to make it work.

Now the migration will actually create the archive tables, but the next problem is that records are deleted from the origin table and never actually created in the archive table.

winton commented 13 years ago

Hey guys, thanks for looking into this. I am going to look into getting the specs running in SQLite this weekend. If anybody makes it there before me, it would be much appreciated.