Open chrisl777 opened 1 month ago
Hey👋, thanks for raising this! I'm going to transfer this over to our API repository for better assistance 🙂
Hey @chrisl777, Thanks for raising this. To better understand the issue, would you be able to share the generated schema?
@AnilMaktala I can't share the entire generated schema publicly, but here's an excerpt of some models that I thought may be interesting.
Oddly, the identifier in some cases is not "id"
. Also, some of the table ids are integers (stored as BigInt in Postgres).
/* eslint-disable */
/* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. */
import { a } from "@aws-amplify/data-schema";
import { configure } from "@aws-amplify/data-schema/internals";
import { secret } from "@aws-amplify/backend";
export const schema = configure({
database: {
identifier: "...",
engine: "postgresql",
connectionUri: secret("SQL_CONNECTION_STRING"),
sslCert: secret("CUSTOM_SSL_CERT")
}
}).schema({
....
"ar_internal_metadata": a.model({
key: a.string().required(),
value: a.string(),
created_at: a.datetime().required(),
updated_at: a.datetime().required()
}).identifier([
"key"
]),
...
"cities": a.model({
id: a.integer().required(),
city_name: a.string(),
state_id: a.integer().required()
}).identifier([
"id"
]),
...
"notifications": a.model({
id: a.integer().required(),
sender_user_id: a.integer().required(),
receiver_user_id: a.integer().required(),
notification_category: a.string().required(),
notification_message: a.string(),
additional_data: a.json(),
read_status: a.string().required(),
created_at: a.datetime().required(),
updated_at: a.datetime().required()
}).identifier([
"id"
]),
...
"schema_migrations": a.model({
version: a.string().required()
}).identifier([
"version"
]),
...
"states": a.model({
id: a.integer().required(),
state_name: a.string(),
state_code: a.string()
}).identifier([
"id"
]),
...
"venues": a.model({
id: a.integer().required(),
...,
created_at: a.datetime().required(),
updated_at: a.datetime().required(),
metadata: a.json().required(),
...
}).identifier([
"id"
]),
});
Hey @chrisl777, Thanks for your reply. Based on the error, the issue seems related to the Brand model. Do you have a Brand model, and if so, could you share it with us?
@AnilMaktala As far as Brand, if you mean database type, we're connecting to a Postgres database (it's a third party database host, not RDS).
We followed these directions quite closely to generate the schema (Postgres): https://docs.amplify.aws/react-native/build-a-backend/data/connect-to-existing-data-sources/connect-postgres-mysql-database/
Hey @chrisl777, thanks for providing additional details. Can you please remove and re-install the node modules. run below command to remove the node modules
and package-lock.json
file.
rm -rf node_modules package-lock.json
Oddly, the identifier in some cases is not "id". Also, some of the table ids are integers (stored as BigInt in Postgres).
Hey @chrisl777 - It looks like in some cases, the primary key isn't correctly detected during the schema generation step and it ends up assigning the default id
field as primary key which could be breaking the type definition. Could you share the CREATE TABLE
script and the corresponding model definition (a.model({...})
) from the generated schema file for one of the tables for which the inferred primary key is incorrect.
@sundersc @AnilMaktala I ended up commenting out the "ar_internal_metadata" and "schema_migrations" tables in the generated schema, as I don't really need those for operation of the app.
In the case of "ar_internal_metadata," that table is apparently automatically created by Rails to check the current environment before running migrations (the current backend was created using Ruby on Rails): https://vinioyama.com/blog/ruby-on-rails-what-is-ar_internal_metadata-metada-table/
For the "schema_migrations" table, it similarly is automatically created by Rails to manage databse migrations: https://planetscale.com/docs/tutorials/automatic-rails-migrations
Going forward, I don't need to access these tables via AppSync, so it's not as much of an issue. But I could see other people tripping over this problem.
Environment information
Describe the bug
I'm following the directions on connecting to existing data sources:
https://docs.amplify.aws/react-native/build-a-backend/data/connect-to-existing-data-sources/connect-postgres-mysql-database/
In my case, I'm connecting to a Postgres database (third-party, not RDS).
I see the following error when I deploy the sandbox:
Reproduction steps
Follow the directions for importing your database schema (using
npx ampx generate schema-from-database
).Deploy the sandbox with
npx ampx sandbox
.