source: trunk/npemap.org.uk/schema_postgres.sql @ 230

Last change on this file since 230 was 168, checked in by Dominic Hargreaves, 14 years ago

Add a deleted column

File size: 1.9 KB
RevLine 
[31]1-- NPE postcode collector schema
[4]2
[31]3
4-- Different Sources of the Postcode
5CREATE SEQUENCE s_sources;
6CREATE TABLE sources (
7        id integer NOT NULL DEFAULT NEXTVAL('s_sources'),
8        name character varying(30) NOT NULL,
9        CONSTRAINT pk_sources PRIMARY KEY (id)
10);
[36]11INSERT INTO sources VALUES (0, 'NPE Postcode web submission');
[31]12INSERT INTO sources VALUES (1, 'FreeThePostcode.org Importer');
13SELECT SETVAL('s_sources',1);
14
15
16-- ID sequence
17--  so we can have a unique way to reference a postcode submission
18CREATE SEQUENCE s_postcodes;
19
20-- Our submitted postcodes
[4]21CREATE TABLE postcodes (
[31]22        id integer NOT NULL DEFAULT NEXTVAL('s_postcodes'),
23    outward character varying(5) NOT NULL,
24    inward character varying(3),
[72]25    raw_postcode_outward character varying(30) NOT NULL,
26    raw_postcode_inward character varying(30),
[31]27    easting integer NOT NULL,
28    northing integer NOT NULL,
[4]29    ip inet,
[31]30    created_at timestamp without time zone NOT NULL default NOW(),
31    source integer NOT NULL,
[168]32    deleted boolean NOT NULL default 'f',
[31]33
34        CONSTRAINT pk_postcode PRIMARY KEY (id),
35        CONSTRAINT fk_postcode_source FOREIGN KEY (source) REFERENCES sources (id)
[4]36);
37
[62]38-- Bad postcode reports
39CREATE TABLE bad_postcodes (
40    postcode integer NOT NULL,
41    ip inet,
42    reason character varying,
43    reporter_email character varying,
44    created_at timestamp without time zone NOT NULL default NOW(),
45
46    CONSTRAINT fk_postcode_id FOREIGN KEY (postcode) REFERENCES postcodes (id)
47);
48
[75]49-- Interest in future plans
50CREATE TABLE interest (
51    email character varying,
[76]52    scotland boolean default false,
[77]53    northernireland boolean default false,
[78]54    ip inet,
55    created_at timestamp without time zone NOT NULL default NOW()
[76]56);
[75]57
[31]58CREATE INDEX postcode_easting ON postcodes (easting);
59CREATE INDEX postcode_northing ON postcodes (northing);
60CREATE INDEX postcode_outward ON postcodes (outward);
61CREATE INDEX postcode_postcode ON postcodes (outward,inward);
Note: See TracBrowser for help on using the repository browser.