strds_metadata_table.sql 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. --#############################################################################
  2. -- This SQL script generates the space time raster dataset metadata table,
  3. -- view and trigger
  4. --
  5. -- Author: Soeren Gebbert soerengebbert <at> googlemail <dot> com
  6. --#############################################################################
  7. PRAGMA foreign_keys = ON;
  8. CREATE TABLE strds_metadata (
  9. id VARCHAR NOT NULL, -- Id of the space-time dataset, this is the primary foreign key
  10. raster_register VARCHAR, -- The id of the table in which the raster maps are registered for this dataset
  11. number_of_maps INTEGER, -- The number of registered raster maps
  12. max_min DOUBLE PRECISION, -- The minimal maximum of the registered raster maps
  13. min_min DOUBLE PRECISION, -- The minimal minimum of the registered raster maps
  14. max_max DOUBLE PRECISION, -- The maximal maximum of the registered raster maps
  15. min_max DOUBLE PRECISION, -- The maximal minimum of the registered raster maps
  16. nsres_min DOUBLE PRECISION, -- The lowest north-south resolution of the registered raster maps
  17. nsres_max DOUBLE PRECISION, -- The highest north-south resolution of the registered raster maps
  18. ewres_min DOUBLE PRECISION, -- The lowest east-west resolution of the registered raster maps
  19. ewres_max DOUBLE PRECISION, -- The highest east-west resolution of the registered raster maps
  20. title VARCHAR, -- Title of the space-time raster dataset
  21. description VARCHAR, -- Detailed description of the space-time raster dataset
  22. PRIMARY KEY (id),
  23. FOREIGN KEY (id) REFERENCES strds_base (id) ON DELETE CASCADE
  24. );
  25. -- Create the views to access all cols for absolute or relative time
  26. CREATE VIEW strds_view_abs_time AS SELECT
  27. A1.id, A1.temporal_type,
  28. A1.creator, A1.semantic_type,
  29. A1.creation_time, A1.modification_time,
  30. A1.revision, A2.start_time,
  31. A2.end_time, A2.granularity,
  32. A3.north, A3.south, A3.east, A3.west,
  33. A4.raster_register,
  34. A4.number_of_maps,
  35. A4.nsres_min, A4.ewres_min,
  36. A4.nsres_max, A4.ewres_max,
  37. A4.min_min, A4.min_max,
  38. A4.max_min, A4.max_max,
  39. A4.title, A4.description
  40. FROM strds_base A1, strds_absolute_time A2,
  41. strds_spatial_extent A3, strds_metadata A4 WHERE A1.id = A2.id AND
  42. A1.id = A3.id AND A1.id = A4.id;
  43. CREATE VIEW strds_view_rel_time AS SELECT
  44. A1.id, A1.temporal_type,
  45. A1.creator, A1.semantic_type,
  46. A1.creation_time, A1.modification_time,
  47. A1.revision,
  48. A2.interval, A2.granularity,
  49. A3.north, A3.south, A3.east, A3.west,
  50. A4.raster_register,
  51. A4.number_of_maps,
  52. A4.nsres_min, A4.ewres_min,
  53. A4.nsres_max, A4.ewres_max,
  54. A4.min_min, A4.min_max,
  55. A4.max_min, A4.max_max,
  56. A4.title, A4.description
  57. FROM strds_base A1, strds_relative_time A2,
  58. strds_spatial_extent A3, strds_metadata A4 WHERE A1.id = A2.id AND
  59. A1.id = A3.id AND A1.id = A4.id;
  60. -- Create a trigger to update the modification time and revision number in case the metadata or timestanps have been updated
  61. CREATE TRIGGER update_strds_metadata AFTER UPDATE ON strds_metadata
  62. BEGIN
  63. UPDATE strds_base SET modification_time = datetime("NOW") WHERE id = old.id;
  64. UPDATE strds_base SET revision = (revision + 1) WHERE id = old.id;
  65. END;
  66. -- Create trigger for automated deletion of dependent rows, this should normally be done using foreign keys
  67. CREATE TRIGGER delete_strds_base AFTER DELETE ON strds_base
  68. BEGIN
  69. DELETE FROM strds_absolute_time WHERE id = old.id;
  70. DELETE FROM strds_relative_time WHERE id = old.id;
  71. DELETE FROM strds_spatial_extent WHERE id = old.id;
  72. DELETE FROM strds_metadata WHERE id = old.id;
  73. END;