Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into pnomolos/better_t…
Browse files Browse the repository at this point in the history
…ransparency_for_temporalness
  • Loading branch information
pnomolos committed Nov 25, 2021
2 parents 25b2da6 + 29529f9 commit 4ab3d25
Show file tree
Hide file tree
Showing 31 changed files with 364 additions and 114 deletions.
82 changes: 82 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Ruby specs

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test:
name: Ruby specs
runs-on: ubuntu-latest

services:
db:
image: postgres:12
ports: ['5432:5432']
env:
POSTGRES_HOST_AUTH_METHOD: trust

options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
strategy:
matrix:
ruby-version: ['2.3', '2.4', '2.5', '2.6', '2.7', '3.0']
gemfile: [ rails_5.0, rails_5.1, rails_5.2, rails_6.0, rails_6.1 ]
experimental: [false]

exclude:
- ruby-version: '2.3'
gemfile: rails_6.0
- ruby-version: '2.3'
gemfile: rails_6.1
- ruby-version: '2.4'
gemfile: rails_6.0
- ruby-version: '2.4'
gemfile: rails_6.1
- ruby-version: '2.6'
gemfile: rails_5.0
- ruby-version: '2.6'
gemfile: rails_5.1
- ruby-version: '2.7'
gemfile: rails_5.0
- ruby-version: '2.7'
gemfile: rails_5.1
- ruby-version: '2.7'
gemfile: rails_5.2
- ruby-version: '3.0'
gemfile: rails_5.0
- ruby-version: '3.0'
gemfile: rails_5.1
- ruby-version: '3.0'
gemfile: rails_5.2

env:
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
TEST_CONFIG: ./spec/config.github.yml

continue-on-error: ${{ matrix.experimental }}

steps:
- uses: actions/checkout@v2
- name: Set up Database
run: |
psql -c "CREATE ROLE runner SUPERUSER LOGIN CREATEDB;" -U postgres -h localhost
psql -c "CREATE DATABASE chronomodel;" -U postgres -h localhost
psql -c "CREATE DATABASE chronomodel_railsapp;" -U postgres -h localhost
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true
- name: Run specs and publish code coverage
uses: paambaati/[email protected]
env:
CC_TEST_REPORTER_ID: dedfb7472ee410eec459bff3681d9a8fd8dd237e9bd7e8675a7c8eb7e253bba9
with:
coverageCommand: bundle exec rake
55 changes: 0 additions & 55 deletions .travis.yml

This file was deleted.

13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ All timestamps are _forcibly_ stored in as UTC, bypassing the
## Requirements

