Error: relation "offers_details" does not exist
Hey, I'm not really familiar with a lot of backend.
When I'm running this code it just saying the following:
Would you mind share some idea what might be the problem?
Error: relation "offers_details" does not exist
Error: relation "offers_details" does not exist
1 Reply
./schema/index.js
database.ts
offerDetails.test.ts
It seems like
import {
numeric,
pgTable,
jsonb,
serial,
timestamp,
varchar,
} from 'drizzle-orm/pg-core';
import { InferModel } from 'drizzle-orm';
export const offerDetails = pgTable('offer_details', {
id: serial('id').primaryKey(),
url: varchar('url').notNull(),
title: varchar('title').notNull(),
description: varchar('description').notNull(),
price: numeric('price', { precision: 20, scale: 2 }).notNull(),
currency: varchar('currency', { length: 8 }).default('PLN').notNull(),
area: numeric('area', { precision: 20, scale: 2 }).notNull(),
additionalParameters: jsonb('additionalParameters'),
rawResponse: varchar('rawResponse').notNull(),
createDate: timestamp('createDate').notNull(),
modificationDate: timestamp('modificationDate').notNull(),
});
import {
numeric,
pgTable,
jsonb,
serial,
timestamp,
varchar,
} from 'drizzle-orm/pg-core';
import { InferModel } from 'drizzle-orm';
export const offerDetails = pgTable('offer_details', {
id: serial('id').primaryKey(),
url: varchar('url').notNull(),
title: varchar('title').notNull(),
description: varchar('description').notNull(),
price: numeric('price', { precision: 20, scale: 2 }).notNull(),
currency: varchar('currency', { length: 8 }).default('PLN').notNull(),
area: numeric('area', { precision: 20, scale: 2 }).notNull(),
additionalParameters: jsonb('additionalParameters'),
rawResponse: varchar('rawResponse').notNull(),
createDate: timestamp('createDate').notNull(),
modificationDate: timestamp('modificationDate').notNull(),
});
import { drizzle } from 'drizzle-orm/node-postgres';
import { Pool } from 'pg';
import * as schema from './schema/index.js';
const pool = new Pool({
host: 'localhost',
port: 5432,
user: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD,
database: process.env.POSTGRES_DB,
});
export const db = drizzle(pool, { schema: { ...schema }, logger: true });
import { drizzle } from 'drizzle-orm/node-postgres';
import { Pool } from 'pg';
import * as schema from './schema/index.js';
const pool = new Pool({
host: 'localhost',
port: 5432,
user: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD,
database: process.env.POSTGRES_DB,
});
export const db = drizzle(pool, { schema: { ...schema }, logger: true });
import { describe, test, expect, vi, beforeEach } from 'vitest';
import { sql } from 'drizzle-orm';
import { db } from '../database.js';
import { offerDetails } from '../schema/index.js';
const record = {
url: "https://www.example.com/",
title: "Mock title",
description: "Mock description",
price: 100,
currency: "EUR",
area: 82.1,
additionalParameters: {},
rawResponse: "Mock raw response",
createDate: new Date(),
updateDate: new Date(),
}
describe('OfferDetails schema', () => {
test('should create OfferDetails item', async () => {
await db.select().from(offerDetails);
await expect(db.select().from(offerDetails)).resolves.toEqual(record);
});
});
import { describe, test, expect, vi, beforeEach } from 'vitest';
import { sql } from 'drizzle-orm';
import { db } from '../database.js';
import { offerDetails } from '../schema/index.js';
const record = {
url: "https://www.example.com/",
title: "Mock title",
description: "Mock description",
price: 100,
currency: "EUR",
area: 82.1,
additionalParameters: {},
rawResponse: "Mock raw response",
createDate: new Date(),
updateDate: new Date(),
}
describe('OfferDetails schema', () => {
test('should create OfferDetails item', async () => {
await db.select().from(offerDetails);
await expect(db.select().from(offerDetails)).resolves.toEqual(record);
});
});
drizzle
simple doesn't trigger CREATE TABLE
:/
Is that intended?