mirror of
https://github.com/DeNNiiInc/Connect-5.git
synced 2026-04-17 22:46:00 +00:00
Migrate database from MySQL to Supabase PostgreSQL
- Added @supabase/supabase-js client library - Rewrote database.js to use Supabase API - Updated server.js health check for Supabase - Updated db.config.example.js with Supabase format - Created comprehensive SUPABASE_SETUP.md guide - Added SQL schema files for easy deployment - Updated README_DB_CONFIG.md for Supabase Benefits: - Managed PostgreSQL database - Built-in Row Level Security - Real-time capabilities - Easy monitoring via dashboard - Free tier for development
This commit is contained in:
50
supabase-functions.sql
Normal file
50
supabase-functions.sql
Normal file
@@ -0,0 +1,50 @@
|
||||
-- Supabase SQL Helper Functions for Connect-5
|
||||
-- Run this in your Supabase SQL Editor after creating the tables
|
||||
|
||||
-- Function to increment wins
|
||||
CREATE OR REPLACE FUNCTION increment_wins(player_id BIGINT)
|
||||
RETURNS void AS $$
|
||||
BEGIN
|
||||
UPDATE players
|
||||
SET total_wins = total_wins + 1
|
||||
WHERE id = player_id;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
-- Function to increment losses
|
||||
CREATE OR REPLACE FUNCTION increment_losses(player_id BIGINT)
|
||||
RETURNS void AS $$
|
||||
BEGIN
|
||||
UPDATE players
|
||||
SET total_losses = total_losses + 1
|
||||
WHERE id = player_id;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
-- Function to increment draws
|
||||
CREATE OR REPLACE FUNCTION increment_draws(player_id BIGINT)
|
||||
RETURNS void AS $$
|
||||
BEGIN
|
||||
UPDATE players
|
||||
SET total_draws = total_draws + 1
|
||||
WHERE id = player_id;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
-- Optional: Function to get player stats
|
||||
CREATE OR REPLACE FUNCTION get_player_stats(player_username VARCHAR)
|
||||
RETURNS TABLE (
|
||||
id BIGINT,
|
||||
username VARCHAR,
|
||||
total_wins INT,
|
||||
total_losses INT,
|
||||
total_draws INT,
|
||||
created_at TIMESTAMP WITH TIME ZONE
|
||||
) AS $$
|
||||
BEGIN
|
||||
RETURN QUERY
|
||||
SELECT p.id, p.username, p.total_wins, p.total_losses, p.total_draws, p.created_at
|
||||
FROM players p
|
||||
WHERE p.username = player_username;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
Reference in New Issue
Block a user