Module: UsesguidMigrations::ActiveRecordExtensions::ConnectionAdapters::SqliteAdapter
- Defined in:
- lib/usesguid_migrations/active_record_extensions/connection_adapters/sqlite_adapter.rb
Instance Method Summary collapse
- #uses_guid_add_column(table_name, column_name, type, options = {}) ⇒ Object
- #usesguid_add_column_statement(table_name, column_def) ⇒ Object
- #usesguid_alter_column_statement(table_name, pk_name, options = {}) ⇒ Object
- #usesguid_create_table(table_name, table_definition, options) ⇒ Object
- #usesguid_make_column_primary_key(table_name, pk_name) ⇒ Object
- #usesuid_create_table_statement(table_name, table_definition, options) ⇒ Object
Instance Method Details
#uses_guid_add_column(table_name, column_name, type, options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/usesguid_migrations/active_record_extensions/connection_adapters/sqlite_adapter.rb', line 30 def uses_guid_add_column( table_name, column_name, type, ={} ) column = ActiveRecord::ConnectionAdapters::ColumnDefinition.new( self, column_name, :text ) if [:limit] column.limit = [:limit] #elsif native[type.to_sym].is_a?( Hash ) # column.limit = native[type.to_sym][:limit] end column.precision = [:precision] column.scale = [:scale] column.default = [:default] column.null = [:null] add_column_sql = usesguid_add_column_statement( table_name, column ) begin execute( add_column_sql ) rescue SQLite3::MisuseException; end end |
#usesguid_add_column_statement(table_name, column_def) ⇒ Object
65 66 67 |
# File 'lib/usesguid_migrations/active_record_extensions/connection_adapters/sqlite_adapter.rb', line 65 def usesguid_add_column_statement( table_name, column_def ) "ALTER TABLE #{quote_table_name( table_name )} ADD COLUMN #{column_def.to_sql} DEFAULT('')" end |
#usesguid_alter_column_statement(table_name, pk_name, options = {}) ⇒ Object
57 58 59 |
# File 'lib/usesguid_migrations/active_record_extensions/connection_adapters/sqlite_adapter.rb', line 57 def usesguid_alter_column_statement( table_name, pk_name, ={} ) '' end |
#usesguid_create_table(table_name, table_definition, options) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/usesguid_migrations/active_record_extensions/connection_adapters/sqlite_adapter.rb', line 4 def usesguid_create_table( table_name, table_definition, ) begin sql = usesuid_create_table_statement( table_name, table_definition, ) sql.sub!( '"id" blob(22) NOT NULL', '"id" blob(22) PRIMARY KEY NOT NULL' ) execute( sql ) rescue SQLite3::MisuseException; end unless table_name == "schema_migrations" unless [:id] == false || [:guid] == false sql = usesguid_alter_column_statement( table_name, table_definition.primary_key_name, :null => false ) execute( sql ) unless sql.nil? || sql.empty? sql = usesguid_make_column_primary_key( table_name, table_definition.primary_key_name ) execute( sql ) unless sql.nil? || sql.empty? end return if table_definition.associative_keys.nil? table_definition.associative_keys.each do |assoc| begin sql = usesguid_alter_column_statement( table_name, assoc.name, assoc. ) execute( sql ) unless sql.nil? || sql.empty? rescue SQLite3::MisuseException; end end end end |
#usesguid_make_column_primary_key(table_name, pk_name) ⇒ Object
61 62 63 |
# File 'lib/usesguid_migrations/active_record_extensions/connection_adapters/sqlite_adapter.rb', line 61 def usesguid_make_column_primary_key( table_name, pk_name ) '' end |
#usesuid_create_table_statement(table_name, table_definition, options) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/usesguid_migrations/active_record_extensions/connection_adapters/sqlite_adapter.rb', line 49 def usesuid_create_table_statement( table_name, table_definition, ) create_sql = "CREATE#{' TEMPORARY' if [:temporary]} TABLE " create_sql << "#{quote_table_name( table_name )} (" create_sql << table_definition.to_sql create_sql << ") #{[:options]}" create_sql end |