Closed mentiflectax closed 8 years ago
Branch for this issue is issue5
.
Note that we have these branches in both 50web and db-api projects.
We have several options to store user type (fan, musician):
CREATE TABLE peeps.attributes (
person_id integer NOT NULL REFERENCES peeps.people(id) ON DELETE CASCADE,
attribute varchar(16) NOT NULL REFERENCES peeps.atkeys(atkey),
plusminus boolean NOT NULL, -- true if yes, false if no
PRIMARY KEY (person_id, attribute)
);
For now, I select the second option for two reasons:
Next question: Isn't there an API function, which allows to set and unset attributes (do we have to write it ourselves, or can we re-use something existing) ?
There is a an existing function:
-- PARAMS: person_id, attribute, plusminus
CREATE OR REPLACE FUNCTION peeps.person_set_attribute(integer, text, boolean,
OUT status smallint, OUT js json) AS $$
DECLARE
m4_ERRVARS
BEGIN
UPDATE peeps.attributes SET plusminus=$3 WHERE person_id=$1 AND attribute=$2;
IF NOT FOUND THEN
INSERT INTO peeps.attributes VALUES ($1, $2, $3);
END IF;
SELECT x.status, x.js INTO status, js FROM peeps.person_attributes($1) x;
m4_ERRCATCH
END;
$$ LANGUAGE plpgsql;
In order for this to work, we need to insert fan
and musician
attributes during setup. See the schema file in the mvp
branch of db-api project.
Merged the fix into the mvp
branches of both projects:
Next steps:
songcontest
schema to save these data. Reference topeeps
(table with the data about people).signup
so that the user type is saved in the table from previous step.