CREATE TABLE wf_docevents (
id INT PRIMARY KEY,
doc_id INT NOT NULL,
docstate_id INT NOT NULL,
user_id INT NOT NULL,
docaction_id INT NOT NULL,
data TEXT,
ctime TIMESTAMP NOT NULL,
FOREIGN KEY (doc_id) REFERENCES wf_documents(id),
FOREIGN KEY (docstate_id) REFERENCES wf_docstates_master(id),
FOREIGN KEY (user_id) REFERENCES users_masters(id),
FOREIGN KEY (docaction_id) REFERENCES wf_docactions_master(id)
);

CREATE TABLE wf_docevents (
id INT PRIMARY KEY,
doc_id INT NOT NULL,
docstate_id INT NOT NULL,
user_id INT NOT NULL,
docaction_id INT NOT NULL,
data TEXT,
ctime TIMESTAMP NOT NULL,
applied BOOLEAN NOT NULL,
FOREIGN KEY (doc_id) REFERENCES wf_documents(id),
FOREIGN KEY (docstate_id) REFERENCES wf_docstates_master(id),
FOREIGN KEY (user_id) REFERENCES users_masters(id),
FOREIGN KEY (docaction_id) REFERENCES wf_docactions_master(id)
);

Add a flag to table of document events to track application of events
Add a flag to table of document events to track application of events
