chrono_model 1.2.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +19 -20
- data/README.md +62 -40
- data/lib/active_record/connection_adapters/chronomodel_adapter.rb +17 -11
- data/lib/active_record/tasks/chronomodel_database_tasks.rb +64 -23
- data/lib/chrono_model/adapter/ddl.rb +168 -153
- data/lib/chrono_model/adapter/indexes.rb +99 -94
- data/lib/chrono_model/adapter/migrations.rb +81 -104
- data/lib/chrono_model/adapter/migrations_modules/legacy.rb +41 -0
- data/lib/chrono_model/adapter/migrations_modules/stable.rb +41 -0
- data/lib/chrono_model/adapter/tsrange.rb +20 -5
- data/lib/chrono_model/adapter/upgrade.rb +89 -91
- data/lib/chrono_model/adapter.rb +64 -31
- data/lib/chrono_model/chrono.rb +17 -0
- data/lib/chrono_model/conversions.rb +15 -9
- data/lib/chrono_model/db_console.rb +9 -0
- data/lib/chrono_model/json.rb +9 -6
- data/lib/chrono_model/patches/as_of_time_holder.rb +2 -2
- data/lib/chrono_model/patches/as_of_time_relation.rb +2 -2
- data/lib/chrono_model/patches/association.rb +15 -12
- data/lib/chrono_model/patches/batches.rb +17 -0
- data/lib/chrono_model/patches/db_console.rb +20 -4
- data/lib/chrono_model/patches/join_node.rb +4 -4
- data/lib/chrono_model/patches/preloader.rb +41 -11
- data/lib/chrono_model/patches/relation.rb +53 -8
- data/lib/chrono_model/patches.rb +3 -1
- data/lib/chrono_model/railtie.rb +29 -24
- data/lib/chrono_model/time_gate.rb +3 -3
- data/lib/chrono_model/time_machine/history_model.rb +65 -31
- data/lib/chrono_model/time_machine/time_query.rb +65 -49
- data/lib/chrono_model/time_machine/timeline.rb +52 -28
- data/lib/chrono_model/time_machine.rb +66 -25
- data/lib/chrono_model/utilities.rb +3 -3
- data/lib/chrono_model/version.rb +3 -1
- data/lib/chrono_model.rb +31 -36
- metadata +39 -136
- data/.gitignore +0 -21
- data/.rspec +0 -2
- data/.travis.yml +0 -41
- data/Gemfile +0 -4
- data/README.sql +0 -161
- data/Rakefile +0 -25
- data/chrono_model.gemspec +0 -33
- data/gemfiles/rails_5.0.gemfile +0 -6
- data/gemfiles/rails_5.1.gemfile +0 -6
- data/gemfiles/rails_5.2.gemfile +0 -6
- data/spec/aruba/dbconsole_spec.rb +0 -25
- data/spec/aruba/fixtures/database_with_default_username_and_password.yml +0 -14
- data/spec/aruba/fixtures/database_without_username_and_password.yml +0 -11
- data/spec/aruba/fixtures/empty_structure.sql +0 -27
- data/spec/aruba/fixtures/migrations/56/20160812190335_create_impressions.rb +0 -10
- data/spec/aruba/fixtures/migrations/56/20171115195229_add_temporal_extension_to_impressions.rb +0 -10
- data/spec/aruba/fixtures/railsapp/config/application.rb +0 -17
- data/spec/aruba/fixtures/railsapp/config/boot.rb +0 -5
- data/spec/aruba/fixtures/railsapp/config/environments/development.rb +0 -38
- data/spec/aruba/migrations_spec.rb +0 -48
- data/spec/aruba/rake_task_spec.rb +0 -71
- data/spec/chrono_model/adapter/base_spec.rb +0 -157
- data/spec/chrono_model/adapter/ddl_spec.rb +0 -243
- data/spec/chrono_model/adapter/indexes_spec.rb +0 -72
- data/spec/chrono_model/adapter/migrations_spec.rb +0 -312
- data/spec/chrono_model/conversions_spec.rb +0 -43
- data/spec/chrono_model/history_models_spec.rb +0 -32
- data/spec/chrono_model/json_ops_spec.rb +0 -59
- data/spec/chrono_model/time_machine/as_of_spec.rb +0 -188
- data/spec/chrono_model/time_machine/changes_spec.rb +0 -50
- data/spec/chrono_model/time_machine/counter_cache_race_spec.rb +0 -46
- data/spec/chrono_model/time_machine/default_scope_spec.rb +0 -37
- data/spec/chrono_model/time_machine/history_spec.rb +0 -104
- data/spec/chrono_model/time_machine/keep_cool_spec.rb +0 -27
- data/spec/chrono_model/time_machine/manipulations_spec.rb +0 -84
- data/spec/chrono_model/time_machine/model_identification_spec.rb +0 -46
- data/spec/chrono_model/time_machine/sequence_spec.rb +0 -74
- data/spec/chrono_model/time_machine/sti_spec.rb +0 -100
- data/spec/chrono_model/time_machine/time_query_spec.rb +0 -261
- data/spec/chrono_model/time_machine/timeline_spec.rb +0 -63
- data/spec/chrono_model/time_machine/timestamps_spec.rb +0 -43
- data/spec/chrono_model/time_machine/transactions_spec.rb +0 -69
- data/spec/config.travis.yml +0 -5
- data/spec/config.yml.example +0 -9
- data/spec/spec_helper.rb +0 -33
- data/spec/support/adapter/helpers.rb +0 -53
- data/spec/support/adapter/structure.rb +0 -44
- data/spec/support/aruba.rb +0 -44
- data/spec/support/connection.rb +0 -70
- data/spec/support/matchers/base.rb +0 -56
- data/spec/support/matchers/column.rb +0 -99
- data/spec/support/matchers/function.rb +0 -79
- data/spec/support/matchers/index.rb +0 -69
- data/spec/support/matchers/schema.rb +0 -39
- data/spec/support/matchers/table.rb +0 -275
- data/spec/support/time_machine/helpers.rb +0 -47
- data/spec/support/time_machine/structure.rb +0 -111
- data/sql/json_ops.sql +0 -56
- data/sql/uninstall-json_ops.sql +0 -24
data/.travis.yml
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
sudo: false
|
2
|
-
|
3
|
-
language: ruby
|
4
|
-
cache: bundler
|
5
|
-
|
6
|
-
rvm:
|
7
|
-
- 2.3
|
8
|
-
- 2.4
|
9
|
-
- 2.5
|
10
|
-
|
11
|
-
gemfile:
|
12
|
-
- gemfiles/rails_5.0.gemfile
|
13
|
-
- gemfiles/rails_5.1.gemfile
|
14
|
-
- gemfiles/rails_5.2.gemfile
|
15
|
-
|
16
|
-
addons:
|
17
|
-
code_climate:
|
18
|
-
repo_token: dedfb7472ee410eec459bff3681d9a8fd8dd237e9bd7e8675a7c8eb7e253bba9
|
19
|
-
|
20
|
-
postgresql: "10"
|
21
|
-
apt:
|
22
|
-
packages:
|
23
|
-
- postgresql-10
|
24
|
-
- postgresql-client-10
|
25
|
-
|
26
|
-
before_install:
|
27
|
-
- sudo sed -i -e '/local.*peer/s/postgres/all/' -e 's/peer\|md5/trust/g' /etc/postgresql/*/main/pg_hba.conf
|
28
|
-
- sudo /etc/init.d/postgresql restart
|
29
|
-
- sleep 2
|
30
|
-
- psql -c "CREATE DATABASE chronomodel;" -U postgres
|
31
|
-
- psql -c "CREATE DATABASE chronomodel_railsapp;" -U postgres
|
32
|
-
|
33
|
-
env:
|
34
|
-
global:
|
35
|
-
- PGPORT=5433
|
36
|
-
|
37
|
-
script:
|
38
|
-
- bundle exec rake TEST_CONFIG=./spec/config.travis.yml
|
39
|
-
|
40
|
-
after_success:
|
41
|
-
- bundle exec codeclimate-test-reporter
|
data/Gemfile
DELETED
data/README.sql
DELETED
@@ -1,161 +0,0 @@
|
|
1
|
-
------------------------------------------------------
|
2
|
-
-- Temporal schema for an example "countries" relation
|
3
|
-
--
|
4
|
-
-- http://github.com/ifad/chronomodel
|
5
|
-
--
|
6
|
-
create schema temporal; -- schema containing all temporal tables
|
7
|
-
create schema history; -- schema containing all history tables
|
8
|
-
|
9
|
-
-- Current countries data - nothing special
|
10
|
-
--
|
11
|
-
create table temporal.countries (
|
12
|
-
id serial primary key,
|
13
|
-
name varchar,
|
14
|
-
updated_at timestamptz
|
15
|
-
);
|
16
|
-
|
17
|
-
-- Countries historical data.
|
18
|
-
--
|
19
|
-
-- Inheritance is used to avoid duplicating the schema from the main table.
|
20
|
-
-- Please note that columns on the main table cannot be dropped, and other caveats
|
21
|
-
-- http://www.postgresql.org/docs/9.0/static/ddl-inherit.html#DDL-INHERIT-CAVEATS
|
22
|
-
--
|
23
|
-
create table history.countries (
|
24
|
-
hid serial primary key,
|
25
|
-
validity tsrange,
|
26
|
-
recorded_at timestamp not null default timezone('UTC', now()),
|
27
|
-
|
28
|
-
constraint overlapping_times exclude using gist ( id with =, validity with && )
|
29
|
-
|
30
|
-
) inherits ( temporal.countries );
|
31
|
-
|
32
|
-
-- Inherited primary key
|
33
|
-
create index country_inherit_pkey on history.countries ( id );
|
34
|
-
|
35
|
-
-- Snapshot of data at a specific point in time
|
36
|
-
create index country_snapshot on history.countries USING gist ( validity );
|
37
|
-
|
38
|
-
-- Used by the trigger functions when UPDATE'ing and DELETE'ing
|
39
|
-
create index country_lower_validity on history.countries ( lower(validity) )
|
40
|
-
create index country_upper_validity on history.countries ( upper(validity) )
|
41
|
-
create index country_recorded_at on history.countries ( id, valid_to )
|
42
|
-
|
43
|
-
-- Single instance whole history
|
44
|
-
create index country_instance_history on history.countries ( id, recorded_at )
|
45
|
-
|
46
|
-
|
47
|
-
-- The countries view, what the Rails' application ORM will actually CRUD on,
|
48
|
-
-- and the entry point of the temporal triggers.
|
49
|
-
--
|
50
|
-
-- SELECT - return only current data
|
51
|
-
--
|
52
|
-
create view public.countries as select * from only temporal.countries;
|
53
|
-
|
54
|
-
-- INSERT - insert data both in the current data table and in the history one.
|
55
|
-
--
|
56
|
-
create or replace function public.chronomodel_countries_insert() returns trigger as $$
|
57
|
-
begin
|
58
|
-
if new.id is null then
|
59
|
-
new.id = nextval('temporal.countries_id_seq');
|
60
|
-
end if;
|
61
|
-
|
62
|
-
insert into temporal.countries ( id, name, updated_at )
|
63
|
-
values ( new.id, new.name, new.updated_at );
|
64
|
-
|
65
|
-
insert into history.countries (id, name, updated_at, validity )
|
66
|
-
values ( new.id, new.name, new.updated_at, tsrange(timezone('utc', now()), null) );
|
67
|
-
|
68
|
-
return new;
|
69
|
-
end;
|
70
|
-
$$ language plpgsql;
|
71
|
-
|
72
|
-
create trigger chronomodel_insert
|
73
|
-
instead of insert on public.countries
|
74
|
-
for each row execute procedure public.chronomodel_countries_insert();
|
75
|
-
|
76
|
-
-- UPDATE - set the last history entry validity to now, save the current data
|
77
|
-
-- in a new history entry and update the temporal table with the new data.
|
78
|
-
--
|
79
|
-
-- If a row in the history with the current ID and current timestamp already
|
80
|
-
-- exists, update it with new data. This logic makes possible to "squash"
|
81
|
-
-- together changes made in a transaction in a single history row.
|
82
|
-
--
|
83
|
-
-- If the update doesn't change the data, it is skipped and the trigger
|
84
|
-
-- returns NULL.
|
85
|
-
--
|
86
|
-
-- By default, history is not recorded if only the updated_at field
|
87
|
-
-- is changed.
|
88
|
-
--
|
89
|
-
create function chronomodel_countries_update() returns trigger as $$
|
90
|
-
declare _now timestamp;
|
91
|
-
declare _hid integer;
|
92
|
-
declare _old record;
|
93
|
-
declare _new record;
|
94
|
-
begin
|
95
|
-
|
96
|
-
if old is not distinct from new then
|
97
|
-
return null;
|
98
|
-
end if;
|
99
|
-
|
100
|
-
_old := row(old.name);
|
101
|
-
_new := row(new.name);
|
102
|
-
|
103
|
-
if _old is not distinct from new then
|
104
|
-
update only temporal.countries set ( name, updated_at ) = ( new.name, new.updated_at ) where id = old.id
|
105
|
-
return new;
|
106
|
-
end if;
|
107
|
-
|
108
|
-
_now := timezone('utc', now());
|
109
|
-
_hid := null;
|
110
|
-
|
111
|
-
select hid into _hid from history.countries where id = old.id and lower(validity) = _now;
|
112
|
-
|
113
|
-
if _hid is not null then
|
114
|
-
update history.countries set ( name, updated_at ) = ( new.name ) where hid = _hid;
|
115
|
-
else
|
116
|
-
update history.countries set validity = tsrange(lower(validity), _now)
|
117
|
-
where id = old.id and upper_inf(validity);
|
118
|
-
|
119
|
-
insert into history.countries ( id, name, updated_at, validity )
|
120
|
-
values ( old.id, new.name, new.updated_at, tsrange(_now, null) );
|
121
|
-
end if;
|
122
|
-
|
123
|
-
update only temporal.countries set ( name ) = ( new.name ) where id = old.id;
|
124
|
-
|
125
|
-
return new;
|
126
|
-
end;
|
127
|
-
$$ language plpgsql;
|
128
|
-
|
129
|
-
create trigger chronomodel_update
|
130
|
-
instead of update on temporal.countries
|
131
|
-
for each row execute procedure chronomodel_countries_update();
|
132
|
-
|
133
|
-
-- DELETE - save the current data in the history and eventually delete the
|
134
|
-
-- data from the temporal table.
|
135
|
-
--
|
136
|
-
-- The first DELETE is required to remove history for records INSERTed and
|
137
|
-
-- DELETEd in the same transaction.
|
138
|
-
--
|
139
|
-
create or replace function chronomodel_countries_delete() returns trigger as $$
|
140
|
-
declare _now timestamp;
|
141
|
-
begin
|
142
|
-
_now := timezone('utc', now());
|
143
|
-
|
144
|
-
delete from history.countries
|
145
|
-
where id = old.id and validity = tsrange(_now, null);
|
146
|
-
|
147
|
-
update history.countries set valid_to = _now
|
148
|
-
where id = old.id and upper_inf(validity);
|
149
|
-
|
150
|
-
delete from only temporal.countries
|
151
|
-
where temporal.id = old.id;
|
152
|
-
|
153
|
-
return old;
|
154
|
-
end;
|
155
|
-
$$ language plpgsql;
|
156
|
-
|
157
|
-
create trigger chronomodel_delete
|
158
|
-
instead of delete on temporal.countries
|
159
|
-
for each row execute procedure chronomodel_countries_delete();
|
160
|
-
|
161
|
-
-- EOF
|
data/Rakefile
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
#!/usr/bin/env rake
|
2
|
-
require "bundler/gem_tasks"
|
3
|
-
|
4
|
-
# RSpec
|
5
|
-
require 'rspec/core/rake_task'
|
6
|
-
RSpec::Core::RakeTask.new do |spec|
|
7
|
-
spec.rspec_opts = '-f doc'
|
8
|
-
end
|
9
|
-
task :default => ['testapp:create', :spec]
|
10
|
-
|
11
|
-
# Create a test Rails app in tmp/railsapp for testing the rake
|
12
|
-
# tasks and overall Rails integration with Aruba.
|
13
|
-
#
|
14
|
-
namespace :testapp do
|
15
|
-
desc 'Create a dummy rails application for testing in /tmp'
|
16
|
-
task :create do
|
17
|
-
FileUtils.mkdir_p('tmp/aruba')
|
18
|
-
Dir.chdir('tmp') do
|
19
|
-
FileUtils.rm_rf('railsapp')
|
20
|
-
sh 'rails new railsapp --skip-bundle'
|
21
|
-
end
|
22
|
-
FileUtils.cp_r('spec/aruba/fixtures/railsapp/.', 'tmp/railsapp/')
|
23
|
-
FileUtils.rm('tmp/railsapp/Gemfile')
|
24
|
-
end
|
25
|
-
end
|
data/chrono_model.gemspec
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path('../lib/chrono_model/version', __FILE__)
|
3
|
-
|
4
|
-
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = ['Marcello Barnaba', 'Peter Joseph Brindisi']
|
6
|
-
gem.email = ['vjt@openssl.it', 'p.brindisi@ifad.org']
|
7
|
-
gem.description = %q{Give your models as-of date temporal extensions. Built entirely for PostgreSQL >= 9.3}
|
8
|
-
gem.summary = %q{Temporal extensions (SCD Type II) for Active Record}
|
9
|
-
gem.homepage = 'https://github.com/ifad/chronomodel'
|
10
|
-
|
11
|
-
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
-
gem.files = `git ls-files`.split("\n")
|
13
|
-
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
-
gem.name = "chrono_model"
|
15
|
-
gem.require_paths = ["lib"]
|
16
|
-
gem.version = ChronoModel::VERSION
|
17
|
-
|
18
|
-
gem.add_dependency 'activerecord', '>= 5.0.0'
|
19
|
-
gem.add_dependency "pg"
|
20
|
-
gem.add_dependency "multi_json"
|
21
|
-
|
22
|
-
gem.add_development_dependency 'rails'
|
23
|
-
gem.add_development_dependency 'aruba'
|
24
|
-
gem.add_development_dependency 'pry'
|
25
|
-
gem.add_development_dependency 'hirb'
|
26
|
-
gem.add_development_dependency 'byebug'
|
27
|
-
gem.add_development_dependency 'rspec'
|
28
|
-
gem.add_development_dependency 'rake'
|
29
|
-
gem.add_development_dependency 'fuubar'
|
30
|
-
gem.add_development_dependency 'simplecov'
|
31
|
-
gem.add_development_dependency 'codeclimate-test-reporter'
|
32
|
-
end
|
33
|
-
|
data/gemfiles/rails_5.0.gemfile
DELETED
data/gemfiles/rails_5.1.gemfile
DELETED
data/gemfiles/rails_5.2.gemfile
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# The db consle does not work on Rails 5.0
|
2
|
-
#
|
3
|
-
unless Bundler.default_gemfile.to_s =~ /rails_5.0/
|
4
|
-
|
5
|
-
|
6
|
-
require 'spec_helper'
|
7
|
-
|
8
|
-
describe 'rails dbconsole' do
|
9
|
-
before do
|
10
|
-
write_file(
|
11
|
-
'config/database.yml',
|
12
|
-
File.read(File.expand_path('fixtures/database_without_username_and_password.yml', __dir__)))
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'rails dbconsole', type: :aruba do
|
16
|
-
let(:action) { run_command("bash -c \"echo 'select 1 as foo_column; \\q' | bundle exec rails db\"") }
|
17
|
-
let(:last_command) { action && last_command_started }
|
18
|
-
|
19
|
-
specify { expect(last_command).to be_successfully_executed }
|
20
|
-
specify { expect(last_command).to have_output(/\bfoo_column\b/) }
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
SET statement_timeout = 0;
|
2
|
-
SET lock_timeout = 0;
|
3
|
-
SET client_encoding = 'UTF8';
|
4
|
-
SET standard_conforming_strings = on;
|
5
|
-
SET check_function_bodies = false;
|
6
|
-
SET client_min_messages = warning;
|
7
|
-
|
8
|
-
--
|
9
|
-
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: -
|
10
|
-
--
|
11
|
-
|
12
|
-
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
|
13
|
-
|
14
|
-
|
15
|
-
--
|
16
|
-
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: -
|
17
|
-
--
|
18
|
-
|
19
|
-
COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
|
20
|
-
|
21
|
-
|
22
|
-
--
|
23
|
-
-- PostgreSQL database dump complete
|
24
|
-
--
|
25
|
-
|
26
|
-
SET search_path TO "$user", public;
|
27
|
-
|
data/spec/aruba/fixtures/migrations/56/20171115195229_add_temporal_extension_to_impressions.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
class AddTemporalExtensionToImpressions < ActiveRecord::Migration[5.0]
|
2
|
-
def self.up
|
3
|
-
enable_extension 'btree_gist' unless extension_enabled?('btree_gist')
|
4
|
-
change_table :impressions, temporal: true, copy_data: true
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.down
|
8
|
-
change_table :impressions, temporal: false
|
9
|
-
end
|
10
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require_relative 'boot'
|
2
|
-
|
3
|
-
require 'rails/all'
|
4
|
-
|
5
|
-
# Require the gems listed in Gemfile, including any gems
|
6
|
-
# you've limited to :test, :development, or :production.
|
7
|
-
Bundler.require(*Rails.groups)
|
8
|
-
|
9
|
-
module Railsapp
|
10
|
-
class Application < Rails::Application
|
11
|
-
# Initialize configuration defaults for originally generated Rails version.
|
12
|
-
config.active_record.schema_format = :sql
|
13
|
-
# Settings in config/environments/* take precedence over those specified here.
|
14
|
-
# Application configuration should go into files in config/initializers
|
15
|
-
# -- all .rb files in that directory are automatically loaded.
|
16
|
-
end
|
17
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
Rails.application.configure do
|
2
|
-
# Settings specified here will take precedence over those in config/application.rb.
|
3
|
-
|
4
|
-
# In the development environment your application's code is reloaded on
|
5
|
-
# every request. This slows down response time but is perfect for development
|
6
|
-
# since you don't have to restart the web server when you make code changes.
|
7
|
-
config.cache_classes = false
|
8
|
-
|
9
|
-
# Do not eager load code on boot.
|
10
|
-
config.eager_load = false
|
11
|
-
|
12
|
-
# Show full error reports.
|
13
|
-
config.consider_all_requests_local = true
|
14
|
-
|
15
|
-
# Don't care if the mailer can't send.
|
16
|
-
config.action_mailer.raise_delivery_errors = false
|
17
|
-
|
18
|
-
# Print deprecation notices to the Rails logger.
|
19
|
-
config.active_support.deprecation = :log
|
20
|
-
|
21
|
-
# Raise an error on page load if there are pending migrations.
|
22
|
-
config.active_record.migration_error = :page_load
|
23
|
-
|
24
|
-
# Debug mode disables concatenation and preprocessing of assets.
|
25
|
-
# This option may cause significant delays in view rendering with a large
|
26
|
-
# number of complex assets.
|
27
|
-
config.assets.debug = true
|
28
|
-
|
29
|
-
# Suppress logger output for asset requests.
|
30
|
-
config.assets.quiet = true
|
31
|
-
|
32
|
-
# Raises error for missing translations
|
33
|
-
# config.action_view.raise_on_missing_translations = true
|
34
|
-
|
35
|
-
# Use an evented file watcher to asynchronously detect changes in source code,
|
36
|
-
# routes, locales, etc. This feature depends on the listen gem.
|
37
|
-
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
|
38
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'database migrations', type: :aruba do
|
4
|
-
context 'after a migration was generated' do
|
5
|
-
before { write_file('config/database.yml',
|
6
|
-
File.read(File.expand_path('fixtures/database_without_username_and_password.yml', __dir__))) }
|
7
|
-
|
8
|
-
before { run_command_and_stop('bundle exec rails g migration CreateModels name:string') }
|
9
|
-
|
10
|
-
describe 'bundle exec rake db:migrate' do
|
11
|
-
let(:action) { run_command('bundle exec rake db:migrate') }
|
12
|
-
let(:last_command) { action && last_command_started }
|
13
|
-
|
14
|
-
specify { expect(last_command).to be_successfully_executed }
|
15
|
-
specify { expect(last_command).to have_output(/CreateModels: migrated/) }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
describe 'rerun bundle exec rake db:drop db:create db:migrate', issue: 56 do
|
21
|
-
let(:command) { 'bundle exec rake db:drop db:create db:migrate' }
|
22
|
-
before do
|
23
|
-
copy(
|
24
|
-
'../../spec/aruba/fixtures/database_without_username_and_password.yml',
|
25
|
-
'config/database.yml'
|
26
|
-
)
|
27
|
-
copy(
|
28
|
-
'../../spec/aruba/fixtures/migrations/56/',
|
29
|
-
'db/migrate'
|
30
|
-
)
|
31
|
-
end
|
32
|
-
|
33
|
-
let(:action) { run_command(command) }
|
34
|
-
let(:regex) { /-- change_table\(:impressions, {:temporal=>true, :copy_data=>true}\)/ }
|
35
|
-
|
36
|
-
describe 'once' do
|
37
|
-
let(:last_command) { action && last_command_started }
|
38
|
-
specify { expect(last_command).to be_successfully_executed }
|
39
|
-
specify { expect(last_command).to have_output(regex) }
|
40
|
-
end
|
41
|
-
|
42
|
-
describe 'twice' do
|
43
|
-
let(:last_command) { run_command_and_stop(command) && action && last_command_started }
|
44
|
-
specify { expect(last_command).to be_successfully_executed }
|
45
|
-
specify { expect(last_command).to have_output(regex) }
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
# add :announce_stdout, :announce_stderr, before the type: aruba tag in order
|
4
|
-
# to see the commmands' stdout and stderr output.
|
5
|
-
#
|
6
|
-
describe 'rake tasks', type: :aruba do
|
7
|
-
describe 'bundle exec rake -T' do
|
8
|
-
before { run_command_and_stop('bundle exec rake -T') }
|
9
|
-
subject { last_command_started }
|
10
|
-
|
11
|
-
it { is_expected.to have_output(/db:structure:load/) }
|
12
|
-
end
|
13
|
-
|
14
|
-
describe 'db:structure:load' do
|
15
|
-
let(:action) { run_command('bundle exec rake db:structure:load') }
|
16
|
-
let(:last_command) { action && last_command_started }
|
17
|
-
|
18
|
-
context 'given a file db/structure.sql' do
|
19
|
-
let(:structure_sql) { 'fixtures/empty_structure.sql' }
|
20
|
-
before { write_file('db/structure.sql', File.read(File.expand_path(structure_sql, __dir__))) }
|
21
|
-
before { write_file('config/database.yml', File.read(File.expand_path(database_yml, __dir__))) }
|
22
|
-
|
23
|
-
subject { expect(last_command).to be_successfully_executed }
|
24
|
-
|
25
|
-
context 'with default username and password', issue: 55 do
|
26
|
-
let(:database_yml) { 'fixtures/database_with_default_username_and_password.yml' }
|
27
|
-
|
28
|
-
# Handle Homebrew on MacOS, whose database superuser name is
|
29
|
-
# equal to the name of the current user.
|
30
|
-
#
|
31
|
-
before do
|
32
|
-
if which 'brew'
|
33
|
-
file_mangle!('config/database.yml') do |contents|
|
34
|
-
contents.sub('username: postgres', "username: #{Etc.getlogin}")
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
specify { subject }
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'without a specified username and password', issue: 55 do
|
43
|
-
let(:database_yml) { 'fixtures/database_without_username_and_password.yml' }
|
44
|
-
|
45
|
-
specify { subject }
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe 'db:data:dump' do
|
51
|
-
let(:database_yml) { 'fixtures/database_without_username_and_password.yml' }
|
52
|
-
before { write_file('config/database.yml', File.read(File.expand_path(database_yml, __dir__))) }
|
53
|
-
|
54
|
-
before { run_command_and_stop('bundle exec rake db:data:dump DUMP=db/test.sql') }
|
55
|
-
|
56
|
-
it { expect(last_command_started).to be_successfully_executed }
|
57
|
-
it { expect('db/test.sql').to be_an_existing_file }
|
58
|
-
end
|
59
|
-
|
60
|
-
describe 'db:data:load' do
|
61
|
-
let(:database_yml) { 'fixtures/database_without_username_and_password.yml' }
|
62
|
-
before { write_file('config/database.yml', File.read(File.expand_path(database_yml, __dir__))) }
|
63
|
-
|
64
|
-
let(:structure_sql) { 'fixtures/empty_structure.sql' }
|
65
|
-
before { write_file('db/test.sql', File.read(File.expand_path(structure_sql, __dir__))) }
|
66
|
-
|
67
|
-
before { run_command_and_stop('bundle exec rake db:data:load DUMP=db/test.sql') }
|
68
|
-
|
69
|
-
it { expect(last_command_started).to be_successfully_executed }
|
70
|
-
end
|
71
|
-
end
|