-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support schema search path #286
Conversation
412810e
to
3d9a893
Compare
exclude :test_set_pk_sequence, "Skipping until we can triage further. See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/48" | ||
exclude :test_pk_and_sequence_for_with_schema_specified, "Skipping until we can triage further. See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/48" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the failing tests is new to this PR, but I'm not sure how to fix it. We create a table using SELECT a.attname, format_type(a.atttypid, a.atttypmod),
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,
c.collname, NULL AS comment,
attgenerated,
NULL as is_hidden
FROM pg_attribute a
LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
LEFT JOIN pg_type t ON a.atttypid = t.oid
LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation
WHERE a.attrelid = 'thetable'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum @rafiss do you have any idea if this is correct or expected ? |
Yeah
|
Ah so the problem seems to be at creation then: we say create with integer and we get a bigint. Thank you! I'll look at this further during the next days |
fd9e7b3
to
3d9a893
Compare
@rafiss so looking again at the issue, I think there is a CRDB issue. Those statements show me that id is an int8, which create table bar (id integer, num bigint);
show create table bar; Shows both as the same However doing the same with pg gives me integer and bigint. |
Ah I see, yes there is a CRDB difference here. In CRDB, the default integer size is 8. It can be configured using the There are more docs here: https://www.cockroachlabs.com/docs/stable/int |
@rafiss nice thank you ! I think I'll just set this in the database for tests to be ok and more in sync with the PG tests. I can also consider adding a dedicated test to show that this specific case of integer being the same as bigint is considered and not a bug. |
519c542
to
ff264c0
Compare
ff264c0
to
cb1313b
Compare
The For this PR, I think we're fine as this is out of scope anyway. But shouldn't I open an issue to discuss that and what do we want to do ? For now I see two options:
WDYT @rafiss ? |
I believe you encountered this problem: cockroachdb/cockroach#26925 (comment) But it's possible we don't show this warning in all the cases we should. For now, I agree: let's start by opening an issue in this repo, with a full example of the table schema that causes the confusing behavior. |
Good news, the issue is only due to how tests are written, my attempt of a reproduction within the codebase luckily failed, and is covered by some other tests, so we're all set! I'm not pushing the test change upstream this time as it would be meaningless to postgresql adapter (they don't give the option to change the default int size). And btw, the warning is eclipsed because this happen when creating the database, which is extremely verbose. In the test we are removing all the logs at that moment to avoid being too verbose, and for any production app, I don't think someone would see this one line buried in logs! And for completeness, here's the reproduction attemptrequire "active_record"
require "activerecord-cockroachdb-adapter"
require "minitest/autorun"
require "logger"
ActiveRecord::Base.establish_connection(
adapter: "cockroachdb",
host: "localhost",
port: 26257,
user: "root",
database: "ar_crdb_console"
)
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.connection.execute("SET default_int_size = 4")
ActiveRecord::Schema.define do
create_table :albums, force: true do |t|
t.string :title
end
create_table :songs, force: true do |t|
t.string :title
end
pp method(:create_join_table).super_method
binding.irb
create_join_table :albums, :songs, force: true
end
class Album < ActiveRecord::Base
has_and_belongs_to_many :songs
end
class Song < ActiveRecord::Base
has_and_belongs_to_many :albums
end
class BugTest < Minitest::Test
def test_association_stuff
song = Song.create(title: "Another Brick in the Wall")
song.albums.create(title: "The Wall")
conn = ActiveRecord::Base.connection
pp conn.select_one("SHOW CREATE TABLE albums_songs")
pp conn.select_one("SHOW CREATE TABLE albums")
pp conn.select_one("SHOW CREATE TABLE songs")
end
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice work on this!
No description provided.