drizzle-team / drizzle-team/drizzle-orm

[BUG]: --force does not always skip prompts

Open
#4,490 2 comments 3 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Report hasn't been filed before.

- [x] I have verified that the bug I'm about to report hasn't been filed before.

### What version of `drizzle-orm` are you using?

0.43.1

### What version of `drizzle-kit` are you using?

0.31.1

### Other packages

_No response_

### Describe the Bug

```
pnpm drizzle-kit push --force --config drizzle.config.ts

Reading config file '/Users/steebchen/projects/openllm/openllm/packages/db/drizzle.config.ts'
Using 'pg' driver for database querying
[✓] Pulling schema from database...
· You're about to add provider_key_projectId_provider_unique unique constraint to the table, which contains 2 items. If this statement fails, you will receive an error from the database. Do you want to truncate provider_key table?

❯ No, add the constraint without truncating the table
Yes, truncate the table
```

schema.ts

```ts
import {
boolean,
integer,
json,
pgTable,
real,
text,
timestamp,
unique,
} from "drizzle-orm/pg-core";
import { customAlphabet } from "nanoid";

const generate = customAlphabet(
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
);

export const shortid = (size = 20) => generate(size);

export const user = pgTable("user", {
id: text().primaryKey().$defaultFn(shortid),
createdAt: timestamp().notNull().defaultNow(),
updatedAt: timestamp().notNull().defaultNow(),
name: text(),
email: text().notNull().unique(),
emailVerified: boolean().notNull().default(false),
image: text(),
});

export const session = pgTable("session", {
id: text().primaryKey().$defaultFn(shortid),
expiresAt: timestamp().notNull().defaultNow(),
token: text().notNull().unique(),
createdAt: timestamp().notNull().defaultNow(),
updatedAt: timestamp().notNull().defaultNow(),
ipAddress: text(),
userAgent: text(),
userId: text()
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
});

export const account = pgTable("account", {
id: text().primaryKey().$defaultFn(shortid),
accountId: text().notNull(),
providerId: text().notNull(),
userId: text()
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
accessToken: text(),
refreshToken: text(),
idToken: text(),
accessTokenExpiresAt: timestamp(),
refreshTokenExpiresAt: timestamp(),
scope: text(),
password: text(),
createdAt: timestamp().notNull().defaultNow(),
updatedAt: timestamp().notNull().defaultNow(),
});

export const verification = pgTable("verification", {
id: text().primaryKey().$defaultFn(shortid),
identifier: text().notNull(),
value: text().notNull(),
expiresAt: timestamp().notNull().defaultNow(),
createdAt: timestamp(),
updatedAt: timestamp(),
});

export const organization = pgTable("organization", {
id: text().primaryKey().notNull().$defaultFn(shortid),
createdAt: timestamp().notNull().defaultNow(),
updatedAt: timestamp().notNull().defaultNow(),
name: text().notNull(),
});

export const userOrganization = pgTable("user_organization", {
id: text().primaryKey().notNull().$defaultFn(shortid),
createdAt: timestamp().notNull().defaultNow(),
updatedAt: timestamp().notNull().defaultNow(),
userId: text().notNull(),
organizationId: text().notNull(),
});

export const project = pgTable("project", {
id: text().primaryKey().notNull().$defaultFn(shortid),
createdAt: timestamp().notNull().defaultNow(),
updatedAt: timestamp().notNull().defaultNow(),
name: text().notNull(),
organizationId: text().notNull(),
});

export const apiKey = pgTable("api_key", {
id: text().primaryKey().notNull().$defaultFn(shortid),
createdAt: timestamp().notNull().defaultNow(),
updatedAt: timestamp().notNull().defaultNow(),
token: text().notNull().unique(),
description: text().notNull(),
status: text({
enum: ["active", "inactive", "deleted"],
}).default("active"),
projectId: text().notNull(),
});

export const providerKey = pgTable(
"provider_key",
{
id: text().primaryKey().notNull().$defaultFn(shortid),
createdAt: timestamp().notNull().defaultNow(),
updatedAt: timestamp().notNull().defaultNow(),
token: text().notNull().unique(),
provider: text().notNull(),
baseUrl: text(), // Optional base URL for custom providers
status: text({
enum: ["active", "inactive", "deleted"],
}).default("active"),
projectId: text().notNull(),
},
(table) => [unique().on(table.projectId, table.provider)],
);

export const log = pgTable("log", {
id: text().primaryKey().notNull().$defaultFn(shortid),
createdAt: timestamp().notNull().defaultNow(),
updatedAt: timestamp().notNull().defaultNow(),
projectId: text().notNull(),
apiKeyId: text().notNull(),
providerKeyId: text().notNull(),
duration: integer().notNull(),
requestedModel: text().notNull(),
requestedProvider: text(),
usedModel: text().notNull(),
usedProvider: text().notNull(),
responseSize: integer().notNull(),
content: text(),
finishReason: text(),
promptTokens: integer(),
completionTokens: integer(),
totalTokens: integer(),
messages: json().notNull(),
temperature: real(),
maxTokens: integer(),
topP: real(),
frequencyPenalty: real(),
presencePenalty: real(),
hasError: boolean().default(false),
errorDetails: json(),
cost: real(),
inputCost: real(),
outputCost: real(),
});
```

relations.ts
```ts
import { defineRelations } from "drizzle-orm";

import * as schema from "./schema";

export const relations = defineRelations(schema, (r) => ({
user: {
userOrganizations: r.many.userOrganization(),
},
organization: {
userOrganizations: r.many.userOrganization(),
projects: r.many.project(),
},
userOrganization: {
user: r.one.user({
from: r.userOrganization.userId,
to: r.user.id,
}),
organization: r.one.organization({
from: r.userOrganization.organizationId,
to: r.organization.id,
}),
},
project: {
organization: r.one.organization({
from: r.project.organizationId,
to: r.organization.id,
}),
apiKeys: r.many.apiKey(),
logs: r.many.log(),
},
apiKey: {
project: r.one.project({
from: r.apiKey.projectId,
to: r.project.id,
}),
logs: r.many.log(),
},
providerKey: {
project: r.one.project({
from: r.providerKey.projectId,
to: r.project.id,
}),
logs: r.many.log(),
},
log: {
project: r.one.project({
from: r.log.projectId,
to: r.project.id,
}),
apiKey: r.one.apiKey({
from: r.log.apiKeyId,
to: r.apiKey.id,
}),
providerKey: r.one.providerKey({
from: r.log.providerKeyId,
to: r.providerKey.id,
}),
},
}));
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.