How to set a Ruby on Rails 4+ app's default db

2019-08-14 18:53发布

I want to make my application serialize every transaction by default. I'd then relax isolation based on performance measurements and knowing what data particular actions/transactions use and change.

I doubt serializable by default would get into the framework, as it'd slow things down and be difficult to explain. But I don't want to deal with db corruption, and do want internally consistent aggregate calculations.

For case-by-case isolation levels there is Rails postgresql how to set transaction isolation level to serializable but I think this approach is wrong for the same reasons html-escaping to protect against xss were wrong and were dropped: whitelisting is safer than blacklisting.

Has anyone done this already? Where would be a good place to hook into rails to do this?

1条回答
神经病院院长
2楼-- · 2019-08-14 19:29

If you want this the default, then I suggest setting it in your MySQL config. The setting is described here: https://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_transaction-isolation

[mysqld]
default-character-set = utf8
default-storage-engine = InnoDB
default-table-type = InnoDB
transaction-isolation = SERIALIZABLE

For PostgreSQL the setting is called default_transaction_isolation. You can set this in postgresql.conf.

查看更多
登录 后发表回答