i'm building rails 3.2 app upon legacy database has broken records in different tables. 1 of issues giving headache includes invalid dates.
i've setup sandbox manually fixed 1 time code working. it's time deployment. reason, sandbox reset every night , copied live database, ferret indexes rebuilt, , migrations re-applied. going deploy sandbox in last fixes before deploying live setup.
as legacy php app , new rails app need run in parallel few weeks months, cannot one-time-fix dates (update: clarification, means run on same database @ same time). need way automate this, maybe migration or rake task (i'd go latter).
but problem is: activerecord chokes on loading such records have no way investigate record , fix dates hardcoded assumptions made in ruby code.
a second problem legacy database has inconsistencies because php code did not use transactions , code paths broken , left orphans , broken table constraints behind. deal occur, of them taken care of in models. first problem goes dates.
how fix this? maybe there's magic gem out there supports migrating legacy databases broken records intercepting exceptions , running try-to-fix code...
the migration path uses mysql, , 3 production environments (stable live database, staging same database, , sandbox database clone reset every night). decided against doing one-time data mapping / migration because cannot replace complete legacy application in 1 step (it consists of cms 50000 articles, hundreds of topics, huge file database images , downloads, supporting 10 websites, 12 years of data , work, messy php code different programming skills, duplicated code different migration stages, pulling in rss content partner sites mix articles/posts there article timelines in our own application's topics, , lot more fun stuff...
first step migrate backend application consistent admin , publishing interface. legacy frontend applications still need write database (comments , other content created visitors). process of fixing database must able run unattended on regular basis.
we have fixes in place gracefully handle broken model dependencies in belongs_to , has_many. paperclip integration has been designed work fantastic filename mappings invented. , airbrake gem reports application crashes our redmine installation quick overview of left quirks.
the legacy applications have been modified work latest mysql version , has been migrated current mysql database server.
i had same problem. solution tell mysql2 not perform casting, this:
client.query(sql, cast: false).each |row| row['some_date'] = date.parse(row['some_date']) rescue(nil) end
see mysql2 documentation details on how build client object. if required, access rails db config via activerecord::base.configurations
.
Comments
Post a Comment