Module: ActiveRecord::Sequence::Adapter
- Included in:
- ConnectionAdapters::TidbAdapter
- Defined in:
- lib/active_record/sequence/adapter.rb
Instance Method Summary collapse
- #check_sequences ⇒ Object
- #create_sequence(name, options = {}) ⇒ Object
- #drop_sequence(name) ⇒ Object
- #recreate_sequence(name, options = {}) ⇒ Object
Instance Method Details
#check_sequences ⇒ Object
6 7 8 9 10 |
# File 'lib/active_record/sequence/adapter.rb', line 6 def check_sequences select_all( 'SELECT * FROM information_schema.sequences ORDER BY sequence_name' ).to_a end |
#create_sequence(name, options = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/active_record/sequence/adapter.rb', line 12 def create_sequence(name, = {}) increment = [:increment] || [:step] name = quote_column_name(name) sql = ["CREATE SEQUENCE IF NOT EXISTS #{name}"] sql << "INCREMENT BY #{increment}" if increment sql << "START WITH #{[:start]}" if [:start] sql << if [:cache] "CACHE #{[:cache]}" else 'NOCACHE' end sql << if [:cycle] 'CYCLE' else 'NOCYCLE' end sql << "MIN_VALUE #{[:min_value]}" if [:min_value] sql << "COMMENT #{quote([:comment].to_s)}" if [:comment] execute(sql.join("\n")) end |
#drop_sequence(name) ⇒ Object
38 39 40 41 42 |
# File 'lib/active_record/sequence/adapter.rb', line 38 def drop_sequence(name) name = quote_column_name(name) sql = "DROP SEQUENCE IF EXISTS #{name}" execute(sql) end |
#recreate_sequence(name, options = {}) ⇒ Object
44 45 46 47 |
# File 'lib/active_record/sequence/adapter.rb', line 44 def recreate_sequence(name, = {}) drop_sequence(name) create_sequence(name, ) end |