我需要一个关系数据库模式来存储vCard ver 3数据元素。
我没有阅读RFC并从头开始设计,而是希望看看已经做过此操作的人是否愿意分享他们的数据库设计。
答案 0 :(得分:9)
(http://i.stack.imgur.com/61qGU.png)
这是我的VCard 3.0数据库架构。这对CardMe库非常有效,每种类型都映射到数据库表,并且通过外键强制执行多对多/一对多关系。
CREATE DATABASE ERP;
CREATE TABLE ERP.CONTACT_MAIL_ADDRESS
(
MAIL_ADDRESS_ID CHAR(36) NOT NULL,
POBOX VARCHAR(30),
EXTENDED_ADDRESS VARCHAR(255),
STREET VARCHAR(255) NOT NULL,
LOCALITY VARCHAR(50),
REGION VARCHAR(50),
POSTAL_CODE VARCHAR(30),
COUNTRY VARCHAR(50),
PRIMARY KEY(MAIL_ADDRESS_ID)
);
CREATE TABLE ERP.CONTACT_PHONE_NUMBER
(
PHONE_NUMBER_ID CHAR(36) NOT NULL,
LOCAL_NUMBER VARCHAR(255) NOT NULL, -- Free form telephone number
PRIMARY KEY(PHONE_NUMBER_ID)
);
CREATE TABLE ERP.CONTACT_EMAIL
(
EMAIL_ID CHAR(36) NOT NULL,
EMAIL_ADDRESS VARCHAR(255) NOT NULL,
PRIMARY KEY(EMAIL_ID)
);
CREATE TABLE ERP.CONTACT_AGENT
(
AGENT_ID CHAR(36) NOT NULL,
URI VARCHAR(255) NOT NULL,
PRIMARY KEY(AGENT_ID)
);
CREATE TABLE ERP.CONTACT_CATEGORIES
(
CATEGORY_ID CHAR(36) NOT NULL,
CATEGORY_NAME VARCHAR(255) NOT NULL,
PRIMARY KEY(CATEGORY_ID)
);
CREATE TABLE ERP.CONTACT_NOTE
(
NOTE_ID CHAR(36) NOT NULL,
NOTE TEXT NOT NULL,
PRIMARY KEY(NOTE_ID)
);
CREATE TABLE ERP.CONTACT_XTENDED
(
XTENDED_ID CHAR(36) NOT NULL,
XNAME VARCHAR(255) NOT NULL,
XVALUE VARCHAR(255) NOT NULL,
PRIMARY KEY(XTENDED_ID)
);
CREATE TABLE ERP.CONTACT_KEYS
(
KEY_ID CHAR(36) NOT NULL,
KEY_DATA TEXT NOT NULL,
PRIMARY KEY(KEY_ID)
);
CREATE TABLE ERP.CONTACT_DATA
(
CONTACT_DATA_ID CHAR(36) NOT NULL,
DATA_NAME VARCHAR(10) NOT NULL, -- [LOGO,PHOTO,SOUND]
URL VARCHAR(255),
INLINE CHAR(1),
DATA MEDIUMBLOB,
PRIMARY KEY(CONTACT_DATA_ID)
);
CREATE TABLE ERP.CONTACT_TYPES
(
TYPE_ID CHAR(36) NOT NULL,
TYPE_NAME VARCHAR(20) NOT NULL,
PRIMARY KEY(TYPE_ID)
);
CREATE TABLE ERP.CONTACT_ENCODING_TYPES
(
ENCODING_TYPE_ID CHAR(36) NOT NULL,
TYPE_NAME VARCHAR(20) NOT NULL,
PRIMARY KEY(ENCODING_TYPE_ID)
);
CREATE TABLE ERP.CONTACT
(
CONTACT_ID CHAR(36) NOT NULL,
FN VARCHAR(255) NOT NULL,
N VARCHAR(255) NOT NULL,
NICKNAME VARCHAR(255),
BDAY TIMESTAMP,
MAILER VARCHAR(50),
TZ INTEGER, -- Time zone offset in hours
GEO_LAT DOUBLE, -- Latitude
GEO_LONG DOUBLE, -- Longitude
TITLE VARCHAR(50),
ROLE VARCHAR(50),
PROD_ID VARCHAR(255),
REV VARCHAR(50),
SORT_STRING VARCHAR(50),
UID VARCHAR(255),
URL VARCHAR(255),
VERSION VARCHAR(10),
CLASS VARCHAR(50),
PRIMARY KEY(CONTACT_ID)
);
CREATE TABLE ERP.CONTACT_REL_MAIL_ADDRESS
(
CONTACT_ID CHAR(36) NOT NULL,
MAIL_ADDRESS_ID CHAR(36) NOT NULL,
FOREIGN KEY(CONTACT_ID) REFERENCES ERP.CONTACT(CONTACT_ID),
FOREIGN KEY(MAIL_ADDRESS_ID) REFERENCES ERP.CONTACT_MAIL_ADDRESS(MAIL_ADDRESS_ID),
PRIMARY KEY(CONTACT_ID,MAIL_ADDRESS_ID)
);
CREATE TABLE ERP.CONTACT_REL_PHONE_NUMBER
(
CONTACT_ID CHAR(36) NOT NULL,
PHONE_NUMBER_ID CHAR(36) NOT NULL,
FOREIGN KEY(CONTACT_ID) REFERENCES ERP.CONTACT(CONTACT_ID),
FOREIGN KEY(PHONE_NUMBER_ID) REFERENCES ERP.CONTACT_PHONE_NUMBER(PHONE_NUMBER_ID),
PRIMARY KEY(CONTACT_ID,PHONE_NUMBER_ID)
);
CREATE TABLE ERP.CONTACT_REL_EMAIL
(
CONTACT_ID CHAR(36) NOT NULL,
EMAIL_ID CHAR(36) NOT NULL,
FOREIGN KEY(CONTACT_ID) REFERENCES ERP.CONTACT(CONTACT_ID),
FOREIGN KEY(EMAIL_ID) REFERENCES ERP.CONTACT_EMAIL(EMAIL_ID),
PRIMARY KEY(CONTACT_ID,EMAIL_ID)
);
CREATE TABLE ERP.CONTACT_REL_CATEGORIES
(
CONTACT_ID CHAR(36) NOT NULL,
CATEGORY_ID CHAR(36) NOT NULL,
FOREIGN KEY(CONTACT_ID) REFERENCES ERP.CONTACT(CONTACT_ID),
FOREIGN KEY(CATEGORY_ID) REFERENCES ERP.CONTACT_CATEGORIES(CATEGORY_ID),
PRIMARY KEY(CONTACT_ID,CATEGORY_ID)
);
CREATE TABLE ERP.CONTACT_REL_NOTE
(
CONTACT_ID CHAR(36) NOT NULL,
NOTE_ID CHAR(36) NOT NULL,
FOREIGN KEY(CONTACT_ID) REFERENCES ERP.CONTACT(CONTACT_ID),
FOREIGN KEY(NOTE_ID) REFERENCES ERP.CONTACT_NOTE(NOTE_ID),
PRIMARY KEY(CONTACT_ID,NOTE_ID)
);
CREATE TABLE ERP.CONTACT_REL_DATA
(
CONTACT_ID CHAR(36) NOT NULL,
CONTACT_DATA_ID CHAR(36) NOT NULL,
FOREIGN KEY(CONTACT_ID) REFERENCES ERP.CONTACT(CONTACT_ID),
FOREIGN KEY(CONTACT_DATA_ID) REFERENCES ERP.CONTACT_DATA(CONTACT_DATA_ID),
PRIMARY KEY(CONTACT_ID,CONTACT_DATA_ID)
);
CREATE TABLE ERP.CONTACT_REL_AGENT
(
CONTACT_ID CHAR(36) NOT NULL,
AGENT_ID CHAR(36) NOT NULL,
FOREIGN KEY(CONTACT_ID) REFERENCES ERP.CONTACT(CONTACT_ID),
FOREIGN KEY(AGENT_ID) REFERENCES ERP.CONTACT_AGENT(AGENT_ID),
PRIMARY KEY(CONTACT_ID,AGENT_ID)
);
CREATE TABLE ERP.CONTACT_REL_KEYS
(
CONTACT_ID CHAR(36) NOT NULL,
KEY_ID CHAR(36) NOT NULL,
FOREIGN KEY(CONTACT_ID) REFERENCES ERP.CONTACT(CONTACT_ID),
FOREIGN KEY(KEY_ID) REFERENCES ERP.CONTACT_KEYS(KEY_ID),
PRIMARY KEY(CONTACT_ID,KEY_ID)
);
CREATE TABLE ERP.CONTACT_REL_XTENDED
(
CONTACT_ID CHAR(36) NOT NULL,
XTENDED_ID CHAR(36) NOT NULL,
FOREIGN KEY(CONTACT_ID) REFERENCES ERP.CONTACT(CONTACT_ID),
FOREIGN KEY(XTENDED_ID) REFERENCES ERP.CONTACT_XTENDED(XTENDED_ID),
PRIMARY KEY(CONTACT_ID,XTENDED_ID)
);
CREATE TABLE ERP.CONTACT_MAIL_ADDRESS_REL_TYPES
(
MAIL_ADDRESS_ID CHAR(36) NOT NULL,
TYPE_ID CHAR(36) NOT NULL,
FOREIGN KEY(MAIL_ADDRESS_ID) REFERENCES ERP.CONTACT_MAIL_ADDRESS(MAIL_ADDRESS_ID),
FOREIGN KEY(TYPE_ID) REFERENCES ERP.CONTACT_TYPES(TYPE_ID),
PRIMARY KEY(MAIL_ADDRESS_ID,TYPE_ID)
);
CREATE TABLE ERP.CONTACT_PHONE_NUMBER_REL_TYPES
(
PHONE_NUMBER_ID CHAR(36) NOT NULL,
TYPE_ID CHAR(36) NOT NULL,
FOREIGN KEY(PHONE_NUMBER_ID) REFERENCES ERP.CONTACT_PHONE_NUMBER(PHONE_NUMBER_ID),
FOREIGN KEY(TYPE_ID) REFERENCES ERP.CONTACT_TYPES(TYPE_ID),
PRIMARY KEY(PHONE_NUMBER_ID,TYPE_ID)
);
CREATE TABLE ERP.CONTACT_EMAIL_REL_TYPES
(
EMAIL_ID CHAR(36) NOT NULL,
TYPE_ID CHAR(36) NOT NULL,
FOREIGN KEY(EMAIL_ID) REFERENCES ERP.CONTACT_EMAIL(EMAIL_ID),
FOREIGN KEY(TYPE_ID) REFERENCES ERP.CONTACT_TYPES(TYPE_ID),
PRIMARY KEY(EMAIL_ID,TYPE_ID)
);
CREATE TABLE ERP.CONTACT_NOTE_REL_TYPES
(
NOTE_ID CHAR(36) NOT NULL,
TYPE_ID CHAR(36) NOT NULL,
FOREIGN KEY(NOTE_ID) REFERENCES ERP.CONTACT_NOTE(NOTE_ID),
FOREIGN KEY(TYPE_ID) REFERENCES ERP.CONTACT_TYPES(TYPE_ID),
PRIMARY KEY(NOTE_ID,TYPE_ID)
);
CREATE TABLE ERP.CONTACT_KEY_REL_TYPES
(
KEY_ID CHAR(36) NOT NULL,
TYPE_ID CHAR(36) NOT NULL,
FOREIGN KEY(KEY_ID) REFERENCES ERP.CONTACT_KEYS(KEY_ID),
FOREIGN KEY(TYPE_ID) REFERENCES ERP.CONTACT_TYPES(TYPE_ID),
PRIMARY KEY(KEY_ID,TYPE_ID)
);
CREATE TABLE ERP.CONTACT_DATA_REL_TYPES
(
CONTACT_DATA_ID CHAR(36) NOT NULL,
TYPE_ID CHAR(36) NOT NULL,
FOREIGN KEY(CONTACT_DATA_ID) REFERENCES ERP.CONTACT_DATA(CONTACT_DATA_ID),
FOREIGN KEY(TYPE_ID) REFERENCES ERP.CONTACT_TYPES(TYPE_ID),
PRIMARY KEY(CONTACT_DATA_ID,TYPE_ID)
);
CREATE TABLE ERP.CONTACT_DATA_REL_ENCODING_TYPES
(
CONTACT_DATA_ID CHAR(36) NOT NULL,
ENCODING_TYPE_ID CHAR(36) NOT NULL,
FOREIGN KEY(CONTACT_DATA_ID) REFERENCES ERP.CONTACT_DATA(CONTACT_DATA_ID),
FOREIGN KEY(ENCODING_TYPE_ID) REFERENCES ERP.CONTACT_ENCODING_TYPES(ENCODING_TYPE_ID),
PRIMARY KEY(CONTACT_DATA_ID,ENCODING_TYPE_ID)
);