Motion database: Difference between revisions

From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs)
Brian Wilson (talk | contribs)
Line 4: Line 4:
== Table creation SQL ==
== Table creation SQL ==


createdb -t template1 motion
createdb -U webadmin motion -W -T template_postgis


DROP TABLE IF EXISTS vehicle;
DROP TABLE IF EXISTS vehicle;
CREATE TABLE vehicle (
CREATE TABLE vehicle (
   tag CHAR NOT NULL DEFAULT "V",
   tag CHAR DEFAULT 'V',
   vehicle_id SERIAL NOT NULL,  
   vehicle_id SERIAL NOT NULL,  
   name VARCHAR(20),
   name VARCHAR(20) NOT NULL,
   description TEXT,
   description TEXT,
   serial_number VARCHAR(40),
   serial_number VARCHAR(40),
Line 18: Line 18:
DROP TABLE IF EXISTS photos;
DROP TABLE IF EXISTS photos;
CREATE TABLE photos (
CREATE TABLE photos (
   photo_id PRIMARY KEY,
   photo_id SERIAL NOT NULL,
   photo
   photo BLOB NOT NULL,
   description
   description TEXT,
   location
   location POINT,
   fkey
   fkey FOREIGN KEY,
  PRIMARY KEY(photo_id)
);
);


DROP TABLE IF EXISTS trips;
DROP TABLE IF EXISTS trips;
CREATE TABLE trips (
CREATE TABLE trips (
   pk
   tag CHAR DEFAULT 't',
   trip_id
   trip_id SERIAL NOT NULL,
   date
   date DATESTAMP,
   mileage
   mileage NUMERIC,
   vehicle_id
   vehicle_id FOREIGN KEY,
   gpxlog_id
   gpx_id FOREIGN KEY,
   notes
   notes TEXT,
  PRIMARY KEY(tag,trip_id)
);
);


DROP TABLE IF EXISTS maintenance;
DROP TABLE IF EXISTS maintenance;
CREATE TABLE maintenance (
CREATE TABLE maintenance (
   pk CHAR DEFAULT "M",
   tag CHAR DEFAULT 'M',
   maint_id
   maint_id SERIAL NOT NULL,
   date
   date
   description
   description
   notes
   notes
   vehicle_id  
   vehicle_id ,
  PRIMARY KEY(tag,main_id)
);
);


DROP TABLE IF EXISTS gpxlog;
DROP TABLE IF EXISTS gpx;
CREATE TABLE gpxlog (
CREATE TABLE gpx (
   gpxlog_id PRIMARY KEY,
   gpx_id SERIAL NOT NULL,
   upload_date DATESTAMP,
   upload_date DATESTAMP,
   log TEXT,
   log TEXT,
   note TEXT
   note TEXT,
  PRIMARY KEY(gpx_id)
);
);


[[Category: SQL]]
[[Category: SQL]]

Revision as of 06:36, 17 March 2013

The Motion Database is used to keep track of my rolling stock including cars and bicycles. It's a demo database for developing concepts in PostgreSQL and Wavemaker.

Table creation SQL

createdb -U webadmin motion -W -T template_postgis

DROP TABLE IF EXISTS vehicle; CREATE TABLE vehicle (

 tag CHAR DEFAULT 'V',
 vehicle_id SERIAL NOT NULL, 
 name VARCHAR(20) NOT NULL,
 description TEXT,
 serial_number VARCHAR(40),
 PRIMARY KEY(tag,vehicle_id)

);

DROP TABLE IF EXISTS photos; CREATE TABLE photos (

 photo_id SERIAL NOT NULL,
 photo BLOB NOT NULL,
 description TEXT,
 location POINT,
 fkey FOREIGN KEY,
 PRIMARY KEY(photo_id)

);

DROP TABLE IF EXISTS trips; CREATE TABLE trips (

 tag CHAR DEFAULT 't',
 trip_id SERIAL NOT NULL,
 date DATESTAMP,
 mileage NUMERIC,
 vehicle_id FOREIGN KEY,
 gpx_id FOREIGN KEY,
 notes TEXT,
 PRIMARY KEY(tag,trip_id)

);

DROP TABLE IF EXISTS maintenance; CREATE TABLE maintenance (

 tag CHAR DEFAULT 'M',
 maint_id SERIAL NOT NULL,
 date
 description
 notes
 vehicle_id ,
 PRIMARY KEY(tag,main_id)

);

DROP TABLE IF EXISTS gpx; CREATE TABLE gpx (

 gpx_id SERIAL NOT NULL,
 upload_date DATESTAMP,
 log TEXT,
 note TEXT,
 PRIMARY KEY(gpx_id)

);