-- 验证order_main表是否创建成功

-- 1. 查看表结构
\d order_main;

-- 2. 查看表注释
SELECT 
    obj_description('order_main'::regclass) AS table_comment;

-- 3. 查看字段注释（使用pg_catalog.pg_description）
SELECT 
    a.attname AS column_name,
    d.description AS column_comment
FROM pg_attribute a
LEFT JOIN pg_catalog.pg_description d 
    ON d.objoid = a.attrelid 
    AND d.objsubid = a.attnum
WHERE a.attrelid = 'order_main'::regclass 
    AND a.attnum > 0 
    AND NOT a.attisdropped
ORDER BY a.attnum;

-- 4. 查看索引
SELECT 
    indexname AS index_name,
    indexdef AS index_definition
FROM pg_indexes 
WHERE tablename = 'order_main';

-- 5. 查看迁移历史
SELECT * FROM __MigrationsHistory 
WHERE MigrationId = '202512301200add_table_order_main';

-- 6. 查看表的所有约束
SELECT 
    conname AS constraint_name,
    contype AS constraint_type
FROM pg_constraint 
WHERE conrelid = 'order_main'::regclass;

-- 7. 查看序列
SELECT 
    sequencename AS sequence_name,
    last_value,
    start_value,
    increment_by
FROM pg_sequences 
WHERE sequencename = 'order_main_id_seq';

-- 8. 统计表记录数
SELECT COUNT(*) AS record_count FROM order_main;
