Skip to content

Commit

Permalink
Add running CI with sqlite adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
prog-supdex committed Oct 19, 2023
1 parent 5b9566a commit 5de703e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,32 @@ jobs:
BUNDLE_JOBS: 4
BUNDLE_RETRY: 3
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
DATABASE_URL: postgres://postgres:postgres@localhost:5432
POSTGRES_URL: postgres://postgres:postgres@localhost:5432
DB: ${{ matrix.db }}
DB_NAME: slotted_counters_test
CI: true
strategy:
fail-fast: false
matrix:
ruby: ["3.0"]
gemfile: ["gemfiles/rails7.gemfile"]
db: ["sqlite"]
include:
- ruby: "2.7"
gemfile: "gemfiles/rails6.gemfile"
db: "postgres"
- ruby: "3.1"
gemfile: "gemfiles/railsmaster.gemfile"
db: "postgres"
- ruby: "3.0"
gemfile: "gemfiles/rails7.gemfile"
db: "postgres"
- ruby: "2.7"
gemfile: "gemfiles/rails6.gemfile"
db: "sqlite"
- ruby: "3.1"
gemfile: "gemfiles/railsmaster.gemfile"
db: "sqlite"
services:
postgres:
image: postgres:14
Expand Down
35 changes: 20 additions & 15 deletions spec/support/active_record_init.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
# frozen_string_literal: true

connection_params =
if ENV.key?("DATABASE_URL")
{"url" => ENV["DATABASE_URL"]}
else
{
"host" => ENV.fetch("DB_HOST", "localhost"),
"username" => ENV.fetch("DB_USER", "postgres"),
"port" => ENV.fetch("DB_PORT", "9339").to_i
}
DB_CONFIG =
if ENV["DB"] == "postgres"
require "active_record/database_configurations"
url = ENV.fetch("POSTGRES_URL")

config = ActiveRecord::DatabaseConfigurations::UrlConfig.new(
"test",
"primary",
url,
{"database" => ENV.fetch("DB_NAME", "slotted_counters_test")}
)
config.respond_to?(:configuration_hash) ? config.configuration_hash : config.config
elsif ENV["DB"] == "sqlite"
# Make sure we don't have a DATABASE_URL set (it can be used by libs, e.g., database_cleaner)
ENV.delete("DATABASE_URL") if ENV["DATABASE_URL"]

{adapter: "sqlite3", database: ":memory:"}
end

ActiveRecord::Base.establish_connection(
{
"adapter" => "postgresql",
"database" => "slotted_counters_test"
}.merge(connection_params)
)
$stdout.puts "⚙️ Using #{DB_CONFIG[:adapter]} adapter for a database"

ActiveRecord::Base.establish_connection(**DB_CONFIG)

ActiveRecord::Schema.define do
create_table "views", force: :cascade do |t|
Expand Down

0 comments on commit 5de703e

Please sign in to comment.