db_fields.dart 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // Faces Table Fields & Schema Queries
  2. import 'package:photos/services/machine_learning/face_ml/face_filtering/face_filtering_constants.dart';
  3. const facesTable = 'faces';
  4. const fileIDColumn = 'file_id';
  5. const faceIDColumn = 'face_id';
  6. const faceDetectionColumn = 'detection';
  7. const faceEmbeddingBlob = 'eBlob';
  8. const faceScore = 'score';
  9. const faceBlur = 'blur';
  10. const faceClusterId = 'cluster_id';
  11. const mlVersionColumn = 'ml_version';
  12. const createFacesTable = '''CREATE TABLE IF NOT EXISTS $facesTable (
  13. $fileIDColumn INTEGER NOT NULL,
  14. $faceIDColumn TEXT NOT NULL,
  15. $faceDetectionColumn TEXT NOT NULL,
  16. $faceEmbeddingBlob BLOB NOT NULL,
  17. $faceScore REAL NOT NULL,
  18. $faceBlur REAL NOT NULL DEFAULT $kLapacianDefault,
  19. $faceClusterId INTEGER,
  20. $mlVersionColumn INTEGER NOT NULL DEFAULT -1,
  21. PRIMARY KEY($fileIDColumn, $faceIDColumn)
  22. );
  23. ''';
  24. const deleteFacesTable = 'DROP TABLE IF EXISTS $facesTable';
  25. // End of Faces Table Fields & Schema Queries
  26. //##region Face Clusters Table Fields & Schema Queries
  27. const faceClustersTable = 'face_clusters';
  28. const fcClusterID = 'cluster_id';
  29. const fcFaceId = 'face_id';
  30. // fcClusterId & fcFaceId are the primary keys and fcClusterId is a foreign key to faces table
  31. const createFaceClustersTable = '''
  32. CREATE TABLE IF NOT EXISTS $faceClustersTable (
  33. $fcFaceId TEXT NOT NULL,
  34. $fcClusterID INTEGER NOT NULL,
  35. PRIMARY KEY($fcFaceId),
  36. FOREIGN KEY($fcFaceId) REFERENCES $facesTable($faceIDColumn)
  37. );
  38. ''';
  39. // -- Creating a non-unique index on clusterID for query optimization
  40. const fcClusterIDIndex =
  41. '''CREATE INDEX IF NOT EXISTS idx_fcClusterID ON faceClustersTable(fcClusterID);''';
  42. const dropFaceClustersTable = 'DROP TABLE IF EXISTS $faceClustersTable';
  43. //##endregion
  44. // People Table Fields & Schema Queries
  45. const personTable = 'person';
  46. const idColumn = 'id';
  47. const nameColumn = 'name';
  48. const personHiddenColumn = 'hidden';
  49. const clusterToFaceIdJson = 'clusterToFaceIds';
  50. const coverFaceIDColumn = 'cover_face_id';
  51. const createPersonTable = '''CREATE TABLE IF NOT EXISTS $personTable (
  52. $idColumn TEXT NOT NULL UNIQUE,
  53. $nameColumn TEXT NOT NULL DEFAULT '',
  54. $personHiddenColumn INTEGER NOT NULL DEFAULT 0,
  55. $clusterToFaceIdJson TEXT NOT NULL DEFAULT '{}',
  56. $coverFaceIDColumn TEXT,
  57. PRIMARY KEY($idColumn)
  58. );
  59. ''';
  60. const deletePersonTable = 'DROP TABLE IF EXISTS $personTable';
  61. //End People Table Fields & Schema Queries
  62. // Clusters Table Fields & Schema Queries
  63. const clusterPersonTable = 'cluster_person';
  64. const personIdColumn = 'person_id';
  65. const cluserIDColumn = 'cluster_id';
  66. const createClusterPersonTable = '''
  67. CREATE TABLE IF NOT EXISTS $clusterPersonTable (
  68. $personIdColumn TEXT NOT NULL,
  69. $cluserIDColumn INTEGER NOT NULL,
  70. PRIMARY KEY($personIdColumn, $cluserIDColumn)
  71. );
  72. ''';
  73. const dropClusterPersonTable = 'DROP TABLE IF EXISTS $clusterPersonTable';
  74. // End Clusters Table Fields & Schema Queries
  75. /// Cluster Summary Table Fields & Schema Queries
  76. const clusterSummaryTable = 'cluster_summary';
  77. const avgColumn = 'avg';
  78. const countColumn = 'count';
  79. const createClusterSummaryTable = '''
  80. CREATE TABLE IF NOT EXISTS $clusterSummaryTable (
  81. $cluserIDColumn INTEGER NOT NULL,
  82. $avgColumn BLOB NOT NULL,
  83. $countColumn INTEGER NOT NULL,
  84. PRIMARY KEY($cluserIDColumn)
  85. );
  86. ''';
  87. const dropClusterSummaryTable = 'DROP TABLE IF EXISTS $clusterSummaryTable';
  88. /// End Cluster Summary Table Fields & Schema Queries
  89. /// notPersonFeedback Table Fields & Schema Queries
  90. const notPersonFeedback = 'not_person_feedback';
  91. const createNotPersonFeedbackTable = '''
  92. CREATE TABLE IF NOT EXISTS $notPersonFeedback (
  93. $personIdColumn TEXT NOT NULL,
  94. $cluserIDColumn INTEGER NOT NULL
  95. );
  96. ''';
  97. const dropNotPersonFeedbackTable = 'DROP TABLE IF EXISTS $notPersonFeedback';
  98. // End Clusters Table Fields & Schema Queries