Skip to content
Snippets Groups Projects
objects.sql 1.82 KiB
Newer Older
Dean's avatar
Dean committed
-- "objects" table schema
CREATE TABLE objects (
  bucket_key character varying(1088) NOT NULL, -- ${bucket}/${key} (unique)
  bucket character varying(20) NOT NULL, -- Bucket ID ("public" for public bucket)
  key character varying(1024) NOT NULL, -- Full bucket path to file (including directory)
  dir character varying(1024) NOT NULL, -- Directory of file (with trailing slash)
  type integer DEFAULT 0 NOT NULL, -- Object type enumerable (0 = file, 1 = redirect)
  backend_file_id character varying(33) DEFAULT NULL, -- ID of file in backend storage
  dest_url character varying(4096) DEFAULT NULL, -- Destination URL for redirect object (only when object.type == 1)
  content_type character varying(255) DEFAULT 'application/octet-stream', -- Content-Type of file
  content_length integer, -- Content-Length of file
  created_at timestamp without time zone DEFAULT now() NOT NULL, -- File creation timestamp
  random_key character varying(1024) DEFAULT NULL, -- Random key if used
  associated_user character varying(36) DEFAULT NULL, -- ID of user who uploaded file
  deleted_at timestamp without time zone, -- Deletion timestamp
  delete_reason character varying(256) DEFAULT NULL::character varying, -- Deletion reason
  sha256_hash bytea, -- SHA256 hash of file contents (or destination URL)
  md5_hash bytea -- MD5 hash of file contents (or destination URL)
Dean's avatar
Dean committed
);

-- Test file object: /index.md
INSERT INTO objects (bucket_key, bucket, key, dir, type, content_type, content_length, md5_hash) VALUES (
Dean's avatar
Dean committed
  '/index.txt',
Dean's avatar
Dean committed
  0,
  'text/plain',
Dean's avatar
Dean committed
  'e2a81ac6617d7963bda5155239b4b262'
);

-- Test short_url object: /short_link
INSERT INTO objects (bucket_key, bucket, key, dir, type, dest_url, content_type) VALUES (
Dean's avatar
Dean committed
  '/short_path',
Dean's avatar
Dean committed
  1,
  'https://google.com',
Dean's avatar
Dean committed
);