Module: Fixturama::Config

Defined in:
lib/fixturama/config.rb

Overview

Configures the gem to exclude conflicts between ids auto-generated by database and hardcoded in fixtures

Constant Summary collapse

SEQUENCE_BOOST_SCRIPT =
"DO $$\nDECLARE\nseq_name TEXT;\n\nBEGIN\n  FOR seq_name IN (select table_name from information_schema.tables where\n    table_catalog='%<db_name>s' and table_schema='public') LOOP\n  BEGIN\n    EXECUTE ' \\\n      SELECT setval('''||seq_name||'_id_seq''::regclass, %<min_id>s); ';\n  EXCEPTION\n    WHEN undefined_table THEN\n      NULL;\n  END;\n  END LOOP;\nEND$$;\n".freeze

Class Method Summary collapse

Class Method Details

.start_ids_from(value) ⇒ Boolean

Parameters:

  • value (#to_i)

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fixturama/config.rb', line 13

def start_ids_from(value)
  require "active_record"

  db_name = ActiveRecord::Base.connection_config[:database]
  sql = format(SEQUENCE_BOOST_SCRIPT, db_name: db_name, min_id: value.to_i)
  ActiveRecord::Base.connection.execute(sql)

  true
rescue LoadError
  false
end