|
|
@@ -95,7 +95,6 @@ serve(wrapHandler('trigger-sync', async (req) => {
|
|
|
.from('stores')
|
|
|
.update({
|
|
|
sync_status: 'error',
|
|
|
- sync_completed_at: new Date().toISOString(),
|
|
|
sync_error: `Unsupported platform: ${store.platform_name}`
|
|
|
})
|
|
|
.eq('id', store_id)
|
|
|
@@ -145,12 +144,11 @@ serve(wrapHandler('trigger-sync', async (req) => {
|
|
|
const altData = currentStore?.alt_data || {}
|
|
|
const syncCompletedAt = new Date().toISOString()
|
|
|
|
|
|
- // Update stores table (for Web UI display)
|
|
|
+ // Update stores table (runtime status only, preserve alt_data)
|
|
|
await supabaseAdmin
|
|
|
.from('stores')
|
|
|
.update({
|
|
|
sync_status: 'completed',
|
|
|
- sync_completed_at: syncCompletedAt,
|
|
|
alt_data: {
|
|
|
...altData,
|
|
|
last_sync_at: syncCompletedAt,
|
|
|
@@ -161,7 +159,7 @@ serve(wrapHandler('trigger-sync', async (req) => {
|
|
|
})
|
|
|
.eq('id', store_id)
|
|
|
|
|
|
- // Update store_sync_config timestamps (for scheduling logic)
|
|
|
+ // Update store_sync_config (single source of truth for sync timing)
|
|
|
const { error: configUpdateError } = await supabaseAdmin
|
|
|
.from('store_sync_config')
|
|
|
.update({
|
|
|
@@ -187,12 +185,11 @@ serve(wrapHandler('trigger-sync', async (req) => {
|
|
|
.from('stores')
|
|
|
.update({
|
|
|
sync_status: 'error',
|
|
|
- sync_completed_at: errorTime,
|
|
|
sync_error: result.error || 'Unknown error during sync'
|
|
|
})
|
|
|
.eq('id', store_id)
|
|
|
|
|
|
- // Still update store_sync_config timestamp even on error (for retry logic)
|
|
|
+ // Update store_sync_config timestamp even on error (for retry logic)
|
|
|
await supabaseAdmin
|
|
|
.from('store_sync_config')
|
|
|
.update({
|
|
|
@@ -208,12 +205,11 @@ serve(wrapHandler('trigger-sync', async (req) => {
|
|
|
.from('stores')
|
|
|
.update({
|
|
|
sync_status: 'error',
|
|
|
- sync_completed_at: errorTime,
|
|
|
sync_error: error.message || 'Unknown error during sync'
|
|
|
})
|
|
|
.eq('id', store_id)
|
|
|
|
|
|
- // Still update store_sync_config timestamp even on error (for retry logic)
|
|
|
+ // Update store_sync_config timestamp even on error (for retry logic)
|
|
|
await supabaseAdmin
|
|
|
.from('store_sync_config')
|
|
|
.update({
|