Skip to content

Commit 1e3adf9

Browse files
Add sort_index field for palette ordering
- Add sort_index column to palettes table in schema - Update remote.ts to transform index <-> sort_index - Update palettes_with_colors view to include sort_index
1 parent ac44d64 commit 1e3adf9

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

app/data-sources/remote.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ interface SupabasePalette {
2929
is_favorite: boolean;
3030
is_locked: boolean;
3131
selected_color_index: number;
32+
sort_index: number;
3233
color_order: { type: string; id: string }[];
3334
}
3435

@@ -396,6 +397,7 @@ export class SupabaseSource extends Source {
396397
isFavorite: palette.is_favorite,
397398
isLocked: palette.is_locked,
398399
selectedColorIndex: palette.selected_color_index,
400+
index: palette.sort_index,
399401
colorOrder: palette.color_order ?? [],
400402
},
401403
relationships: {
@@ -449,6 +451,7 @@ export class SupabaseSource extends Source {
449451
is_favorite: attrs['isFavorite'] ?? false,
450452
is_locked: attrs['isLocked'] ?? false,
451453
selected_color_index: attrs['selectedColorIndex'] ?? 0,
454+
sort_index: attrs['index'] ?? 0,
452455
color_order: attrs['colorOrder'] ?? [],
453456
};
454457
} else if (record.type === 'color') {

supabase-schema.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ CREATE TABLE IF NOT EXISTS palettes (
1818
is_favorite BOOLEAN DEFAULT FALSE,
1919
is_locked BOOLEAN DEFAULT FALSE,
2020
selected_color_index INTEGER DEFAULT 0,
21+
sort_index INTEGER DEFAULT 0,
2122
color_order JSONB DEFAULT '[]'::jsonb,
2223

2324
-- Constraints
@@ -202,7 +203,7 @@ FROM palettes p
202203
LEFT JOIN colors c ON c.palette_id = p.id
203204
WHERE p.user_id = auth.uid()
204205
GROUP BY p.id, p.user_id, p.name, p.is_color_history, p.is_favorite, p.is_locked,
205-
p.selected_color_index, p.color_order, p.created_at, p.updated_at;
206+
p.selected_color_index, p.sort_index, p.color_order, p.created_at, p.updated_at;
206207

207208
-- ============================================
208209
-- Migration Helper Functions
@@ -219,14 +220,15 @@ DECLARE
219220
palette_uuid UUID;
220221
BEGIN
221222
-- Insert palette
222-
INSERT INTO palettes (user_id, name, is_color_history, is_favorite, is_locked, selected_color_index, color_order)
223+
INSERT INTO palettes (user_id, name, is_color_history, is_favorite, is_locked, selected_color_index, sort_index, color_order)
223224
VALUES (
224225
user_uuid,
225226
palette_data->>'name',
226227
(palette_data->>'isColorHistory')::BOOLEAN,
227228
(palette_data->>'isFavorite')::BOOLEAN,
228229
(palette_data->>'isLocked')::BOOLEAN,
229230
COALESCE((palette_data->>'selectedColorIndex')::INTEGER, 0),
231+
COALESCE((palette_data->>'sortIndex')::INTEGER, 0),
230232
COALESCE(palette_data->>'colorOrder', '[]'::jsonb)
231233
)
232234
RETURNING id INTO palette_uuid;

0 commit comments

Comments
 (0)