更新时间:2022-12-17 19:58:21
如果您需要或想要ActiveRecord无法理解的特定于数据库的功能,则应切换到 db / structure.sql
用于跟踪架构。 db / structure.sql
几乎是使用数据库的本机工具生成的模式的原始转储,因此它将包含触发器,CHECK约束,函数结果的索引以及所有其他内容。
If you need or want database-specific features that ActiveRecord doesn't understand then you should switch to db/structure.sql
for keeping track of your schema. db/structure.sql
is pretty much a raw dump of your schema made using the database's native tools so it will contain triggers, CHECK constraints, indexes on function results, and everything else.
切换很容易:
config / application.rb
包含 config.active_record.schema_format =:sql
。 rake db:structure:dump
以获得初始的 db / structure.sql
。 db / schema.rb
。 db / structure .sql
进行版本控制。 db:structure:dump
而不是 db:schema:dump
db:structure:load
而不是 db:schema:load
config/application.rb
to contain config.active_record.schema_format = :sql
.rake db:structure:dump
to get an initial db/structure.sql
.db/schema.rb
from your directory tree and revision control.db/structure.sql
to revision control.db:structure:dump
instead of db:schema:dump
db:structure:load
instead of db:schema:load
其他所有内容都应照常进行(当然,假设您是
Everything else should work as usual (assuming, of course, that you're sane and using PostgreSQL for development, testing, and production).
进行此更改后,触发器将在 db / structure.sql中进行跟踪。
并重新创建数据库不会丢失它们。
With this change made, your triggers will be tracked in db/structure.sql
and recreating the database won't lose them.