Motion database: Difference between revisions
From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs) mNo edit summary |
Brian Wilson (talk | contribs) |
||
Line 7: | Line 7: | ||
== Table creation SQL == | == Table creation SQL == | ||
createdb -U webadmin motion - | createdb -U webadmin motion | ||
psql -U webadmin motion | |||
DROP TABLE IF EXISTS vehicle; | CREATE EXTENSION postgis; | ||
CREATE TABLE vehicle ( | |||
# Add support for Large Objects | |||
CREATE EXTENSION lo; | |||
# Show installed extensions | |||
SELECT * FROM pg_available_extensions | |||
WHERE comment LIKE '%string%' OR installed_version IS NOT NULL ORDER BY name; | |||
# Get more info on an extension | |||
\dx+ postgis | |||
\dx+ lo | |||
# Create the tables! | |||
DROP TABLE IF EXISTS vehicle; | |||
CREATE TABLE vehicle ( | |||
tag CHAR DEFAULT 'V', | tag CHAR DEFAULT 'V', | ||
vehicle_id SERIAL NOT NULL, | vehicle_id SERIAL NOT NULL, | ||
Line 17: | Line 33: | ||
serial_number VARCHAR(40), | serial_number VARCHAR(40), | ||
PRIMARY KEY(tag,vehicle_id) | PRIMARY KEY(tag,vehicle_id) | ||
); | ); | ||
DROP TABLE IF EXISTS photos; | DROP TABLE IF EXISTS photos; | ||
CREATE TABLE photos ( | CREATE TABLE photos ( | ||
photo_id SERIAL NOT NULL, | photo_id SERIAL NOT NULL, | ||
thumbnail BYTEA, | thumbnail BYTEA, | ||
Line 26: | Line 42: | ||
description TEXT, | description TEXT, | ||
location POINT, | location POINT, | ||
FOREIGN KEY( | FOREIGN KEY(photo_fkey) REFERENCES vehicle(vehicle_pkey), | ||
PRIMARY KEY(photo_id) | PRIMARY KEY(photo_id) | ||
); | ); | ||
CREATE TRIGGER t_raster BEFORE UPDATE OR DELETE ON photos | CREATE TRIGGER t_raster BEFORE UPDATE OR DELETE ON photos | ||
FOR EACH ROW EXECUTE PROCEDURE lo_manage(raster); | FOR EACH ROW EXECUTE PROCEDURE lo_manage(raster); | ||
DROP TABLE IF EXISTS trips; | DROP TABLE IF EXISTS trips; | ||
CREATE TABLE trips ( | CREATE TABLE trips ( | ||
tag CHAR DEFAULT 't', | tag CHAR DEFAULT 't', | ||
trip_id SERIAL NOT NULL, | trip_id SERIAL NOT NULL, | ||
Line 42: | Line 58: | ||
notes TEXT, | notes TEXT, | ||
PRIMARY KEY(tag,trip_id) | PRIMARY KEY(tag,trip_id) | ||
); | ); | ||
DROP TABLE IF EXISTS maintenance; | DROP TABLE IF EXISTS maintenance; | ||
CREATE TABLE maintenance ( | CREATE TABLE maintenance ( | ||
tag CHAR DEFAULT 'M', | tag CHAR DEFAULT 'M', | ||
maint_id SERIAL NOT NULL, | maint_id SERIAL NOT NULL, | ||
Line 53: | Line 69: | ||
vehicle_id , | vehicle_id , | ||
PRIMARY KEY(tag,main_id) | PRIMARY KEY(tag,main_id) | ||
); | ); | ||
DROP TABLE IF EXISTS gpx; | DROP TABLE IF EXISTS gpx; | ||
CREATE TABLE gpx ( | CREATE TABLE gpx ( | ||
gpx_id SERIAL NOT NULL, | gpx_id SERIAL NOT NULL, | ||
upload_date DATESTAMP, | upload_date DATESTAMP, | ||
Line 62: | Line 78: | ||
note TEXT, | note TEXT, | ||
PRIMARY KEY(gpx_id) | PRIMARY KEY(gpx_id) | ||
); | ); | ||
[[Category: SQL]] | [[Category: SQL]] |
Revision as of 00:13, 18 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.
I could do photo/image processing in the database if I installed PostPIC. http://drotiro.github.com/postpic/
Table creation SQL
createdb -U webadmin motion psql -U webadmin motion
CREATE EXTENSION postgis; # Add support for Large Objects CREATE EXTENSION lo;
# Show installed extensions SELECT * FROM pg_available_extensions WHERE comment LIKE '%string%' OR installed_version IS NOT NULL ORDER BY name;
# Get more info on an extension \dx+ postgis \dx+ lo
# Create the tables! 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, thumbnail BYTEA, raster LO, description TEXT, location POINT, FOREIGN KEY(photo_fkey) REFERENCES vehicle(vehicle_pkey), PRIMARY KEY(photo_id) ); CREATE TRIGGER t_raster BEFORE UPDATE OR DELETE ON photos FOR EACH ROW EXECUTE PROCEDURE lo_manage(raster); 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) );