text stringlengths 0 59.1k |
|---|
``` |
### Set up the database |
First, set up your Supabase database: |
1. Create a Supabase account at [supabase.com](https://supabase.com) |
2. Create a new project in your Supabase dashboard |
3. Once your project is ready, navigate to the **SQL Editor** from the sidebar |
4. Run the following SQL commands to create the necessary tables for your ordering system: |
For detailed Supabase setup instructions, see the [official Supabase documentation](https://supabase.com/docs/guides/getting-started). |
 |
### Menu Items Table |
```sql |
CREATE TABLE public.menu_items ( |
id SERIAL PRIMARY KEY, |
category VARCHAR(50) NOT NULL, |
name VARCHAR(100) NOT NULL, |
description TEXT, |
price NUMERIC(10, 2) NOT NULL, |
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
); |
CREATE INDEX idx_menu_items_category ON public.menu_items(category); |
``` |
### Orders Table |
```sql |
CREATE TABLE public.orders ( |
id SERIAL PRIMARY KEY, |
customer_phone VARCHAR(20) NOT NULL, |
customer_address TEXT NOT NULL, |
total_amount NUMERIC(10, 2) NOT NULL, |
status VARCHAR(20) NOT NULL DEFAULT 'preparing', |
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
); |
CREATE INDEX idx_orders_status ON public.orders(status); |
``` |
### Order Items Table |
```sql |
CREATE TABLE public.order_items ( |
id SERIAL PRIMARY KEY, |
order_id INTEGER REFERENCES orders(id) ON DELETE CASCADE, |
menu_item_id INTEGER REFERENCES menu_items(id) ON DELETE CASCADE, |
quantity INTEGER NOT NULL DEFAULT 1, |
price NUMERIC(10, 2) NOT NULL, |
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
); |
CREATE INDEX idx_order_items_order_id ON public.order_items(order_id); |
CREATE INDEX idx_order_items_menu_item_id ON public.order_items(menu_item_id); |
``` |
### Sample Menu Data |
```sql |
INSERT INTO menu_items (category, name, description, price) VALUES |
('Pizza', 'Margherita', 'Fresh tomatoes, mozzarella, basil', 12.99), |
('Pizza', 'Pepperoni', 'Pepperoni, mozzarella, tomato sauce', 14.99), |
('Burger', 'Classic Burger', 'Beef patty, lettuce, tomato, onion', 10.99), |
('Burger', 'Cheeseburger', 'Beef patty, cheese, lettuce, tomato', 11.99), |
('Drinks', 'Coke', 'Coca-Cola 330ml', 2.99), |
('Drinks', 'Water', 'Mineral water 500ml', 1.99); |
``` |
#### Supabase Client Configuration |
The example already includes a `lib/supabase.ts` file that initializes the Supabase client: |
```typescript |
import { createClient } from "@supabase/supabase-js"; |
// Supabase configuration - add these to your .env file |
const supabaseUrl = process.env.SUPABASE_URL || ""; |
const supabaseAnonKey = process.env.SUPABASE_ANON_KEY || ""; |
export const supabase = createClient(supabaseUrl, supabaseAnonKey); |
``` |
This file provides a Supabase client instance that all the tools use to interact with the database. Make sure your environment variables are properly set in the `.env` file. |
#### Start the development server |
```bash |
npm run dev |
``` |
Once your server starts successfully, you see: |
```bash |
════════════════════════════════════════════ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.