Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support PostgreSQL postgres_fdw extension: Foreign Data Wrappers #8614

Open
Tracked by #16311
janpio opened this issue Aug 6, 2021 · 8 comments
Open
Tracked by #16311

Support PostgreSQL postgres_fdw extension: Foreign Data Wrappers #8614

janpio opened this issue Aug 6, 2021 · 8 comments
Labels
domain/psl Issue in the "PSL" domain: Prisma Schema Language domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. kind/feature A request for a new feature. topic: database-functionality topic: foreign data wrapper topic: postgresql topic: postgresqlExtensions

Comments

@janpio
Copy link
Member

janpio commented Aug 6, 2021

Problem

PostgreSQL offers the postgres_fdw extension for Foreign Data Wrappers, "which can be used to access data stored in external PostgreSQL servers".

https://www.postgresql.org/docs/9.5/postgres-fdw.html
https://www.postgresql.org/docs/9.5/sql-importforeignschema.html
https://www.percona.com/blog/2018/08/21/foreign-data-wrappers-postgresql-postgres_fdw/
https://thoughtbot.com/blog/postgres-foreign-data-wrapper

Suggested solution

Prisma should work with servers configured using postgres_fdw.

Alternatives

None.

Additional context

#8610

@janpio janpio added kind/feature A request for a new feature. topic: database-functionality topic: postgresql domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. labels Aug 6, 2021
@Jolg42 Jolg42 changed the title PostgreSQL Foreign Data Wrappers Support PostgreSQL postgres_fdw extension: Foreign Data Wrappers Aug 12, 2021
@janpio
Copy link
Member Author

janpio commented Nov 16, 2022

Prisma currently can not introspect foreign tables like this one:

CREATE FOREIGN TABLE hackernews.hackernews_ask_hn (
	id int8 NULL,
	title text NULL,
	"time" timestamptz NULL,
	"by" text NULL,
	score int8 NULL,
	dead bool NULL,
	deleted bool NULL,
	descendants int8 NULL,
	kids jsonb NULL,
	parent int8 NULL,
	parts jsonb NULL,
	poll int8 NULL,
	"text" text NULL,
	"type" text NULL,
	url text NULL
)
SERVER steampipe
OPTIONS (table 'hackernews_ask_hn');

This is a table set up by cloud.steampipe.io (Sign up, create setup with "Hackernews" setup, use credentials form "Connect" tab). It works fine in Dbeaver:

image image image

We should be able to support this in Prisma as well.

#13793 (comment)

@janpio janpio added the domain/psl Issue in the "PSL" domain: Prisma Schema Language label May 25, 2023
@baconcheese113
Copy link

This would be awesome to support! Our use case would ensure that all foreign tables are read-only, not sure if that simplifies the problem for you.

@JEbertPrime
Copy link

JEbertPrime commented Oct 9, 2023

@janpio I might be wrong, but is fixing this as simple as making an edit to the base SQL query to include foreign tables in this file or this file in the schema engine? Local testing using the binaries generated from my fork correctly introspected the foreign tables in my database

@janpio
Copy link
Member Author

janpio commented Oct 9, 2023

Yes and no. These changes might be enough for Introspection to pick these up, and represent them as models. But migrating that Prisma schema would just create normal tables. We could also not use any other potential functionality that they might bring (if any, did not read through the docs now to refresh my memory).

As you are using these, maybe you can help me answer these questions:
What other functionality than just Introspection and Migration would make sense for Foreign Data Wrappers?
Can these only be used via the extension mentioned above?

@JEbertPrime
Copy link

JEbertPrime commented Oct 9, 2023

To answer your questions, insofar as I can -
1 - In my use case and the one mentioned above, foreign tables are all read-only (because I'm using the file_fdw extension). It may be convenient to just ignore such tables when running migrations, but I don't know if that runs counter to how Prisma likes to do things. Beyond that it would be hard to come up with a list of functionalities since there are so many different types of FDWs
2 - Sort of addressed this before, but there are several native and non-native FDW extensions available for use that all have unique features. But the native extensions all attempt to use standard SQL for querying the foreign tables, and generally they can be queried like any other table (at least for read operations)

@JEbertPrime
Copy link

Have some time to come back to this issue - since full support for all foreign tables seems like a whole bag of worms based on other dependent features, would it be prudent to work on adding in the kind of warning outlined in #16311 ? Is there an existing standard for outputting warnings during introspection, such as this PR on the schema engine repo?

@janpio
Copy link
Member Author

janpio commented Nov 13, 2023

Yes, that was how we started to warn about these. Not sure what the state about FDWs is over there though.

@nipu-softic
Copy link

nipu-softic commented Feb 29, 2024

Error: ERROR: extension "postgres-fdw" is not available
DETAIL: Could not open extension control file "C:/Program Files/PostgreSQL/16/share/extension/postgres-fdw.control": No such file or directory.
HINT: The extension must first be installed on the system where PostgreSQL is running.
   0: sql_schema_connector::apply_migration::migration_step
           with step=CreateExtension(CreateExtension { id: ExtensionId(0) })
             at schema-engine\connectors\sql-schema-connector\src\apply_migration.rs:21
   1: sql_schema_connector::apply_migration::apply_migration
             at schema-engine\connectors\sql-schema-connector\src\apply_migration.rs:10
   2: schema_core::state::SchemaPush
             at schema-engine\core\src\state.rs:436

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain/psl Issue in the "PSL" domain: Prisma Schema Language domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. kind/feature A request for a new feature. topic: database-functionality topic: foreign data wrapper topic: postgresql topic: postgresqlExtensions
Projects
None yet
Development

No branches or pull requests

5 participants