spacedrive/core/prisma/schema.prisma

438 lines
13 KiB
Plaintext
Raw Normal View History

datasource db {
2023-01-05 16:05:33 +00:00
provider = "sqlite"
url = "file:dev.db"
}
generator client {
2023-01-05 16:05:33 +00:00
provider = "cargo prisma"
output = "../src/prisma.rs"
}
2023-01-05 07:11:55 +00:00
generator sync {
2023-01-05 16:05:33 +00:00
provider = "cargo prisma-sync"
output = "../src/prisma_sync.rs"
2023-01-05 07:11:55 +00:00
}
model OwnedOperation {
2023-01-05 16:05:33 +00:00
id Bytes @id
timestamp BigInt
data Bytes
model String
2023-01-05 07:11:55 +00:00
2023-01-05 16:05:33 +00:00
node_id Int
node Node @relation(fields: [node_id], references: [id])
2023-01-05 07:11:55 +00:00
2023-01-05 16:05:33 +00:00
@@map("owned_operation")
2023-01-05 07:11:55 +00:00
}
model SharedOperation {
2023-01-05 16:05:33 +00:00
id Bytes @id
timestamp BigInt
model String
2023-01-05 07:11:55 +00:00
2023-01-05 16:05:33 +00:00
record_id Bytes
kind String
data Bytes
2023-01-05 07:11:55 +00:00
2023-01-05 16:05:33 +00:00
node_id Int
node Node @relation(fields: [node_id], references: [id])
2023-01-05 07:11:55 +00:00
2023-01-05 16:05:33 +00:00
@@map("shared_operation")
2023-01-05 07:11:55 +00:00
}
2022-07-11 02:05:24 +00:00
model Statistics {
2023-01-05 16:05:33 +00:00
id Int @id @default(autoincrement())
date_captured DateTime @default(now())
total_object_count Int @default(0)
library_db_size String @default("0")
total_bytes_used String @default("0")
total_bytes_capacity String @default("0")
total_unique_bytes String @default("0")
total_bytes_free String @default("0")
preview_media_bytes String @default("0")
@@map("statistics")
}
/// @local(id: pub_id)
2022-05-10 16:03:20 +00:00
model Node {
2023-01-05 16:05:33 +00:00
id Int @id @default(autoincrement())
pub_id Bytes @unique
name String
platform Int @default(0)
version String?
last_seen DateTime @default(now())
timezone String?
date_created DateTime @default(now())
jobs Job[]
Location Location[]
2023-01-05 16:05:33 +00:00
OwnedOperation OwnedOperation[]
SharedOperation SharedOperation[]
@@map("node")
}
model Volume {
2023-01-05 16:05:33 +00:00
id Int @id @default(autoincrement())
node_id Int
name String
mount_point String
total_bytes_capacity String @default("0")
total_bytes_available String @default("0")
disk_type String?
filesystem String?
is_system Boolean @default(false)
date_modified DateTime @default(now())
@@unique([node_id, mount_point, name])
@@map("volume")
}
/// @owned(id: pub_id)
model Location {
[ENG 239] Onboarding Flow & Location Settings (#529) * begin better onboarding * added input and altered text * better router & text + database icon Co-authored-by: maxichrome <maxichrome@users.noreply.github.com> * work on privacy screen + radio buttons * fix video extension bug and alter screens * add pending schema and location manager helper * functional onboarding * added secure temp store and started creating library loading screen * fix secure temp keystore + api * better onboarding * added location settings and some overview concept, all WIP * fix switch * prep * fix location router * added backend settings * attempted to fix form * begin indexer rules editor, plus tweaks * indexer rules coming soon * fix onboarding img size * cleanup * clone is needed here, but clippy no like * sike * whole bunch of fixes * clippy + ts * Removing some TODOs from api/libraries.rs and fixing db size calculation * moved object kind to client, added half functionality for appearance settings * fix RadioGroup helper * fix type issues * cargo fmt * fix creating library error handling + invalidate location list on update * forgot to switch back to onError * Invalidating getStatistics query on library creation and introducing the concept of waiting for a job on FileCopierJob * F* cargo fmt * fix RadioGroup interactivity * wipe all migrations * put back COLLATE NOCASE on extension columns * update core.ts * remove unused device component * fix typeerror in mobile --------- Co-authored-by: maxichrome <maxichrome@users.noreply.github.com> Co-authored-by: Brendan Allan <brendonovich@outlook.com> Co-authored-by: Ericson Soares <ericson.ds999@gmail.com> Co-authored-by: Utku Bakir <74243531+utkubakir@users.noreply.github.com>
2023-02-10 22:08:13 +00:00
id Int @id @default(autoincrement())
pub_id Bytes @unique
node_id Int
name String
path String
[ENG 239] Onboarding Flow & Location Settings (#529) * begin better onboarding * added input and altered text * better router & text + database icon Co-authored-by: maxichrome <maxichrome@users.noreply.github.com> * work on privacy screen + radio buttons * fix video extension bug and alter screens * add pending schema and location manager helper * functional onboarding * added secure temp store and started creating library loading screen * fix secure temp keystore + api * better onboarding * added location settings and some overview concept, all WIP * fix switch * prep * fix location router * added backend settings * attempted to fix form * begin indexer rules editor, plus tweaks * indexer rules coming soon * fix onboarding img size * cleanup * clone is needed here, but clippy no like * sike * whole bunch of fixes * clippy + ts * Removing some TODOs from api/libraries.rs and fixing db size calculation * moved object kind to client, added half functionality for appearance settings * fix RadioGroup helper * fix type issues * cargo fmt * fix creating library error handling + invalidate location list on update * forgot to switch back to onError * Invalidating getStatistics query on library creation and introducing the concept of waiting for a job on FileCopierJob * F* cargo fmt * fix RadioGroup interactivity * wipe all migrations * put back COLLATE NOCASE on extension columns * update core.ts * remove unused device component * fix typeerror in mobile --------- Co-authored-by: maxichrome <maxichrome@users.noreply.github.com> Co-authored-by: Brendan Allan <brendonovich@outlook.com> Co-authored-by: Ericson Soares <ericson.ds999@gmail.com> Co-authored-by: Utku Bakir <74243531+utkubakir@users.noreply.github.com>
2023-02-10 22:08:13 +00:00
total_capacity Int?
available_capacity Int?
is_archived Boolean @default(false)
generate_preview_media Boolean @default(true)
sync_preview_media Boolean @default(true)
hidden Boolean @default(false)
date_created DateTime @default(now())
2023-01-05 16:05:33 +00:00
node Node @relation(fields: [node_id], references: [id])
file_paths FilePath[]
indexer_rules IndexerRulesInLocation[]
@@map("location")
}
2023-01-28 03:42:24 +00:00
/// @shared(id: pub_id)
model Object {
2023-01-28 03:42:24 +00:00
id Int @id @default(autoincrement())
pub_id Bytes @unique
2023-01-05 16:05:33 +00:00
// basic metadata
2023-01-28 03:42:24 +00:00
name String?
[ENG 239] Onboarding Flow & Location Settings (#529) * begin better onboarding * added input and altered text * better router & text + database icon Co-authored-by: maxichrome <maxichrome@users.noreply.github.com> * work on privacy screen + radio buttons * fix video extension bug and alter screens * add pending schema and location manager helper * functional onboarding * added secure temp store and started creating library loading screen * fix secure temp keystore + api * better onboarding * added location settings and some overview concept, all WIP * fix switch * prep * fix location router * added backend settings * attempted to fix form * begin indexer rules editor, plus tweaks * indexer rules coming soon * fix onboarding img size * cleanup * clone is needed here, but clippy no like * sike * whole bunch of fixes * clippy + ts * Removing some TODOs from api/libraries.rs and fixing db size calculation * moved object kind to client, added half functionality for appearance settings * fix RadioGroup helper * fix type issues * cargo fmt * fix creating library error handling + invalidate location list on update * forgot to switch back to onError * Invalidating getStatistics query on library creation and introducing the concept of waiting for a job on FileCopierJob * F* cargo fmt * fix RadioGroup interactivity * wipe all migrations * put back COLLATE NOCASE on extension columns * update core.ts * remove unused device component * fix typeerror in mobile --------- Co-authored-by: maxichrome <maxichrome@users.noreply.github.com> Co-authored-by: Brendan Allan <brendonovich@outlook.com> Co-authored-by: Ericson Soares <ericson.ds999@gmail.com> Co-authored-by: Utku Bakir <74243531+utkubakir@users.noreply.github.com>
2023-02-10 22:08:13 +00:00
// Must have 'COLLATE NOCASE' in migration
2023-01-28 03:42:24 +00:00
extension String?
kind Int @default(0)
size_in_bytes String @default("0")
key_id Int?
2023-01-05 16:05:33 +00:00
// handy ways to mark an object
2023-01-28 03:42:24 +00:00
hidden Boolean @default(false)
favorite Boolean @default(false)
important Boolean @default(false)
2023-01-05 16:05:33 +00:00
// if we have generated preview media for this object
2023-01-28 03:42:24 +00:00
has_thumbnail Boolean @default(false)
has_thumbstrip Boolean @default(false)
has_video_preview Boolean @default(false)
2023-01-05 16:05:33 +00:00
// integration with ipfs
2023-01-28 03:42:24 +00:00
ipfs_id String?
2023-01-05 16:05:33 +00:00
// plain text note
2023-01-28 03:42:24 +00:00
note String?
2023-01-05 16:05:33 +00:00
// the original known creation date of this object
2023-01-28 03:42:24 +00:00
date_created DateTime @default(now())
2023-01-05 16:05:33 +00:00
// the last time this object was modified
2023-01-28 03:42:24 +00:00
date_modified DateTime @default(now())
2023-01-05 16:05:33 +00:00
// when this object was first indexed
2023-01-28 03:42:24 +00:00
date_indexed DateTime @default(now())
2023-01-05 16:05:33 +00:00
tags TagOnObject[]
labels LabelOnObject[]
albums ObjectInAlbum[]
spaces ObjectInSpace[]
file_paths FilePath[]
comments Comment[]
media_data MediaData?
key Key? @relation(fields: [key_id], references: [id])
@@map("object")
}
/// @shared(id: [location, id])
model FilePath {
2023-01-28 03:42:24 +00:00
id Int
is_dir Boolean @default(false)
// content addressable storage id - blake3 sampled checksum
cas_id String?
// full byte contents digested into blake3 checksum
integrity_checksum String? @unique
2023-01-05 16:05:33 +00:00
// location that owns this path
2023-01-28 03:42:24 +00:00
location_id Int
location Location @relation(fields: [location_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
2023-01-05 16:05:33 +00:00
// a path generated from local file_path ids eg: "34/45/67/890"
materialized_path String
// the name and extension
[ENG 239] Onboarding Flow & Location Settings (#529) * begin better onboarding * added input and altered text * better router & text + database icon Co-authored-by: maxichrome <maxichrome@users.noreply.github.com> * work on privacy screen + radio buttons * fix video extension bug and alter screens * add pending schema and location manager helper * functional onboarding * added secure temp store and started creating library loading screen * fix secure temp keystore + api * better onboarding * added location settings and some overview concept, all WIP * fix switch * prep * fix location router * added backend settings * attempted to fix form * begin indexer rules editor, plus tweaks * indexer rules coming soon * fix onboarding img size * cleanup * clone is needed here, but clippy no like * sike * whole bunch of fixes * clippy + ts * Removing some TODOs from api/libraries.rs and fixing db size calculation * moved object kind to client, added half functionality for appearance settings * fix RadioGroup helper * fix type issues * cargo fmt * fix creating library error handling + invalidate location list on update * forgot to switch back to onError * Invalidating getStatistics query on library creation and introducing the concept of waiting for a job on FileCopierJob * F* cargo fmt * fix RadioGroup interactivity * wipe all migrations * put back COLLATE NOCASE on extension columns * update core.ts * remove unused device component * fix typeerror in mobile --------- Co-authored-by: maxichrome <maxichrome@users.noreply.github.com> Co-authored-by: Brendan Allan <brendonovich@outlook.com> Co-authored-by: Ericson Soares <ericson.ds999@gmail.com> Co-authored-by: Utku Bakir <74243531+utkubakir@users.noreply.github.com>
2023-02-10 22:08:13 +00:00
// Must have 'COLLATE NOCASE' in migration
2023-01-05 16:05:33 +00:00
name String
extension String?
2023-01-28 03:42:24 +00:00
2023-01-05 16:05:33 +00:00
// the unique Object for this file path
2023-01-28 03:42:24 +00:00
object_id Int?
object Object? @relation(fields: [object_id], references: [id], onDelete: Restrict)
2023-01-05 16:05:33 +00:00
// the parent in the file tree
2023-01-28 03:42:24 +00:00
parent_id Int?
key_id Int? // replacement for encryption
2023-01-05 16:05:33 +00:00
// permissions String?
date_created DateTime @default(now())
date_modified DateTime @default(now())
date_indexed DateTime @default(now())
// NOTE: this self relation for the file tree was causing SQLite to go to forever bed, disabling until workaround
// parent FilePath? @relation("directory_file_paths", fields: [parent_id], references: [id], onDelete: NoAction, onUpdate: NoAction)
// children FilePath[] @relation("directory_file_paths")
key Key? @relation(fields: [key_id], references: [id])
@@id([location_id, id])
@@unique([location_id, materialized_path, name, extension])
@@index([location_id])
@@map("file_path")
}
2022-05-27 21:54:56 +00:00
// if there is a conflicting cas_id, the conficting file should be updated to have a larger cas_id as the field is unique, however this record is kept to tell the indexer (upon discovering this CAS) that there is alternate versions of the file and to check by a full integrity hash to define for which to associate with.
model FileConflict {
2023-01-05 16:05:33 +00:00
original_object_id Int @unique
detactched_object_id Int @unique
2023-01-05 16:05:33 +00:00
@@map("file_conflict")
}
2022-05-10 16:03:20 +00:00
// keys allow us to know exactly which files can be decrypted with a given key
// they can be "mounted" to a client, and then used to decrypt files automatically
/// @shared(id: uuid)
2022-05-10 16:03:20 +00:00
model Key {
2023-01-05 16:05:33 +00:00
id Int @id @default(autoincrement())
// uuid to identify the key
uuid String @unique
version String
key_type String
2023-01-05 16:05:33 +00:00
// the name that the user sets
name String?
// is this key the default for encryption?
// was not tagged as unique as i'm not too sure if PCR will handle it
// can always be tagged as unique, the keys API will need updating to use `find_unique()`
default Boolean @default(false)
// nullable if concealed for security
date_created DateTime? @default(now())
// encryption algorithm used to encrypt the key
algorithm String
2023-01-05 16:05:33 +00:00
// hashing algorithm used for hashing the key with the content salt
hashing_algorithm String
2023-01-05 16:05:33 +00:00
// salt used for encrypting data with this key
content_salt Bytes
// the *encrypted* master key (48 bytes)
master_key Bytes
// the nonce used for encrypting the master key
master_key_nonce Bytes
// the nonce used for encrypting the key
key_nonce Bytes
// the *encrypted* key
key Bytes
// the salt used for deriving the KEK (used for encrypting the master key) from the root key
salt Bytes
automount Boolean @default(false)
objects Object[]
file_paths FilePath[]
@@map("key")
2022-05-10 16:03:20 +00:00
}
model MediaData {
2023-01-05 16:05:33 +00:00
id Int @id
pixel_width Int?
pixel_height Int?
longitude Float?
latitude Float?
fps Int?
capture_device_make String? // eg: "Apple"
capture_device_model String? // eg: "iPhone 12"
capture_device_software String? // eg: "12.1.1"
duration_seconds Int?
codecs String? // eg: "h264,acc"
streams Int?
object Object? @relation(fields: [id], references: [id], onDelete: Cascade, onUpdate: Cascade)
@@map("media_data")
}
/// @shared(id: pub_id)
model Tag {
2023-01-05 16:05:33 +00:00
id Int @id @default(autoincrement())
pub_id Bytes @unique
name String?
color String?
total_objects Int? @default(0)
redundancy_goal Int? @default(1)
date_created DateTime @default(now())
date_modified DateTime @default(now())
tag_objects TagOnObject[]
@@map("tag")
}
model TagOnObject {
2023-01-05 16:05:33 +00:00
date_created DateTime @default(now())
2023-01-05 16:05:33 +00:00
tag_id Int
tag Tag @relation(fields: [tag_id], references: [id], onDelete: NoAction, onUpdate: NoAction)
2023-01-05 16:05:33 +00:00
object_id Int
object Object @relation(fields: [object_id], references: [id], onDelete: NoAction, onUpdate: NoAction)
2023-01-05 16:05:33 +00:00
@@id([tag_id, object_id])
@@map("tag_on_object")
}
model Label {
2023-01-05 16:05:33 +00:00
id Int @id @default(autoincrement())
pub_id Bytes @unique
name String?
date_created DateTime @default(now())
date_modified DateTime @default(now())
2023-01-05 16:05:33 +00:00
label_objects LabelOnObject[]
2022-09-04 20:00:24 +00:00
2023-01-05 16:05:33 +00:00
@@map("label")
}
model LabelOnObject {
2023-01-05 16:05:33 +00:00
date_created DateTime @default(now())
2023-01-05 16:05:33 +00:00
label_id Int
label Label @relation(fields: [label_id], references: [id], onDelete: NoAction, onUpdate: NoAction)
2023-01-05 16:05:33 +00:00
object_id Int
object Object @relation(fields: [object_id], references: [id], onDelete: NoAction, onUpdate: NoAction)
2023-01-05 16:05:33 +00:00
@@id([label_id, object_id])
@@map("label_on_object")
}
model Space {
2023-01-05 16:05:33 +00:00
id Int @id @default(autoincrement())
pub_id Bytes @unique
name String?
description String?
date_created DateTime @default(now())
date_modified DateTime @default(now())
2023-01-05 16:05:33 +00:00
objects ObjectInSpace[]
2022-09-04 20:00:24 +00:00
2023-01-05 16:05:33 +00:00
@@map("space")
}
model ObjectInSpace {
2023-01-05 16:05:33 +00:00
date_created DateTime @default(now())
2023-01-05 16:05:33 +00:00
space_id Int
space Space @relation(fields: [space_id], references: [id], onDelete: NoAction, onUpdate: NoAction)
2023-01-05 16:05:33 +00:00
object_id Int
object Object @relation(fields: [object_id], references: [id], onDelete: NoAction, onUpdate: NoAction)
2023-01-05 16:05:33 +00:00
@@id([space_id, object_id])
@@map("object_in_space")
}
model Job {
2023-01-05 16:05:33 +00:00
id Bytes @id
name String
node_id Int
action Int
status Int @default(0)
data Bytes?
metadata Bytes?
task_count Int @default(1)
completed_task_count Int @default(0)
date_created DateTime @default(now())
date_modified DateTime @default(now())
seconds_elapsed Int @default(0)
nodes Node @relation(fields: [node_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
@@map("job")
}
/// @shared(id: pub_id)
model Album {
2023-01-05 16:05:33 +00:00
id Int @id @default(autoincrement())
pub_id Bytes @unique
name String
is_hidden Boolean @default(false)
2023-01-05 16:05:33 +00:00
date_created DateTime @default(now())
date_modified DateTime @default(now())
2023-01-05 16:05:33 +00:00
objects ObjectInAlbum[]
2022-04-12 22:31:17 +00:00
2023-01-05 16:05:33 +00:00
@@map("album")
}
model ObjectInAlbum {
2023-01-05 16:05:33 +00:00
date_created DateTime @default(now())
2022-04-12 22:31:17 +00:00
2023-01-05 16:05:33 +00:00
album_id Int
album Album @relation(fields: [album_id], references: [id], onDelete: NoAction, onUpdate: NoAction)
2022-04-12 22:31:17 +00:00
2023-01-05 16:05:33 +00:00
object_id Int
object Object @relation(fields: [object_id], references: [id], onDelete: NoAction, onUpdate: NoAction)
2022-04-12 22:31:17 +00:00
2023-01-05 16:05:33 +00:00
@@id([album_id, object_id])
@@map("object_in_album")
2022-04-12 22:31:17 +00:00
}
model Comment {
2023-01-05 16:05:33 +00:00
id Int @id @default(autoincrement())
pub_id Bytes @unique
content String
date_created DateTime @default(now())
date_modified DateTime @default(now())
object_id Int?
object Object? @relation(fields: [object_id], references: [id])
@@map("comment")
}
model IndexerRule {
2023-01-05 16:05:33 +00:00
id Int @id @default(autoincrement())
kind Int
name String
parameters Bytes
date_created DateTime @default(now())
date_modified DateTime @default(now())
2023-01-05 16:05:33 +00:00
locations IndexerRulesInLocation[]
2023-01-05 16:05:33 +00:00
@@map("indexer_rule")
}
model IndexerRulesInLocation {
2023-01-05 16:05:33 +00:00
date_created DateTime @default(now())
2023-01-05 16:05:33 +00:00
location_id Int
location Location @relation(fields: [location_id], references: [id], onDelete: NoAction, onUpdate: NoAction)
2023-01-05 16:05:33 +00:00
indexer_rule_id Int
indexer_rule IndexerRule @relation(fields: [indexer_rule_id], references: [id], onDelete: NoAction, onUpdate: NoAction)
2023-01-05 16:05:33 +00:00
@@id([location_id, indexer_rule_id])
@@map("indexer_rule_in_location")
2022-09-04 20:00:24 +00:00
}