fractaledmind / acidic_job

Elegant, resilient, durable workflows for Rails apps
https://fractaledmind.github.io/acidic_job/
MIT License
487 stars 10 forks source link

CreateAcidicJobRuns migration raises error when using SQLite #95

Open ahacop opened 2 months ago

ahacop commented 2 months ago

The CreateAcidicJobRuns migration defines the default on the staging column with a lambda that returns a boolean. The ActiveRecord SQLite adapter implicitly requires procs to return strings, because it calls match? on the return value. Thus, running the migration when using the SQLite adapter raises an error.

See: https://github.com/rails/rails/blob/e1d58cfd05ae1cc0bfc1006b7ce973a7730831df/activerecord/lib/active_record/connection_adapters/sqlite3/quoting.rb#L89

$ bin/rails db:create db:migrate
Created database 'storage/development.sqlite3'
Created database 'storage/test.sqlite3'
== 20240908122535 CreateAcidicJobRuns: migrating ==============================
-- create_table(:acidic_job_runs)
bin/rails aborted!
StandardError: An error has occurred, this and all later migrations canceled: (StandardError)

undefined method `match?' for false
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/sqlite3/quoting.rb:89:in `quote_default_expression'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/schema_creation.rb:16:in `quote_default_expression'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/schema_creation.rb:152:in `add_column_options!'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/sqlite3/schema_creation.rb:38:in `add_column_options!'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/schema_creation.rb:36:in `visit_ColumnDefinition'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/schema_creation.rb:13:in `accept'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/schema_creation.rb:49:in `block in visit_TableDefinition'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/schema_creation.rb:49:in `map'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/schema_creation.rb:49:in `visit_TableDefinition'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/schema_creation.rb:13:in `accept'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:309:in `create_table'
ruby/gems/activerecord-7.2.1/lib/active_record/migration/default_strategy.rb:10:in `method_missing'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:1059:in `block in method_missing'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:1025:in `block in say_with_time'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:1025:in `say_with_time'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:1048:in `method_missing'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:585:in `create_table'
db/migrate/20240908122535_create_acidic_job_runs.rb:3:in `change'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:994:in `exec_migration'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:978:in `block (2 levels) in migrate'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:977:in `block in migrate'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:389:in `with_connection'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:976:in `migrate'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:1190:in `migrate'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:1538:in `block in execute_migration_in_transaction'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/transaction.rb:616:in `block in within_new_transaction'
ruby/gems/activesupport-7.2.1/lib/active_support/concurrency/null_lock.rb:9:in `synchronize'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/transaction.rb:613:in `within_new_transaction'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:361:in `transaction'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:1589:in `ddl_transaction'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:1537:in `execute_migration_in_transaction'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:1512:in `each'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:1512:in `migrate_without_lock'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:1459:in `migrate'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:1264:in `up'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:1239:in `migrate'
ruby/gems/activerecord-7.2.1/lib/active_record/tasks/database_tasks.rb:251:in `migrate'
ruby/gems/activerecord-7.2.1/lib/active_record/railties/databases.rake:93:in `block (2 levels) in <main>'
ruby/gems/rake-13.2.1/lib/rake/task.rb:281:in `block in execute'
ruby/gems/rake-13.2.1/lib/rake/task.rb:281:in `each'
ruby/gems/rake-13.2.1/lib/rake/task.rb:281:in `execute'
ruby/gems/rake-13.2.1/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
ruby/gems/rake-13.2.1/lib/rake/task.rb:199:in `synchronize'
ruby/gems/rake-13.2.1/lib/rake/task.rb:199:in `invoke_with_call_chain'
ruby/gems/rake-13.2.1/lib/rake/task.rb:188:in `invoke'
ruby/gems/rake-13.2.1/lib/rake/application.rb:188:in `invoke_task'
ruby/gems/rake-13.2.1/lib/rake/application.rb:138:in `block (2 levels) in top_level'
ruby/gems/rake-13.2.1/lib/rake/application.rb:138:in `each'
ruby/gems/rake-13.2.1/lib/rake/application.rb:138:in `block in top_level'
ruby/gems/rake-13.2.1/lib/rake/application.rb:147:in `run_with_threads'
ruby/gems/rake-13.2.1/lib/rake/application.rb:132:in `top_level'
ruby/gems/railties-7.2.1/lib/rails/commands/rake/rake_command.rb:27:in `block (2 levels) in perform'
ruby/gems/rake-13.2.1/lib/rake/application.rb:214:in `standard_exception_handling'
ruby/gems/railties-7.2.1/lib/rails/commands/rake/rake_command.rb:27:in `block in perform'
ruby/gems/railties-7.2.1/lib/rails/commands/rake/rake_command.rb:44:in `block in with_rake'
ruby/gems/rake-13.2.1/lib/rake/rake_module.rb:59:in `with_application'
ruby/gems/railties-7.2.1/lib/rails/commands/rake/rake_command.rb:41:in `with_rake'
ruby/gems/railties-7.2.1/lib/rails/commands/rake/rake_command.rb:20:in `perform'
ruby/gems/railties-7.2.1/lib/rails/command.rb:156:in `invoke_rake'
ruby/gems/railties-7.2.1/lib/rails/command.rb:73:in `block in invoke'
ruby/gems/railties-7.2.1/lib/rails/command.rb:149:in `with_argv'
ruby/gems/railties-7.2.1/lib/rails/command.rb:69:in `invoke'
ruby/gems/railties-7.2.1/lib/rails/commands.rb:18:in `<main>'
ruby/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'

Caused by:
NoMethodError: undefined method `match?' for false (NoMethodError)

            if value.match?(/\A\w+\(.*\)\z/)
                    ^^^^^^^
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/sqlite3/quoting.rb:89:in `quote_default_expression'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/schema_creation.rb:16:in `quote_default_expression'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/schema_creation.rb:152:in `add_column_options!'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/sqlite3/schema_creation.rb:38:in `add_column_options!'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/schema_creation.rb:36:in `visit_ColumnDefinition'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/schema_creation.rb:13:in `accept'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/schema_creation.rb:49:in `block in visit_TableDefinition'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/schema_creation.rb:49:in `map'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/schema_creation.rb:49:in `visit_TableDefinition'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/schema_creation.rb:13:in `accept'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:309:in `create_table'
ruby/gems/activerecord-7.2.1/lib/active_record/migration/default_strategy.rb:10:in `method_missing'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:1059:in `block in method_missing'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:1025:in `block in say_with_time'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:1025:in `say_with_time'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:1048:in `method_missing'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:585:in `create_table'
db/migrate/20240908122535_create_acidic_job_runs.rb:3:in `change'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:994:in `exec_migration'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:978:in `block (2 levels) in migrate'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:977:in `block in migrate'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:389:in `with_connection'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:976:in `migrate'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:1190:in `migrate'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:1538:in `block in execute_migration_in_transaction'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/transaction.rb:616:in `block in within_new_transaction'
ruby/gems/activesupport-7.2.1/lib/active_support/concurrency/null_lock.rb:9:in `synchronize'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/transaction.rb:613:in `within_new_transaction'
ruby/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:361:in `transaction'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:1589:in `ddl_transaction'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:1537:in `execute_migration_in_transaction'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:1512:in `each'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:1512:in `migrate_without_lock'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:1459:in `migrate'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:1264:in `up'
ruby/gems/activerecord-7.2.1/lib/active_record/migration.rb:1239:in `migrate'
ruby/gems/activerecord-7.2.1/lib/active_record/tasks/database_tasks.rb:251:in `migrate'
ruby/gems/activerecord-7.2.1/lib/active_record/railties/databases.rake:93:in `block (2 levels) in <main>'
ruby/gems/rake-13.2.1/lib/rake/task.rb:281:in `block in execute'
ruby/gems/rake-13.2.1/lib/rake/task.rb:281:in `each'
ruby/gems/rake-13.2.1/lib/rake/task.rb:281:in `execute'
ruby/gems/rake-13.2.1/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
ruby/gems/rake-13.2.1/lib/rake/task.rb:199:in `synchronize'
ruby/gems/rake-13.2.1/lib/rake/task.rb:199:in `invoke_with_call_chain'
ruby/gems/rake-13.2.1/lib/rake/task.rb:188:in `invoke'
ruby/gems/rake-13.2.1/lib/rake/application.rb:188:in `invoke_task'
ruby/gems/rake-13.2.1/lib/rake/application.rb:138:in `block (2 levels) in top_level'
ruby/gems/rake-13.2.1/lib/rake/application.rb:138:in `each'
ruby/gems/rake-13.2.1/lib/rake/application.rb:138:in `block in top_level'
ruby/gems/rake-13.2.1/lib/rake/application.rb:147:in `run_with_threads'
ruby/gems/rake-13.2.1/lib/rake/application.rb:132:in `top_level'
ruby/gems/railties-7.2.1/lib/rails/commands/rake/rake_command.rb:27:in `block (2 levels) in perform'
ruby/gems/rake-13.2.1/lib/rake/application.rb:214:in `standard_exception_handling'
ruby/gems/railties-7.2.1/lib/rails/commands/rake/rake_command.rb:27:in `block in perform'
ruby/gems/railties-7.2.1/lib/rails/commands/rake/rake_command.rb:44:in `block in with_rake'
ruby/gems/rake-13.2.1/lib/rake/rake_module.rb:59:in `with_application'
ruby/gems/railties-7.2.1/lib/rails/commands/rake/rake_command.rb:41:in `with_rake'
ruby/gems/railties-7.2.1/lib/rails/commands/rake/rake_command.rb:20:in `perform'
ruby/gems/railties-7.2.1/lib/rails/command.rb:156:in `invoke_rake'
ruby/gems/railties-7.2.1/lib/rails/command.rb:73:in `block in invoke'
ruby/gems/railties-7.2.1/lib/rails/command.rb:149:in `with_argv'
ruby/gems/railties-7.2.1/lib/rails/command.rb:69:in `invoke'
ruby/gems/railties-7.2.1/lib/rails/commands.rb:18:in `<main>'
ruby/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)