Closed brianfoshee closed 9 years ago
I decided to generate this id on the monitoring device and send it up in the "POST" with the rest of the readings.
I have added support for this in main.go and my local database using the following alter command: alter table readings add column device_id character (56) not null; (Note: I deleted all of the old data from my local postgres database to support the 'not null' option as opposed to back filling the old data.)
The frontend is currently statically coded to pull from the only monitoring device: http://gowebz.herokuapp.com/devices/fe5d2287d64e448971febd91a4229b616e3a4bf6641916ade12a931a/readings
If you want to add a native UUID type to the database you can run CREATE EXTENSION uuid-ossp;
on the database, then set the column type to uuid
. Then version 4 UUIDs can be generated on the client in whichever language.
Table "public.readings"
Column | Type | Modifiers
-------------+--------------------------+-----------
ph | numeric(18,2) |
tds | numeric(18,2) |
temperature | numeric(18,2) |
created_at | timestamp with time zone |
device_id | character(56) | not null
Maybe also a table to keep track of device IDs and a foreign key to the device table from the readings table. It can simply contain the mac address or UUID assigned to a device for now. Later it'd need a foreign key to a user's table to determine which user the device belongs to.
Postgres has both MAC address types and UUID types: http://www.postgresql.org/docs/9.3/static/datatype-net-types.html http://www.postgresql.org/docs/9.3/static/datatype-uuid.html
UUIDs can be auto generated in a column if necessary: