diff options
author | Josh Susser <josh@hasmanythrough.com> | 2010-03-20 18:26:12 -0700 |
---|---|---|
committer | Josh Susser <josh@hasmanythrough.com> | 2010-12-01 10:57:38 -0800 |
commit | 7139aa878ceea8dd17a60955cd4d07f5f68980d9 (patch) | |
tree | 6246048e1a611d770a3f5b5b0208c6597cbd646a /activerecord/lib/active_record | |
parent | 4e4e9ad48a222ac94a904c62ae684c609bd8e177 (diff) | |
download | rails-7139aa878ceea8dd17a60955cd4d07f5f68980d9.tar.gz rails-7139aa878ceea8dd17a60955cd4d07f5f68980d9.tar.bz2 rails-7139aa878ceea8dd17a60955cd4d07f5f68980d9.zip |
name in schema_migrations, migrations in schema dump
Diffstat (limited to 'activerecord/lib/active_record')
4 files changed, 28 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 730b1c7425..ccb6fe3be2 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -429,9 +429,13 @@ module ActiveRecord update "UPDATE #{quote_table_name(sm_table)} SET migrated_at = '#{quoted_date(Time.now)}' WHERE migrated_at IS NULL" change_column sm_table, :migrated_at, :datetime, :null => false end + unless cols.include?("name") + add_column sm_table, :name, :string, :null => false, :default => "" + end else create_table(sm_table, :id => false) do |schema_migrations_table| schema_migrations_table.column :version, :string, :null => false + schema_migrations_table.column :name, :string, :null => false, :default => "" schema_migrations_table.column :migrated_at, :datetime, :null => false end add_index sm_table, :version, :unique => true, diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 2cf2f4acd0..d2ebf656cb 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -701,6 +701,7 @@ module ActiveRecord @migrated_versions.push(target.version).sort! table.insert( table["version"] => target.version.to_s, + table["name"] => File.basename(target.filename,'.rb').gsub(/^\d+_/,''), table["migrated_at"] => Time.now ) end diff --git a/activerecord/lib/active_record/schema.rb b/activerecord/lib/active_record/schema.rb index c6bb5c1961..c9b5539e4f 100644 --- a/activerecord/lib/active_record/schema.rb +++ b/activerecord/lib/active_record/schema.rb @@ -49,10 +49,19 @@ module ActiveRecord schema = new schema.instance_eval(&block) - unless info[:version].blank? - initialize_schema_migrations_table - assume_migrated_upto_version(info[:version], schema.migrations_path) - end + initialize_schema_migrations_table + assume_migrated_upto_version(info[:version], schema.migrations_path) unless info[:version].blank? + end + + def self.migration(version, name="", options={}) + name, options = "", name if name.is_a?(Hash) + + table = Arel::Table.new(ActiveRecord::Migrator.schema_migrations_table_name) + table.insert( + table["version"] => version, + table["name"] => name, + table["migrated_at"] => Time.now + ) end end end diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb index e30b481fe1..a53dce0cf4 100644 --- a/activerecord/lib/active_record/schema_dumper.rb +++ b/activerecord/lib/active_record/schema_dumper.rb @@ -24,6 +24,7 @@ module ActiveRecord def dump(stream) header(stream) + migrations(stream) tables(stream) trailer(stream) stream @@ -62,6 +63,15 @@ HEADER stream.puts "end" end + def migrations(stream) + rows = @connection.select_all("SELECT * FROM #{@connection.quote_table_name(ActiveRecord::Migrator.schema_migrations_table_name)}") + rows.each do |migration| + line = %Q(migration "#{migration['version']}") + line << %Q(, "#{migration['name']}") unless migration['name'].blank? + stream.puts line + end + end + def tables(stream) @connection.tables.sort.each do |tbl| next if ['schema_migrations', ignore_tables].flatten.any? do |ignored| |