1

I have read this two questions:

Is there a MySQL option/feature to track history of changes to records?

How to version control a record in a database

I understood how the version system should work but I have a a particular question for my situation.

For example I have this table:

DB record example

Let us say that this table has around 4000 records in it. I will display to the user 100 records once based on a preset configuration, for example display all record where record A value is foo.

The user now has the possibility to change any of the 100 records, for example let us say that he changes 4 records and he leaves the other 96 records untouched.

My question is:

If the user changes only 4 record from the preset configuration what is the best way to keep track of the changes and beside that the track of configurations (the way that the 100 record looked like in a particular date before changing).

I can add a start_date and end_date fields to keep track of the configurations in another table but it doesn't feel right to have a table and fill it with 100 record from which only 4 record changed just to be able to know how the configuration looked at a certain date and what record changed according to the version from that date. At the end I will end up with hundreds of duplicated content that has only the date field different. What is the ideal solution for this situation?


Later Edit: The main idea is to obtain something like this: Version set history

I want to be able to see each configuration version (version 1, 2, 3, 4) from the specific creation date. Each configuration is containing old rows (from previous configuration version) + the rows modified by the user in the new version.

Community
  • 1
  • 1
Starlays
  • 999
  • 1
  • 10
  • 27
  • consider more tables. One being a session for edits. Another a history table. A third being a Junction Table – Drew Nov 19 '15 at 18:55
  • Hmm. Ok then when the user will take the same 100 record again and modify only 6 record from 100, I have to add another 100 record in to the history table to be able to see how the last configuration for the 100 records looked liked on a older version? – Starlays Nov 19 '15 at 18:58
  • I was never suggesting writing out again that which never changed – Drew Nov 19 '15 at 18:59
  • Then I don't know how it should be done, this is why I'm asking. – Starlays Nov 19 '15 at 19:00
  • A high level question that needs to be answered is: Do you want version numbers or would you rather want to know what was the configuration as of this timestamp – Drew Nov 19 '15 at 19:00
  • From my point of view if it reduces the amount of data both of them. – Starlays Nov 19 '15 at 19:02
  • well design in 1 and design it well. Because those two choices vector off in wildly different implementations – Drew Nov 19 '15 at 19:02
  • How? I don't know how to do that. If I keep the whay the configuration looked at a certain date then I will have duplicate records, so how should be done? – Starlays Nov 19 '15 at 19:03
  • We can help with that but choose one first – Drew Nov 19 '15 at 19:03
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/95617/discussion-between-starlays-and-drew). – Starlays Nov 19 '15 at 19:05

1 Answers1

1

Based on our chat discussion, and this link as a talking point,

consider the following schema and expand upon it.

-- drop table bom
create table bom
(   -- Bill of Materials
    bomId int auto_increment primary key
    -- other high level fields
);

-- drop table bomVersion
create table bomVersion
(   -- Bill of Materials / version
    id int auto_increment primary key,
    bomId int not null,
    -- other high level fields
    version int not null, -- you need to figure out how to increment this, and it is not an auto inc here
    description varchar(1000), -- ie: let's add a Floppy Drive
    creationDate datetime not null,
    unique key(bomId,version),  -- no dupes
    -- yes, (bomId,version) could be the PK but I chose not to
    CONSTRAINT fk_version_bom FOREIGN KEY (bomId) REFERENCES bom(bomId)
);

-- drop table bvDetails;
create table bvDetails
(   -- Bill of Materials / Version / Details
    id int auto_increment primary key,
    bvId int not null,
    lineNumber int not null, -- if ordering is important
    partId int not null,
    qty int not null,   --  I am no BOM expert, is this stuff in there?
    price decimal(12,2) not null, --    I am no BOM expert, is this stuff in there?
    -- FK constraints back to Part table and bvId, below shows one of them
    CONSTRAINT fk_det_bomversion FOREIGN KEY (bvId) REFERENCES bomVersion(id)
);

One of the biggest challenges is how to capture the changes made in Part descriptions if they change. So in that link at the very top, if that Case SX1040 has a change in description from Easy Access to Easy Access / Well vented.

