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

Disable hard coded updatedAt/updated_at columns? #1871

Open
dwidge opened this issue Dec 23, 2024 · 0 comments
Open

Disable hard coded updatedAt/updated_at columns? #1871

dwidge opened this issue Dec 23, 2024 · 0 comments

Comments

@dwidge
Copy link

dwidge commented Dec 23, 2024

Our API stores timestamps (createdAt and updatedAt) as epoch seconds instead of milliseconds. Additionally, the API returns its data using camelCase (updatedAt) rather than snake_case (updated_at). This discrepancy caused us debugging challenges, particularly with errors like the following:

Cannot destructure property 'type' of 'columnSchema' as it is undefined.
Call Stack
_setRaw
node_modules/@nozbe/watermelondb/RawRecord/index.js
setRawSanitized
node_modules/@nozbe/watermelondb/RawRecord/index.js
_setRaw
node_modules/@nozbe/watermelondb/Model/index.js

The error message provided no clear indication of which key or column was causing the issue. To identify the root cause, we had to manually comment out columns one by one until the error disappeared.

Proposed Solutions

Configurable or Self-Managed Timestamps

Can createdAt and updatedAt be made configurable or optionally self-managed?
This would allow us to retain these column names (createdAt and updatedAt) while managing their behavior ourselves.

Current workaround: Renaming columns to createdAt2/updatedAt2 and using adapters to translate between the API, WatermelonDB, and React components.

Improved Error Messaging

Can error messages in _setRaw (or higher up the call stack) include additional context, such as the specific key or column name causing the issue? This would make debugging a bit easier.

Example Workaround

import { Model, tableSchema } from "@nozbe/watermelondb";
import { field } from "@nozbe/watermelondb/decorators";

export type Item1 = {
  id: string;
  updatedAt: number;
  createdAt: number;
  deletedAt: number | null;
  data: string | null;
};

export class Item1Model
  extends Model
  implements Omit<Item1, "id" | "createdAt" | "updatedAt" | "deletedAt">
{
  static table = "Item";

  @field("createdAt") createdAt2!: number;
  @field("updatedAt") updatedAt2!: number;
  @field("deletedAt") deletedAt2!: number | null;
  @field("data") data!: string | null;
}

export const Item1Table = tableSchema({
  name: "Item",
  columns: [
    { name: "createdAt", type: "number", isOptional: false },
    { name: "updatedAt", type: "number", isOptional: false },
    { name: "deletedAt", type: "number", isOptional: true },
    { name: "data", type: "string", isOptional: true },
  ],
});

Related Issues

#1752

@dwidge dwidge changed the title Remove hard coded updatedAt/updated_at columns? Disable hard coded updatedAt/updated_at columns? Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant