Created
August 21, 2017 01:50
-
-
Save dongyuwei/12ae28ec03464fd851aa78e0814a13c0 to your computer and use it in GitHub Desktop.
snapshot design for rails's ActiveRecord model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreateSnapShots < ActiveRecord::Migration[5.0] | |
def change | |
create_table :snap_shots do |t| | |
t.integer :user_id | |
t.string :table_name | |
t.text :table_data , limit: 4294967295 | |
t.integer :table_id | |
t.integer :snapshot_id | |
t.timestamps | |
end | |
add_index :snap_shots, :user_id | |
add_index :snap_shots, :table_name | |
add_index :snap_shots, :table_id | |
add_index :snap_shots, :snapshot_id | |
end | |
end |
Author
dongyuwei
commented
Aug 21, 2017
table_id actually is the record_id of the target table.
snapshot_id is the index of all relations of the snapshotted models.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment