Skip to content
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

Change created_at and deleted_at to transaction_from and transaction_to #38

Merged
merged 22 commits into from
Nov 5, 2020

Conversation

osyo-manga
Copy link
Collaborator

@osyo-manga osyo-manga commented Nov 20, 2019

Summary

Change name created_at and deleted_at columns to transaction_from and transaction_to.

Before

ActiveRecord::Schema.define(version: 1) do
  create_table :employees, force: true do |t|
    t.string :emp_code
    t.string :name

    # Require BTDM columns
    t.integer :bitemporal_id
    t.datetime :valid_from
    t.datetime :valid_to
    t.datetime :created_at   # optional
    t.datetime :deleted_at
  end
end

After

ActiveRecord::Schema.define(version: 1) do
  create_table :employees, force: true do |t|
    t.string :emp_code
    t.string :name

    # Require BTDM columns
    t.integer :bitemporal_id
    t.datetime :valid_from
    t.datetime :valid_to
    t.datetime :transaction_from   # require
    t.datetime :transaction_to
  end
end

NOTE

created_at deleted_at is still supported.
However, it will not be supported in the future.

@osyo-manga osyo-manga force-pushed the add-use-transaction_at branch from 8a541e1 to 884c282 Compare February 3, 2020 08:02
@osyo-manga osyo-manga force-pushed the add-use-transaction_at branch 2 times, most recently from 85d3495 to 59e4524 Compare July 17, 2020 10:00
…d_datetime` in the past than `valid_from`.
Assign `transaction_from` to `created_at` when after create record.
DEPRECATION WARNING: Using `Range#include?` to check the inclusion of a value in a date time range is deprecated. It is recommended to use `Range#cover?` instead of `Range#include?` to check the inclusion of a value in a date time range. (called from block in scope_relation at /lib/activerecord-bitemporal/bitemporal.rb:547)
PR: rails/rails#38186
@osyo-manga osyo-manga force-pushed the add-use-transaction_at branch from cebb0f4 to 0d18569 Compare September 1, 2020 09:21
…me value when created.`

sort by `created_at` is broken.
@osyo-manga osyo-manga marked this pull request as ready for review November 4, 2020 07:24

# Assign only if defined created_at and deleted_at
if has_column?(:created_at)
self.transaction_from = self.created_at if changes.key?("created_at")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case (created_at was changed), it seems valid_from and transaction_from is not the same values.
Is this valid records? Does this cause problems?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, valid_from and transaction_from are not the same because they have different information.
And they are the same by default.

company = Company.create
pp company.created_at.iso8601(10)
# => "2020-11-04T08:18:03.1952580000Z"
pp company.transaction_from.iso8601(10)
# => "2020-11-04T08:18:03.1952580000Z"
pp company.valid_from.iso8601(10)
# => "2020-11-04T08:18:03.1952580000Z"

@@ -373,4 +564,48 @@ class EmployeeWithUniquness < Employee
end
end
end

xdescribe "without created_at deleted_at" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤗

Copy link
Contributor

@wata727 wata727 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@wakasa51 wakasa51 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@osyo-manga
Copy link
Collaborator Author

@wata727 @wakasa51 Thanks!

@osyo-manga osyo-manga merged commit 061ac59 into kufu:master Nov 5, 2020
@osyo-manga osyo-manga deleted the add-use-transaction_at branch November 5, 2020 00:02
@osyo-manga osyo-manga restored the add-use-transaction_at branch November 5, 2020 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants