Discussion:
[jifty-devel] additional SQL constraints?
Matt Zagrabelny
2010-09-28 19:58:24 UTC
Permalink
I'm working through some jifty tutorials, particular the Model stuff.
I can use the schema language to create most of the following:

CREATE TABLE incoming_components (
id BIGINT PRIMARY KEY,

-- mac MACADDR,
mac_as_int BIGINT NOT NULL DEFAULT -1,
mac VARCHAR(17) NOT NULL DEFAULT '',

serial_number TEXT NOT NULL DEFAULT '',
model_number TEXT NOT NULL DEFAULT '',

UNIQUE(
mac_as_int,
mac,
serial_number,
model_number
)
);


Do I model the UNIQUE constraints within my AppName::Record schema { } ?

or

Do I add in the constraints as supplementary sql statements?

Thanks for the help,

-matt zagrabelny
Thomas Sibley
2010-09-28 20:26:56 UTC
Permalink
Hi Matt,
Post by Matt Zagrabelny
Do I model the UNIQUE constraints within my AppName::Record schema { } ?
The way to do this is to specify "is distinct" for each column in your
AppName::Record schema { } definition.

Cheers,
Thomas
Matt Zagrabelny
2010-09-28 21:00:34 UTC
Permalink
Post by Thomas Sibley
Hi Matt,
Post by Matt Zagrabelny
Do I model the UNIQUE constraints within my AppName::Record schema { } ?
The way to do this is to specify "is distinct" for each column in your
AppName::Record schema { } definition.
Hmmm. That doesn't seem quite logical. I could have a unique
constraint for each column individually or the *combination* of
multiple columns.

For instance:

CREATE TABLE widgets (
name TEXT,
model_number TEXT,

UNIQUE(name),
UNIQUE(model_number)
);

is very different from:

CREATE TABLE widgets (
name TEXT,
model_number TEXT,

UNIQUE(name, model_number)
);

How does jifty handle the above difference?

or do you manually tweak the DB?

Thanks,

-matt zagrabelny
Thomas Sibley
2010-10-01 19:22:56 UTC
Permalink
Post by Matt Zagrabelny
Hmmm. That doesn't seem quite logical. I could have a unique
constraint for each column individually or the *combination* of
multiple columns.
Jifty only handles the first case with the syntax I mentioned before.
If you want the second case, you'll need to tweak the DB and write a
custom validation routine in your Widgets model to check for the unique
pair.

Thomas
Post by Matt Zagrabelny
CREATE TABLE widgets (
name TEXT,
model_number TEXT,
UNIQUE(name),
UNIQUE(model_number)
);
CREATE TABLE widgets (
name TEXT,
model_number TEXT,
UNIQUE(name, model_number)
);
How does jifty handle the above difference?
or do you manually tweak the DB?
Thanks,
-matt zagrabelny
_______________________________________________
jifty-devel mailing list
http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-devel
Loading...