From 385bd572a32f68e8fd80bc909d6bfdbca760f684 Mon Sep 17 00:00:00 2001 From: Alexander Onnikov Date: Tue, 22 Oct 2024 00:49:23 +0700 Subject: [PATCH] fix: use string content type instead of enum (#7007) Signed-off-by: Alexander Onnikov --- workers/datalake/schema/datalake.sql | 5 +---- workers/datalake/src/blob.ts | 8 +++----- workers/datalake/src/db.ts | 9 ++++----- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/workers/datalake/schema/datalake.sql b/workers/datalake/schema/datalake.sql index 892564e7e9..4dfbfed035 100644 --- a/workers/datalake/schema/datalake.sql +++ b/workers/datalake/schema/datalake.sql @@ -3,12 +3,10 @@ CREATE SCHEMA IF NOT EXISTS blob; DROP TABLE IF EXISTS blob.blob; DROP TABLE IF EXISTS blob.data; -DROP TYPE IF EXISTS blob.content_type; DROP TYPE IF EXISTS blob.location; -- B L O B -CREATE TYPE blob.content_type AS ENUM ('application','audio','font','image','model','text','video'); CREATE TYPE blob.location AS ENUM ('kv', 'weur', 'eeur', 'wnam', 'enam', 'apac'); \echo "Creating blob.data..." @@ -17,8 +15,7 @@ CREATE TABLE blob.data ( location blob.location NOT NULL, size INT8 NOT NULL, filename UUID NOT NULL, - type blob.content_type NOT NULL, - subtype STRING(64) NOT NULL, + type STRING(255) NOT NULL, CONSTRAINT pk_data PRIMARY KEY (hash, location) ); diff --git a/workers/datalake/src/blob.ts b/workers/datalake/src/blob.ts index fc893b9151..e21f9c327e 100644 --- a/workers/datalake/src/blob.ts +++ b/workers/datalake/src/blob.ts @@ -163,7 +163,6 @@ async function saveBlob ( const { location, bucket } = selectStorage(env, workspace) const size = file.size - const [mimetype, subtype] = type.split('/') const httpMetadata = { contentType: type, cacheControl } const filename = getUniqueFilename() @@ -179,7 +178,7 @@ async function saveBlob ( } else { await bucket.put(filename, file, { httpMetadata }) await sql.begin((sql) => [ - db.createData(sql, { hash, location, filename, type: mimetype, subtype, size }), + db.createData(sql, { hash, location, filename, type, size }), db.createBlob(sql, { workspace, name, hash, location }) ]) } @@ -201,7 +200,7 @@ async function saveBlob ( } else { // Otherwise register a new hash and blob await sql.begin((sql) => [ - db.createData(sql, { hash, location, filename, type: mimetype, subtype, size }), + db.createData(sql, { hash, location, filename, type, size }), db.createBlob(sql, { workspace, name, hash, location }) ]) } @@ -227,9 +226,8 @@ export async function handleBlobUploaded (env: Env, workspace: string, name: str } else { const size = object.size const type = object.httpMetadata.contentType ?? 'application/octet-stream' - const [mimetype, subtype] = type.split('/') - await db.createData(sql, { hash, location, filename, type: mimetype, subtype, size }) + await db.createData(sql, { hash, location, filename, type, size }) await db.createBlob(sql, { workspace, name, hash, location }) } } diff --git a/workers/datalake/src/db.ts b/workers/datalake/src/db.ts index ad7ea03f33..725c21c62c 100644 --- a/workers/datalake/src/db.ts +++ b/workers/datalake/src/db.ts @@ -25,7 +25,6 @@ export interface BlobDataRecord extends BlobDataId { filename: UUID size: number type: string - subtype: string } export interface BlobId { @@ -47,7 +46,7 @@ export async function getData (sql: postgres.Sql, dataId: BlobDataId): Promise` - SELECT hash, location, filename, size, type, subtype + SELECT hash, location, filename, size, type FROM blob.data WHERE hash = ${hash} AND location = ${location} ` @@ -60,11 +59,11 @@ export async function getData (sql: postgres.Sql, dataId: BlobDataId): Promise { - const { hash, location, filename, size, type, subtype } = data + const { hash, location, filename, size, type } = data await sql` - UPSERT INTO blob.data (hash, location, filename, size, type, subtype) - VALUES (${hash}, ${location}, ${filename}, ${size}, ${type}, ${subtype}) + UPSERT INTO blob.data (hash, location, filename, size, type) + VALUES (${hash}, ${location}, ${filename}, ${size}, ${type}) ` }