更新时间:2022-12-17 19:45: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
其他一切都应该像往常一样工作(当然,假设您是理智的并且使用 PostgreSQL 进行开发、测试和生产).
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.