drizzle-team / drizzle-team/drizzle-orm
[BUG]: Column names in `pgView` definitions are not used
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### What version of `drizzle-orm` are you using?
0.35.3
### What version of `drizzle-kit` are you using?
0.26.2
### Describe the Bug
1. Write the following schema
```ts
import { eq } from "drizzle-orm";
import { pgTable, uuid, text, pgView } from "drizzle-orm/pg-core";
export const table1 = pgTable("table_1", {
id: uuid().primaryKey().defaultRandom(),
foo: text(),
});
export const table2 = pgTable("table_2", {
id: uuid().references(() => table1.id),
foo: text(),
});
export const view = pgView("view").as((qb) =>
qb
.select({ id: table1.id, foo_one: table1.foo, foo_two: table2.foo })
.from(table1)
.leftJoin(table2, eq(table1.id, table2.id)),
);
```
2. Generate migration files with `drizzle-kit` (you can also use https://drizzle.run/converter)
3. The SQL that generates the view looks like
```sql
CREATE VIEW "public"."view" AS (
select
"table_1"."id",
"table_1"."foo",
"table_2"."foo"
from "table_1"
left join "table_2" on "table_1"."id" = "table_2"."id"
);
```
This generates a view with two columns named `foo`, which will error when trying to apply the migration.
### Expected behavior
The columns in the view should take the name of the properties in the `qb.select()`, and the select in the `CREATE VIEW` should look say `table_1.foo AS foo_one, table_2.foo AS foo_two`.
### Environment & setup
https://drizzle.run/converter
Contributor guide
Assessment
This issue has not been assessed yet.