drift icon indicating copy to clipboard operation
drift copied to clipboard

Postgres views

Open karroze opened this issue 10 months ago • 3 comments

Hi!

Postgres implementation of Drift does not seem to support views.

Upon creating any view, which works for the default sqlite implementation of Drift, Postgres would fail with this error:

ERROR:  syntax error at or near "NOT" at character 16
STATEMENT:  CREATE VIEW IF NOT EXISTS ...

So this raises the question: are views supported for Postgres? It doesn't seem to be mentioned anywhere in the docs that this functionality is not supported.

karroze avatar Apr 06 '25 10:04 karroze

Some drift methods, in particular the migration APIs, are only partially supported on Postgres. I'm currently working on a new drift version that will allow dialects more flexibility in how statements are created.

As a workaround in the meantime, I'm afraid the best option is probably to write the migration manually. You can run dart run drift_dev schema dump path/to/database.dart --dialect postgres to make drift print out the CREATE ... statements it would use. You can then fix them manually and either use a bunch of customStatement() calls in your onCreate / onUpgrade callbacks of the MigrationStrategy or use a different tool for Postgres to manage schema migrations.

simolus3 avatar Apr 09 '25 07:04 simolus3

Thank you for your answer! 👍

karroze avatar Apr 12 '25 15:04 karroze

@simolus3 Your comment is a bit confusing because it makes it sound like dump command supports --dialect. The official documentation also gives a similar confusing expression. I’ve opened a pull request. #3573

momadvisor avatar May 25 '25 05:05 momadvisor