Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So, basically this is a "how do I version text information in my DB".</p> <p>Well, the simplest way is simply copying the data.</p> <p>Simply, create a "version" table that holds "old versions" of the data, and link it back to your main table.</p> <pre><code>create table docs { id integer primary key not null, version integer not null, create_date date, change_date date, create_user_id integer not null references users(id), change_user_id integer references users(id), text_data text } create table versions { id integer primary key not null, doc_id integer not null references docs(id), version integer, change_date date, change_user integer not null references users(id), text_data text } </code></pre> <p>Whenever you update your original document, you copy the old text value in to this table, copy the user and change date and bump the version.</p> <pre><code>select version, change_date, change_user, text_data into l_version, l_change_data, l_change_user, l_text_data from docs where id = l_doc_id; insert into versions values (newid, l_doc_id, l_version, l_change_date, l_change_user, l_text_data); update docs set version = version + 1, change_date = now, change_user = cur_user, text_data = l_new_text where id = l_doc_id; </code></pre> <p>You could even do this in a trigger if your DB supports those.</p> <p>Faults with this method are that its a full copy of the data (so if you have a large document, the version stay large). You can mitigate that by using something like diff(1) and patch(1). </p> <p>For example:</p> <pre><code>diff version2.txt version1.txt &gt; difffile </code></pre> <p>Then you can store that difffile as "version 1".</p> <p>In order to recover version 1 from version 2, you grab the version 2 data, run patch on it using the diff file data, and that gives you v1.</p> <p>If you want to go from v3 to v1, you need to do this twice (once to get v2, and then again to get v1).</p> <p>This lowers your storage burden, but increases your processing (obviously), so you'll have to judge how you want to do this.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload