aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/schema.rb
diff options
context:
space:
mode:
authorJosh Susser <josh@hasmanythrough.com>2012-12-02 21:16:32 -0800
committerJosh Susser <josh@hasmanythrough.com>2012-12-02 21:16:32 -0800
commitf02d2185ebbe01f455a9a91216ff7094b014ea72 (patch)
tree078c6183d84a9b3c7e72fe77450083df13d86b7e /activerecord/lib/active_record/schema.rb
parent0a5afa229d769bce9e221f34053bb93b60817a5a (diff)
downloadrails-f02d2185ebbe01f455a9a91216ff7094b014ea72.tar.gz
rails-f02d2185ebbe01f455a9a91216ff7094b014ea72.tar.bz2
rails-f02d2185ebbe01f455a9a91216ff7094b014ea72.zip
Add migration history to schema.rb dump
Diffstat (limited to 'activerecord/lib/active_record/schema.rb')
-rw-r--r--activerecord/lib/active_record/schema.rb40
1 files changed, 29 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/schema.rb b/activerecord/lib/active_record/schema.rb
index eaa4aa7086..7ec06e699b 100644
--- a/activerecord/lib/active_record/schema.rb
+++ b/activerecord/lib/active_record/schema.rb
@@ -34,27 +34,45 @@ module ActiveRecord
end
def define(info, &block)
+ @using_deprecated_version_setting = info[:version].present?
+ SchemaMigration.drop_table
+ initialize_schema_migrations_table
+
instance_eval(&block)
- unless info[:version].blank?
- initialize_schema_migrations_table
- assume_migrated_upto_version(info[:version], migrations_paths)
- end
+ # handle files from pre-4.0 that used :version option instead of dumping migration table
+ assume_migrated_upto_version(info[:version], migrations_paths) if @using_deprecated_version_setting
end
# Eval the given block. All methods available to the current connection
# adapter are available within the block, so you can easily use the
# database definition DSL to build up your schema (+create_table+,
# +add_index+, etc.).
- #
- # The +info+ hash is optional, and if given is used to define metadata
- # about the current schema (currently, only the schema's version):
- #
- # ActiveRecord::Schema.define(version: 20380119000001) do
- # ...
- # end
def self.define(info={}, &block)
new.define(info, &block)
end
+
+ # Create schema migration history. Include migration statements in a block to this method.
+ #
+ # migrations do
+ # migration 20121128235959, "44f1397e3b92442ca7488a029068a5ad", "add_horn_color_to_unicorns"
+ # migration 20121129235959, "4a1eb3965d94406b00002b370854eae8", "add_magic_power_to_unicorns"
+ # end
+ def migrations
+ raise(ArgumentError, "Can't set migrations while using :version option") if @using_deprecated_version_setting
+ yield
+ end
+
+ # Add a migration to the ActiveRecord::SchemaMigration table.
+ #
+ # The +version+ argument is an integer.
+ # The +fingerprint+ and +name+ arguments are required but may be empty strings.
+ # The migration's +migrated_at+ attribute is set to the current time,
+ # instead of being set explicitly as an argument to the method.
+ #
+ # migration 20121129235959, "4a1eb3965d94406b00002b370854eae8", "add_magic_power_to_unicorns"
+ def migration(version, fingerprint, name)
+ SchemaMigration.create!(version: version, migrated_at: Time.now, fingerprint: fingerprint, name: name)
+ end
end
end