Module: ActiveRecord::ConnectionAdapters::SchemaStatements
- Defined in:
- lib/active_record/connection_adapters/ibm_db_pstmt.rb,
lib/active_record/connection_adapters/ibm_db_adapter.rb
Instance Method Summary collapse
- #assume_migrated_upto_version(version) ⇒ Object
- #create_table_definition(name, temporary, options, as = nil) ⇒ Object
- #remove_foreign_key(from_table, options_or_to_table = {}) ⇒ Object
Instance Method Details
#assume_migrated_upto_version(version) ⇒ Object
1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 |
# File 'lib/active_record/connection_adapters/ibm_db_pstmt.rb', line 1931 def assume_migrated_upto_version(version) version = version.to_i sm_table = quote_table_name(ActiveRecord::Migrator.schema_migrations_table_name) migrated = select_values("SELECT version FROM #{sm_table}").map(&:to_i) versions = Dir['db/migrate/[0-9]*_*.rb'].map do |filename| filename.split('/').last.split('_').first.to_i end unless migrated.include?(version) pstmt = prepare("INSERT INTO #{sm_table} (version) VALUES (?)") execute_prepared_stmt(pstmt, [version]) end inserted = Set.new (versions - migrated).each do |v| if inserted.include?(v) raise "Duplicate migration #{v}. Please renumber your migrations to resolve the conflict." elsif v < version pstmt = prepare("INSERT INTO #{sm_table} (version) VALUES (?)") execute_prepared_stmt(pstmt, [v]) inserted << v end end end |
#create_table_definition(name, temporary, options, as = nil) ⇒ Object
283 284 285 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 283 def create_table_definition(name, temporary, ,as = nil) TableDefinition.new self, name, temporary, end |
#remove_foreign_key(from_table, options_or_to_table = {}) ⇒ Object
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 287 def remove_foreign_key(from_table, = {}) return unless supports_foreign_keys? if .is_a?(Hash) = else = { column: foreign_key_column_for() } end fk_name_to_delete = .fetch(:name) do fk_to_delete = foreign_keys(@servertype.set_case(from_table)).detect {|fk| "#{@servertype.set_case(fk.column)}" == "#{servertype.set_case([:column])}"} if fk_to_delete fk_to_delete.name else raise ArgumentError, "Table '#{from_table}' has no foreign key on column '#{[:column]}'" end end at = create_alter_table from_table at.drop_foreign_key fk_name_to_delete execute schema_creation.accept(at) end |