mirror: add primitives table for EAV migration (#1340)

Summary:
See #1313 for context. The plan is to set up dual-writes with `extract`
calls still reading from the old tables until the new ones are complete
and tested. The primary risk to production would be a fatal exception in
the new write paths, which seems like an acceptable risk.

Test Plan:
Unit tests pass.

wchargin-branch: mirror-eav-schema
This commit is contained in:
William Chargin 2019-09-14 17:21:42 -07:00 committed by GitHub
parent 976afb6665
commit 0418dfe9dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -145,6 +145,10 @@ export class Mirror {
* efficiently in both space and time (see discussion on #883 for
* some options).
*
* NOTE: A migration is underway to switch from type-specific
* primitive tables to a single entity-attribute-value table
* storing primitives for all types. See issue #1313 for details.
*
* We refer to node and primitive data together as "own data", because
* this is the data that can be queried uniformly for all elements of
* a type; querying connection data, by contrast, requires the
@ -192,7 +196,7 @@ export class Mirror {
// it requires bumping the version, bump it: requiring some extra
// one-time cache resets is okay; doing the wrong thing is not.
const blob = stringify({
version: "MIRROR_v3",
version: "MIRROR_v4",
schema: this._schema,
options: {
blacklistedIds: this._blacklistedIds,
@ -253,6 +257,20 @@ export class Mirror {
FOREIGN KEY(last_update) REFERENCES updates(rowid)
)
`,
dedent`\
CREATE TABLE primitives (
rowid INTEGER PRIMARY KEY,
object_id TEXT NOT NULL,
fieldname TEXT NOT NULL,
value, -- JSON string, or SQL 0 or 1 for nest fields
UNIQUE(object_id, fieldname),
FOREIGN KEY(object_id) REFERENCES objects(id)
)
`,
dedent`\
CREATE UNIQUE INDEX idx_primitives__object_id__fieldname
ON primitives (object_id, fieldname)
`,
dedent`\
CREATE TABLE links (
rowid INTEGER PRIMARY KEY,

View File

@ -146,6 +146,7 @@ describe("graphql/mirror", () => {
"meta",
"updates",
"objects",
"primitives",
"links",
"connections",
"connection_entries",