diff --git a/.env b/.env new file mode 100644 index 0000000..d406536 --- /dev/null +++ b/.env @@ -0,0 +1,7 @@ +# Environment variables declared in this file are automatically made available to Prisma. +# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema + +# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB. +# See the documentation for all the connection string options: https://pris.ly/d/connection-strings + +DATABASE_URL="postgresql://mcrates:digdeep@0.0.0.0:45432/mcrates?schema=public" \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index 9e73aca..cc2f5c9 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -6,7 +6,7 @@ services: environment: POSTGRES_USER: 'mcrates' POSTGRES_DB: 'mcrates' - POSTGRES_PASSWORD: 'dig deep' + POSTGRES_PASSWORD: 'digdeep' ports: - '45432:5432' volumes: diff --git a/knexfile.js b/knexfile.js index cef5a48..3831975 100644 --- a/knexfile.js +++ b/knexfile.js @@ -5,7 +5,7 @@ module.exports = { port: 45432, database: 'mcrates', user: 'mcrates', - password: 'dig deep', + password: 'digdeep', }, pool: { min: 2, diff --git a/package-lock.json b/package-lock.json index 0d37157..a00b628 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "@prisma/client": "^4.1.0", "axios": "^0.27.2", "bluebird": "^3.7.2", "bunyan": "^1.8.15", @@ -19,6 +20,7 @@ }, "devDependencies": { "node-dev": "^7.4.3", + "prisma": "^4.1.0", "ts-node-dev": "^2.0.0", "typescript": "^4.7.4" } @@ -60,6 +62,38 @@ "@jridgewell/sourcemap-codec": "^1.4.10" } }, + "node_modules/@prisma/client": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@prisma/client/-/client-4.1.0.tgz", + "integrity": "sha512-MvfPGAd42vHTiCYxwS6N+2U3F+ukoJ48D2QRnX1zSPJHBkh1CBtshl75daKzvVfgQwSouzSQeugKDej5di+E/g==", + "hasInstallScript": true, + "dependencies": { + "@prisma/engines-version": "4.1.0-48.8d8414deb360336e4698a65aa45a1fbaf1ce13d8" + }, + "engines": { + "node": ">=14.17" + }, + "peerDependencies": { + "prisma": "*" + }, + "peerDependenciesMeta": { + "prisma": { + "optional": true + } + } + }, + "node_modules/@prisma/engines": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-4.1.0.tgz", + "integrity": "sha512-quqHXD3P83NBLVtRlts4SgKHmqgA8GMiyDTJ7af03Wg0gl6F5t65mBYvIuwmD+52vHm42JtIsp/fAO9YIV0JBA==", + "devOptional": true, + "hasInstallScript": true + }, + "node_modules/@prisma/engines-version": { + "version": "4.1.0-48.8d8414deb360336e4698a65aa45a1fbaf1ce13d8", + "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-4.1.0-48.8d8414deb360336e4698a65aa45a1fbaf1ce13d8.tgz", + "integrity": "sha512-cRRJwpHFGFJZvtHbY3GZjMffNBEjjZk68ztn+S2hDgPCGB4H66IK26roK94GJxBodSehwRJ0wGyebC2GoIH1JQ==" + }, "node_modules/@tsconfig/node10": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", @@ -1379,6 +1413,23 @@ "node": ">=0.10.0" } }, + "node_modules/prisma": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/prisma/-/prisma-4.1.0.tgz", + "integrity": "sha512-iwqpAT6In1uvMSwQAM3PqmaBdhh2OaQ/2t+n3RjpW4vAKP3R7E1T34FZUU4zGOWtMWm5dt0sPThQkT/h87r6gw==", + "devOptional": true, + "hasInstallScript": true, + "dependencies": { + "@prisma/engines": "4.1.0" + }, + "bin": { + "prisma": "build/index.js", + "prisma2": "build/index.js" + }, + "engines": { + "node": ">=14.17" + } + }, "node_modules/proxy-addr": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", @@ -1936,6 +1987,25 @@ "@jridgewell/sourcemap-codec": "^1.4.10" } }, + "@prisma/client": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@prisma/client/-/client-4.1.0.tgz", + "integrity": "sha512-MvfPGAd42vHTiCYxwS6N+2U3F+ukoJ48D2QRnX1zSPJHBkh1CBtshl75daKzvVfgQwSouzSQeugKDej5di+E/g==", + "requires": { + "@prisma/engines-version": "4.1.0-48.8d8414deb360336e4698a65aa45a1fbaf1ce13d8" + } + }, + "@prisma/engines": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-4.1.0.tgz", + "integrity": "sha512-quqHXD3P83NBLVtRlts4SgKHmqgA8GMiyDTJ7af03Wg0gl6F5t65mBYvIuwmD+52vHm42JtIsp/fAO9YIV0JBA==", + "devOptional": true + }, + "@prisma/engines-version": { + "version": "4.1.0-48.8d8414deb360336e4698a65aa45a1fbaf1ce13d8", + "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-4.1.0-48.8d8414deb360336e4698a65aa45a1fbaf1ce13d8.tgz", + "integrity": "sha512-cRRJwpHFGFJZvtHbY3GZjMffNBEjjZk68ztn+S2hDgPCGB4H66IK26roK94GJxBodSehwRJ0wGyebC2GoIH1JQ==" + }, "@tsconfig/node10": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", @@ -2913,6 +2983,15 @@ "xtend": "^4.0.0" } }, + "prisma": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/prisma/-/prisma-4.1.0.tgz", + "integrity": "sha512-iwqpAT6In1uvMSwQAM3PqmaBdhh2OaQ/2t+n3RjpW4vAKP3R7E1T34FZUU4zGOWtMWm5dt0sPThQkT/h87r6gw==", + "devOptional": true, + "requires": { + "@prisma/engines": "4.1.0" + } + }, "proxy-addr": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", diff --git a/package.json b/package.json index bac0a1a..76abd19 100644 --- a/package.json +++ b/package.json @@ -6,17 +6,19 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "migrate": "knex migrate:latest", - "migrate:make": "knex migrate:make --", + "migrate:make": "prisma migrate dev --name", "start": "ts-node-dev --respawn --transpile-only index.ts" }, "author": "", "license": "ISC", "devDependencies": { "node-dev": "^7.4.3", + "prisma": "^4.1.0", "ts-node-dev": "^2.0.0", "typescript": "^4.7.4" }, "dependencies": { + "@prisma/client": "^4.1.0", "axios": "^0.27.2", "bluebird": "^3.7.2", "bunyan": "^1.8.15", diff --git a/prisma/migrations/20220727084210_users/migration.sql b/prisma/migrations/20220727084210_users/migration.sql new file mode 100644 index 0000000..62f37d7 --- /dev/null +++ b/prisma/migrations/20220727084210_users/migration.sql @@ -0,0 +1,13 @@ +-- CreateTable +CREATE TABLE "User" ( + "id" TEXT NOT NULL, + "discogs" TEXT, + "data" JSONB NOT NULL, + "creaedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "User_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "User_discogs_key" ON "User"("discogs"); diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml new file mode 100644 index 0000000..fbffa92 --- /dev/null +++ b/prisma/migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added in your version-control system (i.e. Git) +provider = "postgresql" \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma new file mode 100644 index 0000000..173db4f --- /dev/null +++ b/prisma/schema.prisma @@ -0,0 +1,20 @@ +// This is your Prisma schema file, +// learn more about it in the docs: https://pris.ly/d/prisma-schema + +generator client { + provider = "prisma-client-js" +} + +datasource db { + provider = "postgresql" + url = env("DATABASE_URL") +} + +model User { + id String @id @default(uuid()) + discogs String? @unique + data Json + + creaedAt DateTime @default(now()) + updatedAt DateTime @updatedAt +} diff --git a/src/discogs.ts b/src/discogs.ts index 10f3e9a..e25fc6e 100644 --- a/src/discogs.ts +++ b/src/discogs.ts @@ -19,9 +19,7 @@ export default function discogs(pg: Pg) { function handleApiError(e) { logAxiosError(e); - console.log('aaaaa', e.response.status); if (e.response.status === 429) { - console.log('bbbbbbb') throw new Error('rate limited'); } }