diff --git a/Dockerfile b/Dockerfile index 5d0334f..9222e23 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,6 +22,7 @@ WORKDIR /usr/src/app # Copy built files, schema, and package.json COPY --from=builder /usr/src/app/dist/index.js ./dist/index.js +COPY --from=builder /usr/src/app/dist/migrate.js ./dist/migrate.js COPY schema.sql ./ COPY package.json ./ diff --git a/package.json b/package.json index 57a7ac8..c2de5da 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,9 @@ "type": "module", "scripts": { "dev": "bun --hot src/index.ts", - "build": "bun build src/index.ts --target=bun --outfile=dist/index.js", + "build": "bun build src/index.ts --target=bun --outfile=dist/index.js && bun build src/db/migrate.ts --target=bun --outfile=dist/migrate.js", "start": "NODE_ENV=production bun dist/index.js", - "db:migrate": "bun src/db/migrate.ts", + "db:migrate": "bun dist/migrate.js", "test": "bun test test/rateLimit.test.ts && bun test test/file.test.ts && bun test test/telegram.test.ts && bun test test/upload.test.ts && bun test test/files.test.ts && bun test test/health.test.ts && bun test test/bot.test.ts && bun test test/bootstrap.test.ts && bun test test/swagger.test.ts", "lint": "bunx biome check src test", "format": "bunx biome format --write src test" diff --git a/schema.sql b/schema.sql index 5f1fa81..015a77f 100644 --- a/schema.sql +++ b/schema.sql @@ -1,4 +1,4 @@ -CREATE TABLE files ( +CREATE TABLE IF NOT EXISTS files ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), public_id VARCHAR(21) UNIQUE NOT NULL, telegram_file_id VARCHAR NOT NULL, @@ -10,11 +10,14 @@ CREATE TABLE files ( size_bytes BIGINT NOT NULL, file_type VARCHAR NOT NULL, uploader_id BIGINT NOT NULL, + file_hash VARCHAR, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); -CREATE INDEX idx_files_public_id ON files(public_id); -CREATE INDEX idx_files_telegram_file_id ON files(telegram_file_id); -CREATE INDEX idx_files_uploader_id ON files(uploader_id); -CREATE INDEX idx_files_created_at ON files(created_at DESC); \ No newline at end of file +ALTER TABLE files ADD COLUMN IF NOT EXISTS file_hash VARCHAR; + +CREATE INDEX IF NOT EXISTS idx_files_public_id ON files(public_id); +CREATE INDEX IF NOT EXISTS idx_files_telegram_file_id ON files(telegram_file_id); +CREATE INDEX IF NOT EXISTS idx_files_uploader_id ON files(uploader_id); +CREATE INDEX IF NOT EXISTS idx_files_created_at ON files(created_at DESC); \ No newline at end of file