具有多租户的Postgresql 9.6-INHERIT表示子表具有具有不同数据类型的列,但没有

问题描述 投票:0回答:1

我一直在使用具有相同“继承”迁移功能的旧版Rails应用程序,该迁移程序过去已经运行了很多次,但是突然抱怨其中一个子表的列类型与父表不同在公共模式中,但是当我检查数据库中的内容时,这似乎并不正确。请参见下面的代码示例

错误

Apartment::Tenant.switch("child_schema")

# local variable assigned in a looping array of table names...
table = "categories"
ActiveRecord::Base.connection.execute("ALTER TABLE #{table} INHERIT public.#{table}")

-- ERROR:

ActiveRecord::StatementInvalid: PG::DatatypeMismatch: ERROR:  child table "categories" has different type for column "name"
: ALTER TABLE categories INHERIT public.categories

from /var/bundle/ruby/2.3.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `async_exec'

检查

> ActiveRecord::Base.connection.execute("select column_name,data_type from information_schema.columns where table_schema = 'child_schema' AND table_name = 'categories';").to_a

 => [{"column_name"=>"id", "data_type"=>"integer"}, {"column_name"=>"name", "data_type"=>"character varying"}] 


> ActiveRecord::Base.connection.execute("select column_name,data_type from information_schema.columns where table_schema = 'public' AND table_name = 'categories';").to_a

=> [{"column_name"=>"id", "data_type"=>"integer"}, {"column_name"=>"name", "data_type"=>"character varying"}] 

我在这里确实无所适从,我曾尝试搜索Google和SO,查看了postgresql INHERIT文档,四处寻找rails /公寓问题,却找不到任何信息。

更新

看起来好像我这样做:

> Category.connection.columns('public.categories')
> Category.connection.columns('child_schema.categories')

我现在在列类型上有所不同:

# Public parent table:
=> [#<ActiveRecord::ConnectionAdapters::PostgreSQLColumn: #...
@name="name", #...
@sql_type="character varying(255)" #...

# child_schema child table:
=> [#<ActiveRecord::ConnectionAdapters::PostgreSQLColumn: #...
@name="name", #...
@sql_type="character varying" #...

好,所以...任何人都有一个线索,我怎么才能知道为什么子模式表的类型略有不同?

我找不到用于调整列类型/长度的任何迁移,并且租户创建代码仅使用租户名称运行公寓的租户创建方法。

ruby-on-rails ruby postgresql multi-tenant apartment-gem
1个回答
0
投票

这是我的错,结果是单元架构问题引起了一些麻烦:https://github.com/influitive/apartment/issues/626#issuecomment-573206304

© www.soinside.com 2019 - 2024. All rights reserved.