* Ruby >= 2.3
* Active Record >= 5.0. See the [detailed supported versions matrix on travis](https://travis-ci.org/ifad/chronomodel)
* Active Record >= 5.0. See the [detailed supported versions matrix on Ruby GitHub Actions workflow](https://github.com/ifad/chronomodel/blob/master/.github/workflows/ruby.yml)
* PostgreSQL >= 9.4 (legacy support for 9.3)
* The `btree_gist` PostgreSQL extension

Expand Down Expand Up @@ -96,6 +96,13 @@ development:
username: ...
```
Configure Active Record in your `config/application.rb` to use the `:sql` schema
format:

```rb
config.active_record.schema_format = :sql
```

## Schema creation

ChronoModel hooks all `ActiveRecord::Migration` methods to make them temporal
Expand Down Expand Up @@ -376,8 +383,8 @@ while using it in many important projects.
This software is Made in Italy :it: :smile:.


[build-status]: https://travis-ci.org/ifad/chronomodel
[build-status-badge]: https://travis-ci.org/ifad/chronomodel.svg
[build-status]: https://github.com/ifad/chronomodel/actions
[build-status-badge]: https://github.com/ifad/chronomodel/actions/workflows/ruby.yml/badge.svg
[code-analysis]: https://codeclimate.com/github/ifad/chronomodel
[code-analysis-badge]: https://codeclimate.com/github/ifad/chronomodel.svg
[docs-analysis]: http://inch-ci.org/github/ifad/chronomodel
Expand Down
3 changes: 1 addition & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env rake
require "bundler/gem_tasks"

# RSpec
Expand All @@ -17,7 +16,7 @@ namespace :testapp do
FileUtils.mkdir_p('tmp/aruba')
Dir.chdir('tmp') do
FileUtils.rm_rf('railsapp')
sh 'rails new railsapp --skip-bundle'
sh 'rails new railsapp --skip-bundle --skip-webpack-install --skip-git'
end
FileUtils.cp_r('spec/aruba/fixtures/railsapp/.', 'tmp/railsapp/')
FileUtils.rm('tmp/railsapp/Gemfile')
Expand Down
2 changes: 0 additions & 2 deletions chrono_model.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,4 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'rake'
gem.add_development_dependency 'fuubar'
gem.add_development_dependency 'simplecov'
gem.add_development_dependency 'codeclimate-test-reporter'
end

5 changes: 5 additions & 0 deletions gemfiles/rails_5.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@ source "https://rubygems.org"
gem "activerecord", "~> 5.0.0"
gem "rails", "~> 5.0.0"

# Fix code coverage on old Ruby versions
if RUBY_VERSION < '2.5'
gem 'simplecov', '< 0.18.0'
end

gemspec :path => "../"
5 changes: 5 additions & 0 deletions gemfiles/rails_5.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@ source "https://rubygems.org"
gem "activerecord", "~> 5.1.0"
gem "rails", "~> 5.1.0"

# Fix code coverage on old Ruby versions
if RUBY_VERSION < '2.5'
gem 'simplecov', '< 0.18.0'
end

gemspec :path => "../"
5 changes: 5 additions & 0 deletions gemfiles/rails_5.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@ source "https://rubygems.org"
gem "activerecord", "~> 5.2.0"
gem "rails", "~> 5.2.0"

# Fix code coverage on old Ruby versions
if RUBY_VERSION < '2.5'
gem 'simplecov', '< 0.18.0'
end

gemspec :path => "../"
6 changes: 6 additions & 0 deletions gemfiles/rails_6.1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source "https://rubygems.org"

gem "activerecord", "~> 6.1.0"
gem "rails", "~> 6.1.0"

gemspec :path => "../"
12 changes: 9 additions & 3 deletions lib/active_record/tasks/chronomodel_database_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def structure_dump(*arguments)
def data_dump(target)
set_psql_env

args = ['-c', '-f', target]
args << configuration['database']
args = ['-c', '-f', target.to_s]
args << configuration[:database]

run_cmd "pg_dump", args, 'dumping data'
end
Expand All @@ -34,13 +34,19 @@ def data_load(source)
set_psql_env

args = ['-f', source]
args << configuration['database']
args << configuration[:database]

run_cmd "psql", args, 'loading data'
end

private

def configuration
# In Rails 6.1.x the configuration instance variable is not available
# and it's been replaced by @configuration_hash (which is frozen).
@configuration ||= @configuration_hash.dup
end

# If a schema search path is defined in the configuration file, it will
# be used by the database tasks class to dump only the specified search
# path. Here we add also ChronoModel's temporal and history schemas to
Expand Down
7 changes: 6 additions & 1 deletion lib/chrono_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def self.history_models
# Checks whether this Active Recoed model is backed by a temporal table
#
def chrono?
return false unless connection.respond_to? :is_chrono?
connection.is_chrono?(table_name)
end
end
Expand Down Expand Up @@ -70,6 +71,10 @@ def chrono?

if defined?(Rails::DBConsole)
Rails::DBConsole.instance_eval do
prepend ChronoModel::Patches::DBConsole
if Rails.version < '6.1'
prepend ChronoModel::Patches::DBConsole::Config
else
prepend ChronoModel::Patches::DBConsole::DbConfig
end
end
end
7 changes: 6 additions & 1 deletion lib/chrono_model/adapter/indexes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,14 @@ def chrono_copy_indexes_to_history(table_name)
next if history_indexes.include?(index.name)

on_history_schema do
# index.columns is an Array for plain indexes,
# while it is a String for computed indexes.
#
columns = Array.wrap(index.columns).join(', ')

execute %[
CREATE INDEX #{index.name} ON #{table_name}
USING #{index.using} ( #{index.columns.join(', ')} )
USING #{index.using} ( #{columns} )
], 'Copy index from temporal to history'
end
end
Expand Down
Loading

0 comments on commit 4ab3d25

Please sign in to comment.