2015-12-06 23:42:50 +00:00
|
|
|
-- Conservancy Supporter Database, Version 0.2
|
2015-01-03 23:02:18 +00:00
|
|
|
|
2015-12-06 23:42:50 +00:00
|
|
|
DROP TABLE IF EXISTS "supporter";
|
|
|
|
|
|
|
|
CREATE TABLE "supporter" (
|
2015-01-03 23:02:18 +00:00
|
|
|
"id" integer NOT NULL PRIMARY KEY,
|
|
|
|
"ledger_entity_id" varchar(300) NOT NULL UNIQUE,
|
|
|
|
"display_name" varchar(300),
|
2015-12-06 23:42:56 +00:00
|
|
|
"public_ack" bool NOT NULL
|
2015-01-03 23:02:18 +00:00
|
|
|
);
|
|
|
|
|
2015-12-06 23:42:53 +00:00
|
|
|
DROP TABLE IF EXISTS "request";
|
|
|
|
|
2015-12-06 23:42:50 +00:00
|
|
|
CREATE TABLE "request" (
|
|
|
|
"id" integer NOT NULL PRIMARY KEY,
|
|
|
|
"supporter_id" integer NOT NULL,
|
|
|
|
"request_type_id" integer NOT NULL,
|
|
|
|
"request_configuration_id" integer,
|
|
|
|
"date_requested" date NOT NULL,
|
2015-12-06 23:43:13 +00:00
|
|
|
"fulfillment_id" integer,
|
2015-12-06 23:42:50 +00:00
|
|
|
"notes" TEXT
|
|
|
|
);
|
|
|
|
|
2015-12-06 23:42:53 +00:00
|
|
|
DROP TABLE IF EXISTS "request_configuration";
|
|
|
|
|
2015-12-06 23:42:50 +00:00
|
|
|
CREATE TABLE "request_configuration" (
|
|
|
|
"id" integer NOT NULL PRIMARY KEY,
|
|
|
|
"request_type_id" integer NOT NULL,
|
2015-12-06 23:42:56 +00:00
|
|
|
"description" varchar(100) NOT NULL
|
2015-12-06 23:42:50 +00:00
|
|
|
);
|
|
|
|
|
2015-12-06 23:42:53 +00:00
|
|
|
DROP TABLE IF EXISTS "fulfillment";
|
|
|
|
|
2015-12-06 23:42:50 +00:00
|
|
|
CREATE TABLE "fulfillment" (
|
|
|
|
"id" integer NOT NULL PRIMARY KEY,
|
|
|
|
"date" TEXT NOT NULL,
|
|
|
|
"who" varchar(300) NOT NULL,
|
2015-12-06 23:42:56 +00:00
|
|
|
"how" TEXT
|
2015-12-06 23:42:50 +00:00
|
|
|
);
|
|
|
|
|
2015-12-06 23:42:53 +00:00
|
|
|
DROP TABLE IF EXISTS "request_type";
|
|
|
|
|
2015-12-06 23:42:50 +00:00
|
|
|
CREATE TABLE "request_type" (
|
|
|
|
"id" integer NOT NULL PRIMARY KEY,
|
2015-12-06 23:42:56 +00:00
|
|
|
"type" varchar(100) NOT NULL
|
2015-12-06 23:42:50 +00:00
|
|
|
);
|
|
|
|
|
2015-12-06 23:42:53 +00:00
|
|
|
DROP TABLE IF EXISTS "email_address";
|
|
|
|
|
2015-12-06 23:42:50 +00:00
|
|
|
CREATE TABLE "email_address" (
|
|
|
|
"id" integer NOT NULL PRIMARY KEY,
|
|
|
|
"email_address" varchar(300) NOT NULL UNIQUE,
|
|
|
|
"type_id" integer,
|
2015-12-06 23:42:56 +00:00
|
|
|
"date_encountered" date NOT NULL
|
2015-12-06 23:42:50 +00:00
|
|
|
);
|
|
|
|
|
2015-12-06 23:42:53 +00:00
|
|
|
DROP TABLE IF EXISTS "supporter_email_address_mapping";
|
|
|
|
|
2015-12-06 23:42:50 +00:00
|
|
|
CREATE TABLE "supporter_email_address_mapping" (
|
|
|
|
"supporter_id" integer NOT NULL,
|
2015-12-06 23:42:56 +00:00
|
|
|
"email_address_id" integer NOT NULL,
|
2015-12-06 23:42:50 +00:00
|
|
|
"preferred" bool,
|
|
|
|
PRIMARY KEY(supporter_id, email_address_id)
|
|
|
|
);
|
|
|
|
|
2015-12-06 23:43:00 +00:00
|
|
|
CREATE UNIQUE INDEX supporter_email_address_mapping__single_prefferred_per_supporter
|
2015-12-06 23:42:53 +00:00
|
|
|
ON supporter_email_address_mapping(supporter_id, preferred);
|
2015-12-06 23:42:50 +00:00
|
|
|
|
2015-12-06 23:42:53 +00:00
|
|
|
DROP TABLE IF EXISTS "address_type";
|
|
|
|
|
2015-12-06 23:42:50 +00:00
|
|
|
CREATE TABLE "address_type" (
|
|
|
|
"id" integer NOT NULL PRIMARY KEY,
|
2015-12-06 23:42:56 +00:00
|
|
|
"name" varchar(50) NOT NULL UNIQUE
|
2015-12-06 23:42:50 +00:00
|
|
|
);
|
|
|
|
|
2015-12-06 23:42:53 +00:00
|
|
|
DROP TABLE IF EXISTS "postal_address";
|
|
|
|
|
2015-12-06 23:42:50 +00:00
|
|
|
CREATE TABLE "postal_address" (
|
|
|
|
"id" integer NOT NULL PRIMARY KEY,
|
|
|
|
"formatted_address" varchar(5000),
|
|
|
|
"type_id" INTEGER NOT NULL,
|
2015-12-06 23:42:56 +00:00
|
|
|
"date_encountered" date NOT NULL
|
2015-12-06 23:42:50 +00:00
|
|
|
);
|
|
|
|
|
2015-12-06 23:42:53 +00:00
|
|
|
DROP TABLE IF EXISTS "supporter_postal_address_mapping";
|
|
|
|
|
2015-12-06 23:42:50 +00:00
|
|
|
CREATE TABLE "supporter_postal_address_mapping" (
|
2015-12-06 23:43:00 +00:00
|
|
|
"supporter_id" integer NOT NULL,
|
|
|
|
"postal_address_id" integer NOT NULL,
|
2015-12-06 23:42:50 +00:00
|
|
|
"preferred" bool,
|
2015-12-06 23:43:00 +00:00
|
|
|
PRIMARY KEY(supporter_id, postal_address_id)
|
2015-12-06 23:42:50 +00:00
|
|
|
);
|
|
|
|
|
2015-12-06 23:43:00 +00:00
|
|
|
CREATE UNIQUE INDEX supporter_postal_address_mapping_single_prefferred_per_supporter
|
2015-12-06 23:42:53 +00:00
|
|
|
ON supporter_postal_address_mapping(supporter_id, preferred);
|
2015-12-06 23:42:50 +00:00
|
|
|
|