Rails: Is the version number in 'schema.rb' used for anything?

前端 未结 2 1863
一向
一向 2020-12-15 17:18

Now that Rails has timestamped migrations, the single version number at the top of /db/schema.rb seems pointless. Sometimes the version number ends up incorrec

2条回答
  •  死守一世寂寞
    2020-12-15 17:38

    I decided to investigate myself. It turns out that because of the timestamped migrations, the only thing Rails does with that number is assume that the migration with that particular timestamp has already been applied and thus create the appropriate entry in the schema_migration table if it doesn't exist.

    from: /lib/active_record/connection_adapters/abstract/schema_statements.rb

    def assume_migrated_upto_version(version, migrations_path = ActiveRecord::Migrator.migrations_path)
        # other code ... 
        unless migrated.include?(version)
          execute "INSERT INTO #{sm_table} (version) VALUES ('#{version}')"
        end
        # ...
    

提交回复
热议问题