Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug affecting sqlite3 date fields: Date columns are now converted to YYYY-MM-DD format #77

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

brianmeidell
Copy link

Dumping from MySQL and loading to sqlite3 was failing for me.

Sqlite3 doesn't have native date formats (afaik), so rails deals with that by storing dates as iso8601 (YYYY-MM-DD HH:MM:SS etc) in sqlite3.

It turns out it was because dates would get dumped from mysql to the yaml file in a format like "Mar 23, 2015", which then got imported straight into sqlite as a string. This made a lot of rails date handling silently and subtly fail, because rails seems to rely on lexical ordering of date fields to work.

This commit fixes that problem, by adding the same type of conversion as happens for booleans - it takes all the date fields and converts them to YYYY-MM-DD. Datetime seemed unaffected by this problem, so I only deal with date.

I haven't checked it extensively for side effects, but it passes the yaml_db unit tests, and I suspect this is a reasonably correct approach that should work with other dbs.

…which means they will be imported correctly into sqlite3 databases.
@brianmeidell brianmeidell changed the title Added support for date columns to be converted to YYYY-MM-DD format Fix bug affecting sqlite3 date fields: Date columns are now converted to YYYY-MM-DD format Apr 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant