CourseOrchestra / 2bass

DB schema as code tool

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

idempotent table contents

fiddlededee opened this issue · comments

suggested instruction:
/* BASS CONTENTS {table name} [DELIMITER COMMA | TAB | COLON | SEMICOLON | 'USER DELIMITER' ] UPDATE METHOD [REPLACE | UPDATE] [KEEP TRIGGERS [ALL | FOR MATERIALIZED VIEWS | selected trigger] ENABLED] [VERSION {version number}

FILENAME |

INLINE CONTENTS
field1, field2
field1, field2

*/

The idea is to keep checksum for every defined table contents. If checksum (or version) has changed then the contents of table is updated.

Replace method assumes truncating table and inserting new values. Update methods assume inserting new, deleting excess, updating changed.

Operation assumes that indexed and triggers are turned off, but we can explicitly say to leave triggers on. It is necessary, for example, for materialized views.

Indempotent approach may seem resource consuming. But putting table contents to vcs is useful in a limited number of cases. And in most of this cases we need modest tables. That would be good alternative for option field, for example.

Yes this is exactly what I've been planning for implementation in CelestaSQL for a long period of time.

My idea was to implement something like idempotent version of INSERT statement.

in simplified version we introduce two commands

1 -------------------------------
INSERT {table name} [({comma delimited fields})] VALUES ({comma delimited values})

= INSERT INTO

if field clause is ommited, then we take it from table specification

INSERT is idempotent, works as INSERT OR UPDATE

and there is a question of sequence fields...

2-------------------------------

DELETE... not sure about synax, really we need only key field values, but in ANSI SQL there is no convinient command