38 lines
1.2 KiB
SQL
38 lines
1.2 KiB
SQL
-- Get all tables
|
|
SELECT table_name FROM information_schema.tables
|
|
WHERE table_schema = 'public' AND table_type = 'BASE TABLE'
|
|
ORDER BY table_name;
|
|
|
|
-- Get columns for key tables
|
|
\echo '\n=== PRODUCTS TABLE ==='
|
|
SELECT column_name, data_type, is_nullable, column_default
|
|
FROM information_schema.columns
|
|
WHERE table_name = 'products'
|
|
ORDER BY ordinal_position;
|
|
|
|
\echo '\n=== PRODUCT_IMAGES TABLE ==='
|
|
SELECT column_name, data_type, is_nullable, column_default
|
|
FROM information_schema.columns
|
|
WHERE table_name = 'product_images'
|
|
ORDER BY ordinal_position;
|
|
|
|
\echo '\n=== UPLOADS TABLE ==='
|
|
SELECT column_name, data_type, is_nullable, column_default
|
|
FROM information_schema.columns
|
|
WHERE table_name = 'uploads'
|
|
ORDER BY ordinal_position;
|
|
|
|
\echo '\n=== FOREIGN KEYS ==='
|
|
SELECT
|
|
tc.table_name,
|
|
kcu.column_name,
|
|
ccu.table_name AS foreign_table_name,
|
|
ccu.column_name AS foreign_column_name
|
|
FROM information_schema.table_constraints AS tc
|
|
JOIN information_schema.key_column_usage AS kcu
|
|
ON tc.constraint_name = kcu.constraint_name
|
|
JOIN information_schema.constraint_column_usage AS ccu
|
|
ON ccu.constraint_name = tc.constraint_name
|
|
WHERE tc.constraint_type = 'FOREIGN KEY'
|
|
ORDER BY tc.table_name, kcu.column_name;
|