Skip to content

Commit

Permalink
Improved error message when database connection fails
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Oct 8, 2024
1 parent fdba797 commit eb042fe
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/support/mariadb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ class MariadbRecord < ActiveRecord::Base
establish_connection adapter: "mysql2", database: "neighbor_test", host: "127.0.0.1", port: 3307, username: "root"
end

begin
MariadbRecord.connection.verify!
rescue => e
abort <<~MSG
Database connection failed: #{e.message}
To use the Docker container, run:
docker run -e MARIADB_ALLOW_EMPTY_ROOT_PASSWORD=1 -e MARIADB_DATABASE=neighbor_test -p 3307:3306 quay.io/mariadb-foundation/mariadb-devel:11.6-vector-preview
(and wait for it to be ready)
MSG
end

MariadbRecord.connection.instance_eval do
create_table :mariadb_items, force: true do |t|
t.binary :embedding, null: false
Expand Down
14 changes: 14 additions & 0 deletions test/support/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ class MysqlRecord < ActiveRecord::Base
establish_connection adapter: (ENV["TEST_TRILOGY"] ? "trilogy" : "mysql2"), database: "neighbor_test", host: "127.0.0.1", username: "root"
end

begin
MysqlRecord.connection.verify!
rescue => e
abort <<~MSG
Database connection failed: #{e.message}
To use the Docker container, run:
docker run -e MYSQL_ALLOW_EMPTY_PASSWORD=1 -e MYSQL_DATABASE=neighbor_test -p 3306:3306 mysql:9
(and wait for it to be ready)
MSG
end

MysqlRecord.connection.instance_eval do
create_table :mysql_items, force: true do |t|
t.vector :embedding, limit: 3
Expand Down

0 comments on commit eb042fe

Please sign in to comment.