Open TazChoudhury opened 5 months ago
Also having this issue. I have tried changing the connection string all sorts of ways.
node_modules/@aws-amplify/schema-generator/lib/generate-schema.js
shows this code:
export const parseDatabaseUrl = (databaseUrl) => {
try {
const parsedDatabaseUrl = new URL(databaseUrl);
const { username: encodedUsername, password: encodedPassword, hostname: encodedHost, } = parsedDatabaseUrl;
const username = decodeURIComponent(encodedUsername);
const password = decodeURIComponent(encodedPassword);
const host = decodeURIComponent(encodedHost);
const database = decodeURIComponent(parsedDatabaseUrl?.pathname?.slice(1));
// Default engine is MySQL
const engine = constructDBEngine(parsedDatabaseUrl?.protocol?.slice(0, -1) ?? DEFAULT_ENGINE);
const port = parsedDatabaseUrl?.port
? parseInt(parsedDatabaseUrl?.port, 10)
: getDefaultPort(engine);
const config = {
engine,
username,
password,
database,
host,
port,
};
I would assume the schema should be here but is not included.
Edit: I should also note that this works with another database name that has a table under the public schema, but for this case, the public schema does not contain any tables, thus returning the Imported SQL schema is empty.
error.
I was able to modify my database to fix this issue. This may not be an option in some cases however.
CREATE VIEW public.table AS SELECT * FROM otherSchema.table;
I was able to get a auto generated schema from amplify after making this change
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
Storage
Amplify Version
v6
Amplify Categories
storage
Backend
Amplify Gen 2 (Preview)
Environment information
Describe the bug
When running the command:
npx ampx generate schema-from-database --connection-uri-secret SQL_CONNECTION_STRING --out amplify/data/schema.sql.ts
The auto-generation process does not pick up tables that are in non-public schemas. If the table_schema is not 'public' or belongs to another category, it will not be included by the auto-generation command.
Expected behavior
All tables within the 'public' schema or any other user-defined schemas should be picked up by the auto-generation process. Tables within the pg_catalog or information_schema schemas should be ignored.
Reproduction steps
Having run the step 1 from this guide. Then run step 2 on a postgresql database that has tables under a non public schema.