Checks a database table every hour and appends any records it has not copied yet to a Google Sheet.
Uses
Google Sheets
Supabase
Copy new database records to a spreadsheet
Every hour, the workflow reads a table in your Supabase database and appends any record it has not copied before as a new row in a Google Sheet. People who cannot open the database get a live copy of the table in a spreadsheet, and the database itself is only ever read, never changed.
Each row holds the record's id, when it was created, its name and its email. The sheet is the memory: column A holds every copied id, and a record whose id is already there is skipped, so a second run adds nothing new, re-running after a failure is safe, and deleting a row from the sheet has that record copied again. Nothing already in the sheet is overwritten. A record with no id is skipped and reported, since it could never be told apart later, while a record missing a name or email is still copied with that cell left blank.
If the sheet is empty, a heading row is written first. The whole table is read on each run, so it suits tables up to a few thousand rows.
tableName to blank.Set tableName to blank.spreadsheetUrl to blank.Set spreadsheetUrl to blank.sheetName to Sheet1.Set sheetName to Sheet1.sheetName in spreadsheetUrl. Save it as sheetColumn.Read column 'A' of sheetName in spreadsheetUrl. Save it as sheetColumn.copiedKeys to sheetColumn.values.Set copiedKeys to sheetColumn.values.copiedKeys is emptyIf copiedKeys is emptysheetName in spreadsheetUrl.Add a row to sheetName in spreadsheetUrl.Record ID to the end of copiedKeys and save it as copiedKeys.Add Record ID to the end of copiedKeys and save it as copiedKeys.tableName. Save it as lookup.List rows from tableName. Save it as lookup.records to lookup.rows.Set records to lookup.rows.addedCount to 0.Set addedCount to 0.record in records:For each record in records:idValue to record.id.Set idValue to record.id.idValue is emptyIf idValue is emptySkipped a record with no 'id' column - nothing to identify it by..Show in the output: Skipped a record with no 'id' column - nothing to identify it by..recordKey to idValue.Set recordKey to idValue.recordKey is emptyIf recordKey is emptySkipped a record whose 'id' is empty..Show in the output: Skipped a record whose 'id' is empty..copiedKeys contains recordKeyIf copiedKeys contains recordKeycreatedAt to blank.Set createdAt to blank.record.created_at isn't emptyIf record.created_at isn't emptycreatedAt to record.created_at.Change createdAt to record.created_at.recordName to blank.Set recordName to blank.record.name isn't emptyIf record.name isn't emptyrecordName to record.name.Change recordName to record.name.recordEmail to blank.Set recordEmail to blank.record.email isn't emptyIf record.email isn't emptyrecordEmail to record.email.Change recordEmail to record.email.appendErrorIf a step below fails, save the error as appendErrorsheetName in spreadsheetUrl.Add a row to sheetName in spreadsheetUrl.recordKey to the end of copiedKeys and save it as copiedKeys.Add recordKey to the end of copiedKeys and save it as copiedKeys.addedCount.Add 1 to addedCount.recordKey: appendError as text.Show in the output: Could not copy record recordKey: appendError as text.addedCount as text new record(s) into the spreadsheet.Show in the output: Copied addedCount as text new record(s) into the spreadsheet.