drizzle-team / drizzle-team/drizzle-orm
[ENHANCEMENT] Support other geometry types in PG
- 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.33.0
### What version of `drizzle-kit` are you using?
0.24.2
### Describe the Bug
I have a table in the database like the below
```sql
CREATE TABLE IF NOT EXISTS geohub.dataset
(
id character varying COLLATE pg_catalog."default" NOT NULL,
url character varying COLLATE pg_catalog."default" NOT NULL,
is_raster boolean NOT NULL,
license character varying COLLATE pg_catalog."default",
bounds geometry(Polygon,4326) NOT NULL,
createdat timestamp with time zone NOT NULL,
updatedat timestamp with time zone,
name character varying COLLATE pg_catalog."default",
description character varying COLLATE pg_catalog."default",
created_user character varying(100) COLLATE pg_catalog."default" NOT NULL,
updated_user character varying(100) COLLATE pg_catalog."default",
access_level integer NOT NULL DEFAULT 3,
CONSTRAINT dataset_pkey PRIMARY KEY (id)
)
```
When I used `introspect`, introspect correctly generated initial SQL like below
```sql
CREATE TABLE IF NOT EXISTS "geohub"."dataset" (
"id" varchar PRIMARY KEY NOT NULL,
"url" varchar NOT NULL,
"is_raster" boolean NOT NULL,
"license" varchar,
"bounds" geometry(Polygon,4326) NOT NULL, # introspect correctly generated current schema
"createdat" timestamp with time zone NOT NULL,
"updatedat" timestamp with time zone,
"name" varchar,
"description" varchar,
"created_user" varchar(100) NOT NULL,
"updated_user" varchar(100),
"access_level" integer DEFAULT 3 NOT NULL
);
```
and, the below is schema.ts generated by introspect. This has no issue.
```ts
export const datasetInGeohub = geohub.table(
'dataset',
{
id: varchar('id').primaryKey().notNull(),
url: varchar('url').notNull(),
isRaster: boolean('is_raster').notNull(),
license: varchar('license'),
bounds: geometry('bounds', { type: 'polygon', srid: 4326 }).notNull(),
createdat: timestamp('createdat', { withTimezone: true, mode: 'string' }).notNull(),
updatedat: timestamp('updatedat', { withTimezone: true, mode: 'string' }),
name: varchar('name'),
description: varchar('description'),
createdUser: varchar('created_user', { length: 100 }).notNull(),
updatedUser: varchar('updated_user', { length: 100 }),
accessLevel: integer('access_level').default(3).notNull()
},
(table) => {
return {
boundsGeomIdx: index('dataset_bounds_geom_idx').using('gist', table.bounds.asc().nullsLast())
};
}
);
```
However, when I used `pnpm drizzle-kit:generate`, it created the wrong SQL like below. Then when I push migrations to my local database, drizzle create the table with point geometry without specified srid 4326 even schema.ts is configured correctly.
```sql
CREATE TABLE IF NOT EXISTS "geohub"."dataset" (
"id" varchar PRIMARY KEY NOT NULL,
"url" varchar NOT NULL,
"is_raster" boolean NOT NULL,
"license" varchar,
"bounds" geometry(point) NOT NULL, # changed polygon to point, and dropped srid
"createdat" timestamp with time zone NOT NULL,
"updatedat" timestamp with time zone,
"name" varchar,
"description" varchar,
"created_user" varchar(100) NOT NULL,
"updated_user" varchar(100),
"access_level" integer DEFAULT 3 NOT NULL
);
```
### Expected behavior
migration should correctly create Polygon geometry SQL with srid as `introspect` does.
### Environment & setup
I am using drizzle in svelte-kit
drizzle.config.ts is as follow
```ts
import { defineConfig } from 'drizzle-kit';
export default defineConfig({
schema: './src/lib/server/schema.ts',
out: './drizzle_tmp',
dialect: 'postgresql',
dbCredentials: {
url: process.env.DATABASE_CONNECTION!
},
schemaFilter: ['geohub'],
extensionsFilters: ['postgis']
});
```
my working branch is at https://github.com/UNDP-Data/geohub/pull/4142
Contributor guide
Assessment
This issue has not been assessed yet.