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

rake db:test:prepare fails loading schema (generated by MySql ) using sqlite3 engine because of specific options passed in schema (MySql specific) #228

Open
Kareem-Emad opened this issue Mar 7, 2019 · 1 comment

Comments

@Kareem-Emad
Copy link

sqlite3 --version
3.25.2
mysql --version
mysql Ver 14.14 Distrib 5.7.25

Error Log:

bin/bundle exec rake db:test:prepare
rake aborted!
ActiveRecord::StatementInvalid: SQLite3::SQLException: near "ENGINE": syntax error: CREATE TABLE "app_dependencies" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "app_id" integer, "dependency_id" integer, "created_at" datetime, "updated_at" datetime) ENGINE=InnoDB DEFAULT CHARSET=utf8
/home/kareem/Projects/platform/db/schema.rb:15:in block in <top (required)>' /home/kareem/Projects/platform/db/schema.rb:13:in <top (required)>'
bin/bundle:104:in load' bin/bundle:104:in

'

Caused by:
SQLite3::SQLException: near "ENGINE": syntax error
/home/kareem/Projects/platform/db/schema.rb:15:in block in <top (required)>' /home/kareem/Projects/platform/db/schema.rb:13:in <top (required)>'
bin/bundle:104:in load' bin/bundle:104:in

'
Tasks: TOP => db:test:load_schema
(See full trace by running task with --trace)
Makefile:36: recipe for target 'run-tests' failed
make: *** [run-tests] Error 1

I can get around this by removing options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" from the schema file before running make run-tests.

@acasaism
Copy link

acasaism commented Feb 3, 2020

I have this in my tasks to eliminate these lines automatically when throwing rake db:migrate

Rake::Task['db:migrate'].enhance do
file_path = Rails.root.join('db', 'schema.rb')
text = File.read(file_path)
text = text.gsub(/options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", /, '')
text = text.gsub(/options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", /, '')
File.open((file_path), "w") { |file| file << new_contents }
end

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

No branches or pull requests

2 participants