So in that case a re-print of a BOM (that was supposed to be nailed down by ISO standards) is going to change. That is not good. So you need to have an audit, a history, of changes to rows that are textual, and save those ids (like for the Part Number). So to be clear, though you can have a Parts table, also have a PartsHistory table (and the id's from the latter go in the bom).

The numerics like price and qty are cool to save like in the above schema. It is the textual history changes that is problematic, and you need to solve that as described in the previous paragraph.


Note, I once wrote a system where in the case of changes to the text columns, we would keep all the revisions all in the same table and have only 1 row (say, for that part) marked as active='Y' for any given item. This way a join was not necessary to the other history table. Either way, you have flexibility from your GUI to select which version you want. Remember from an audit standpoint, you need to have an updateBy (personId) and an updatedDt in these tables.

Edit

Your question just changed. See new column in table bomVersion

Drew
  • 24,120
  • 9
  • 38
  • 72
  • I have re-read you answer, the part description will not be replaced it will be replaced with a completely new part, you are not allowed to change the specification of material witch is standard, I forgot to tell you that. I think the database layout will be simpler in this case, right? – Starlays Nov 21 '15 at 20:54
  • right. I am answering this generically, to help those that follow and in which that applies – Drew Nov 21 '15 at 21:01
  • I still don't get it: I did what you said http://imgur.com/auzTf6n, How i will be able to see the version set for boomversion ID 2 fore example? – Starlays Nov 22 '15 at 20:10
  • Hmm, I want to obtain something like this: http://imgur.com/njMlgPX . I want to be able to see a certain version from a certain date and I think the only way is to store material ID adn quantity from the boom and store them in a history_table_boom but my concern was that I will have duplicate records. – Starlays Nov 22 '15 at 21:17
  • I don't know how I will be able to see version 1, version 2, version 3, version 4 with the 3 tables BOM, BOMVERSION and BVDETAILS and I don't know where to save what when I modify a record in BVDETAILS to be able to save the actual configuration ( I need to see all the rows not just changed records in that version, the exact configuration old rows + moidified rows). I don't know what workflow should I implement. – Starlays Nov 22 '15 at 21:38
  • I want to be able to see each configuration version (version 1, 2, 3, 4) from the specific creation date, basically the history of revisions. Each configuration is containing old rows (from previous configuration version) + the rows modified by the user in the new version. This is what I don't understand how can I obtain the configuration set from BVDETAILS? – Starlays Nov 22 '15 at 21:49
  • I don't what you to code it for me I want just to understand how this will function because it seems to me that we are speaking different things. – Starlays Nov 22 '15 at 21:53
  • And how I will be able to see let's say version 21 that contains information from all previous version from 1 to 21, how do I know what is the combinations of rows for version 21, version 21 can have rows from all previous versions. – Starlays Nov 22 '15 at 21:57
  • Please take a look at the last picture, I tried to make a example for 4 configuration versions how is the evolution from each version. I tried to make with the same colors what is the user modifying from version to version and how each version is looking. – Starlays Nov 22 '15 at 22:01
  • you can create a GUI to cherry pick individual rows from previous versions and slam them into the new version #21, or you can say, hey, I kinda like version 20, which is a good starting point. Either way, you have a new version 21. So then go in to edit it (make a GUI for that). When you are deep in love with #21, ship it to the factory. Until you ship it, it is just a fanciful thought that is a work-in-progress with a status column reflecting that fact. Create a status column. Think outside the box and be creative – Drew Nov 22 '15 at 22:03
  • My question is not how to build the new version, Is more on how to store and later to be able to see the exact configuration set. – Starlays Nov 22 '15 at 22:06
  • How can I see a configuration set from the tables? For example version 4 from the last image. – Starlays Nov 22 '15 at 22:10
  • sorry, you marked it as not answered. Perhaps the next guy can help – Drew Nov 22 '15 at 22:11
  • It was unclear to me how it works, but after reading about event sourcing I think I have figure out how it should be done. Thanks once more. – Starlays Nov 24 '15 at 22:08