Rails:存储一个简单的、不关联的、管理员可编辑的值

发布于 2024-12-05 15:43:42 字数 191 浏览 3 评论 0原文

我有一个网站需要一个管理员可编辑的整数。它与数据库中的任何其他模型或属性没有关联。它实际上是一个介于 1-10,000 之间的平面整数,管理员(唯一的用户)需要访问该整数才能进行编辑。

我的问题与数据库设计有关。当然,最有效的方法不是创建自己的表,只有一列和一行?

简而言之......一个单一的领域,没有关联:我应该如何最好地滚动它?

I have a site which needs one admin-editable integer. It has no association to any other model or attribute in the database. It's literally a flat integer, between 1-10,000, that the admin (who is the only user) needs access to edit.

My question relates to database design. Surely the most efficient way to do this isn't to create its own table, with just one single column and one single row?

In short...one single field, no associations: how should I best roll that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独守阴晴ぅ圆缺 2024-12-12 15:43:42

这取决于你如何定义“高效”。

如果将“高效”定义为

  • 对所有用户可编辑数据(数据库)使用单一存储机制,
  • 对所有用户可编辑数据(SQL GRANT 和 REVOKE)使用单一安全机制,
  • 对所有用户可编辑数据使用单一约束机制数据(SQL DDL),

那么创建单行表可能是最有效的。沿着这些思路的东西可能会在数据库方面起作用。

create table admin_editable_integer (
  restrictive_key integer primary key,
  the_integer integer not null,
  -- Allow only one row.
  check (restrictive_key = 1),
  -- Restrict the range of integers.
  check (the_integer between 1 and 10000)
);

revoke all on admin_editable_integer from public;
grant select, insert, update on admin_editable_integer to admin;

我认为 Rails 不支持 CHECK 约束,因此我认为您需要在迁移中传递 ALTER TABLE SQL 语句。

It depends on how you define "efficient".

If you define "efficient" as using

  • a single storage mechanism for all user-editable data (a database),
  • a single security mechanism for all user-editable data (SQL GRANT and REVOKE), and
  • a single constraint mechanism for all user-editable data (SQL DDL),

then creating a one-row table probably is the most efficient. Something along these lines might work on the database side.

create table admin_editable_integer (
  restrictive_key integer primary key,
  the_integer integer not null,
  -- Allow only one row.
  check (restrictive_key = 1),
  -- Restrict the range of integers.
  check (the_integer between 1 and 10000)
);

revoke all on admin_editable_integer from public;
grant select, insert, update on admin_editable_integer to admin;

I don't think rails supports CHECK constraints, so I think you'll need to pass ALTER TABLE SQL statements in the migration.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文