From a7645346293ed6a912c26d0c50b6f7943f1f3072 Mon Sep 17 00:00:00 2001
From: Kelly Rauchenberger <fefferburbia@gmail.com>
Date: Sat, 28 Jan 2017 12:59:42 -0500
Subject: Restructured verb frame schema to be more queryable

Groups are much less significant now, and they no longer have a database
table, nor are they considered a top level object anymore. Instead of
containing their own role data, that data is folded into the frames so
that it's easier to query; as a result, each group has its own copy of
the frames that it contains. Additionally, parts are considered top
level objects now, and you can query for frames based on attributes of
their indexed parts. Synrestrs are also contained in their own table
now, so that parts can be filtered against their synrestrs; they are
however not considered top level objects.

Created a new type of field, the "join where" or "condition join" field,
which is a normal join field that has a built in condition on a
specified field. This is used to allow creating multiple distinct join
fields from one object to another. This is required for the lemma::form
and frame::part joins, because filters for forms of separate inflections
should not be coalesced; similarly, filters on differently indexed frame
parts should not be coalesced.

Queries can now be ordered, ascending or descending, by a field, in
addition to randomly as before. This is necessary for accessing the
parts of a verb frame in the correct order, but may be useful to an end
user as well.

Fixed a bug with statement generation in that condition groups were not
being surrounded in parentheses, which made mixing OR groups and AND
groups generate inaccurate statements. This has been fixed;
additionally, parentheses are not placed around the top level condition,
and nested condition groups with the same logic type are coalesced, to
make query strings as easy to read as possible.

Also simplified the form::lemma field; it no longer conditions on the
inflection of the form like the lemma::form field does.

Also added a debug flag to statement::getQueryString that makes it
return a query string with all of the bindings filled in, for debug use
only.
---
 generator/schema.sql | 33 +++++++++++++++++++++++----------
 1 file changed, 23 insertions(+), 10 deletions(-)

(limited to 'generator/schema.sql')

diff --git a/generator/schema.sql b/generator/schema.sql
index c3e54d8..33ebc28 100644
--- a/generator/schema.sql
+++ b/generator/schema.sql
@@ -186,19 +186,32 @@ CREATE TABLE `forms_pronunciations` (
 CREATE INDEX `pronunciation_of` ON `forms_pronunciations`(`form_id`);
 CREATE INDEX `spelling_of` ON `forms_pronunciations`(`pronunciation_id`);
 
-CREATE TABLE `groups` (
-  `group_id` INTEGER PRIMARY KEY,
-  `data` BLOB NOT NULL
+CREATE TABLE `frames` (
+  `frame_id` INTEGER NOT NULL,
+  `group_id` INTEGER NOT NULL,
+  'length' INTEGER NOT NULL
 );
 
-CREATE TABLE `frames` (
-  `frame_id` INTEGER PRIMARY KEY,
-  `data` BLOB NOT NULL
+CREATE INDEX `frames_in` ON `frames`(`group_id`);
+
+CREATE TABLE `parts` (
+  `part_id` INTEGER PRIMARY KEY,
+  `frame_id` INTEGER NOT NULL,
+  `part_index` INTEGER NOT NULL,
+  `type` INTEGER NOT NULL,
+  `role` VARCHAR(16),
+  `selrestrs` BLOB,
+  `prepositions` BLOB,
+  `preposition_literality` SMALLINT,
+  `literal_value` VARCHAR(64)
 );
 
-CREATE TABLE `groups_frames` (
-  `group_id` INTEGER NOT NULL,
-  `frame_id` INTEGER NOT NULL
+CREATE INDEX `parts_of` ON `parts`(`frame_id`);
+CREATE UNIQUE INDEX `part_by_frame_index` ON `parts`(`frame_id`, `part_index`);
+
+CREATE TABLE `synrestrs` (
+  `part_id` INTEGER NOT NULL,
+  `synrestr` VARCHAR(32) NOT NULL
 );
 
-CREATE INDEX `frames_in` ON `groups_frames`(`group_id`);
+CREATE INDEX `synrestrs_for` ON `synrestrs`(`part_id`);
-- 
cgit 1.4.1

