在主要/副本上下文中创建和迁移设计的用户模型

发布于 2025-01-28 09:44:49 字数 1334 浏览 1 评论 0原文

以下主/复制数据库结构

development:
  primary:
    <<: *default
    database: users_development
    username: deploy_root
    password: password
    host: "localhost"
    migrations_paths: db/user_migrate
  primary_replica:
    <<: *default
    database: users_development
    username: deploy_readonly
    password: password
    host: "localhost"
    replica: true

已定义为其主要AR定义为:

class ApplicationRecord < ActiveRecord::Base
  self.abstract_class = true

  connects_to database: { writing: :primary, reading: :primary_replica }
end

但是,当运行以下命令遵循导轨指南所建议的语法

rails generate devise User nick avatar --database users
bin/rails db:migrate

唯一的响应是提示。出现了两个问题:

  1. 迁移是创建的,但不是在适当的目录migrations_paths:db/user_migrate

  2. 登录到数据库user_development =#\ dt返回,一致地与提示回复没有找到任何关系。换句话说,该表未创建(由schema.rb文件确认,文件未更改

指定oprizations_paths用子目录一个错误的错误数据库连接?
还是Rails应该生成设计用户Nick Avatar -Database用户 Indoke 主代替用户

The following main/replica database structure

development:
  primary:
    <<: *default
    database: users_development
    username: deploy_root
    password: password
    host: "localhost"
    migrations_paths: db/user_migrate
  primary_replica:
    <<: *default
    database: users_development
    username: deploy_readonly
    password: password
    host: "localhost"
    replica: true

has defined as its main AR defined as:

class ApplicationRecord < ActiveRecord::Base
  self.abstract_class = true

  connects_to database: { writing: :primary, reading: :primary_replica }
end

However, when The following commands are run following the suggested syntax by the rails guides

rails generate devise User nick avatar --database users
bin/rails db:migrate

the only response is a prompt. Two problems arise:

  1. the migration is created but not in the proper directory migrations_paths: db/user_migrate

  2. Logging into the database users_development=# \dt returns, consistently with the prompt reply Did not find any relations. In other words the table was not created (which is confirmed by the schema.rb file being unaltered

is specifying migrations_paths with a sub directory a mistake for the primary database connection?
Or should rails generate devise User nick avatar --database users invoke primary in lieu of users?

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

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

发布评论

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

评论(1

九公里浅绿 2025-02-04 09:44:49

假定主要数据库在迁移目录中具有其迁移,而不是子目录。

development:
  primary:
    <<: *default
    database: users_development
    username: deploy_root
    password: password
    host: "localhost"
  primary_replica:
    <<: *default
    database: users_development
    username: deploy_readonly
    password: password
    host: "localhost"
    replica: true

运行Rails生成使用- 数据库name_of_primary_database将按照单个数据库应用程序进行。

虽然,这个观察者会喜欢以类似方式组织所有迁移,但是migrations_paths对于主要数据库不允许。

The primary database is assumed to have its migrations in the migrate directory, not a sub-directory.

development:
  primary:
    <<: *default
    database: users_development
    username: deploy_root
    password: password
    host: "localhost"
  primary_replica:
    <<: *default
    database: users_development
    username: deploy_readonly
    password: password
    host: "localhost"
    replica: true

Running a rails generate with --database name_of_primary_database will proceed as in single database application.

Although, this observer would have enjoyed that all migrations be organised in a similar manner, migrations_paths is not allowed for a primary database.

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