mirror of
https://github.com/marcogll/AnchorOS.git
synced 2026-03-15 13:24:27 +00:00
feat: Add kiosk setup and API testing scripts, alongside database function fixes for API key generation and short IDs.
This commit is contained in:
26
scripts/fix-short-id.sql
Normal file
26
scripts/fix-short-id.sql
Normal file
@@ -0,0 +1,26 @@
|
||||
-- Fix short_id variable name collision
|
||||
CREATE OR REPLACE FUNCTION generate_short_id()
|
||||
RETURNS VARCHAR(6) AS $$
|
||||
DECLARE
|
||||
chars VARCHAR(36) := '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
v_short_id VARCHAR(6);
|
||||
attempts INT := 0;
|
||||
max_attempts INT := 10;
|
||||
BEGIN
|
||||
LOOP
|
||||
v_short_id := '';
|
||||
FOR i IN 1..6 LOOP
|
||||
v_short_id := v_short_id || substr(chars, floor(random() * 36 + 1)::INT, 1);
|
||||
END LOOP;
|
||||
|
||||
IF NOT EXISTS (SELECT 1 FROM bookings WHERE short_id = v_short_id) THEN
|
||||
RETURN v_short_id;
|
||||
END IF;
|
||||
|
||||
attempts := attempts + 1;
|
||||
IF attempts >= max_attempts THEN
|
||||
RAISE EXCEPTION 'Failed to generate unique short_id after % attempts', max_attempts;
|
||||
END IF;
|
||||
END LOOP;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql SECURITY DEFINER;
|
||||
Reference in New Issue
Block a user