Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revamp lists implementation #55

Open
lykahb opened this issue Feb 4, 2016 · 0 comments
Open

Revamp lists implementation #55

lykahb opened this issue Feb 4, 2016 · 0 comments

Comments

@lykahb
Copy link
Owner

lykahb commented Feb 4, 2016

Description

Consider a simple datatype

data Entity {
somevalue :: String,
somelist :: [String]
}

Current schema

Entity references list table. List values table references list table. Triggers remove list row from the list row on entity update/delete.

CREATE TABLE entity (id INTEGER, somevalue VARCHAR, somelist INTEGER);
CREATE TABLE List#String (id INTEGER PRIMARY KEY);
CREATE TABLE List#String#values (id INTEGER REFERENCES List#String(id), ord INTEGER, value VARCHAR);
CREATE TRIGGER ... ON DELETE ...
CREATE TRIGGER ... ON UPDATE ...

Proposed schema

List table is eliminated. Each list has its own table that references entity id or one of its unique keys.

CREATE TABLE entity (id INTEGER, somevalue VARCHAR);
CREATE TABLE entity#somelist (key INTEGER REFERENCES entity (id) ON DELETE CASCADE, ord INTEGER, value VARCHAR);

This opens the way for maps and other complex data structures.

Questions

How can the new schema help solving N+1 query problem?
What is the behavior if the list is inside of an embedded datatype?

Roadmap

The newly added converters may help with this if they do side effects and take entity and its autokey as arguments. A simple way to distinguish between pure and non-pure converter in compile time (TH generation) would be to create two newtypes.

To avoid breaking changes, Groundhog needs to support both schemas for a while. The new schema will be used only if converter is specified. Also, there needs to be a way to do automatic migration from the old schema.

@lykahb lykahb changed the title Revamp lists schema Revamp lists implementation Feb 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant