-- =============================================
-- Business Pages Table Migration Script
-- 学业邑规划 - MiAssessment
-- 
-- This script creates the business_pages table
-- for managing business introduction pages
--
-- Database: SQL Server 2022
-- =============================================

USE [MiAssessment_Business];
GO

-- =============================================
-- Create Business Pages Table (业务介绍页表)
-- =============================================
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[business_pages]') AND type in (N'U'))
BEGIN
    CREATE TABLE [dbo].[business_pages] (
        [Id] BIGINT IDENTITY(1,1) NOT NULL,
        [Title] NVARCHAR(100) NOT NULL,                -- 标题
        [ImageUrl] NVARCHAR(500) NOT NULL,             -- 图片URL（长图）
        [HasActionButton] BIT NOT NULL DEFAULT 0,      -- 是否有操作按钮
        [ActionButtonText] NVARCHAR(50) NULL,          -- 操作按钮文字
        [ActionButtonLink] NVARCHAR(500) NULL,         -- 操作按钮链接
        [Sort] INT NOT NULL DEFAULT 0,                 -- 排序
        [Status] INT NOT NULL DEFAULT 1,               -- 状态：0禁用 1启用
        [CreateTime] DATETIME2 NOT NULL DEFAULT GETDATE(),
        [UpdateTime] DATETIME2 NOT NULL DEFAULT GETDATE(),
        [IsDeleted] BIT NOT NULL DEFAULT 0,
        CONSTRAINT [PK_business_pages] PRIMARY KEY CLUSTERED ([Id] ASC)
    );
    
    -- 创建状态索引
    CREATE NONCLUSTERED INDEX [IX_business_pages_status] ON [dbo].[business_pages] ([Status] ASC);
    
    PRINT N'Table business_pages created successfully';
END
ELSE
BEGIN
    PRINT N'Table business_pages already exists';
END
GO
