Skip to content
Snippets Groups Projects
objects.sql 1.58 KiB
Newer Older
Dean's avatar
Dean committed
-- "objects" table schema
CREATE TABLE IF NOT EXISTS objects (
  bucket_key VARCHAR(1088) NOT NULL UNIQUE, -- bucket + key (unique)
  bucket VARCHAR(20) NOT NULL, -- uint64 bucket ID ("public" for public bucket)
  "key" VARCHAR(1024) NOT NULL, -- Full bucket path to file (including directory)
  random_key VARCHAR(1024), -- random key if used
  dir VARCHAR(1024) NOT NULL, -- Directory of file (with trailing slash)
  "type" integer NOT NULL DEFAULT 0, -- Object type enumerable (0 = file, 1 = redirect)
  dest_url VARCHAR(1024) DEFAULT NULL, -- Destination URL for redirect object (only when object.type == 1)
Dean's avatar
Dean committed
  content_type VARCHAR(255) DEFAULT 'application/octet-stream', -- Content-Type of file
  content_length INT DEFAULT NULL, -- Content-Length of file
  associated_user VARCHAR(36) DEFAULT NULL, -- ID of user who uploaded file
Dean's avatar
Dean committed
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- File creation timestamp
  deleted_at TIMESTAMP DEFAULT NULL, -- Deletion timestamp
  delete_reason VARCHAR(256) DEFAULT NULL, -- Deletion reason
  md5_hash VARCHAR(32) DEFAULT NULL -- 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
);