package com.ruoyi.common.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class DatabaseInit {
    
    @Autowired
    private JdbcTemplate jdbcTemplate;
    
    @PostConstruct
    public void init() {
        try {
            String sql = "ALTER TABLE introduction ADD COLUMN title VARCHAR(200) NOT NULL COMMENT '标题' AFTER intro_id";
            jdbcTemplate.execute(sql);
            System.out.println("数据库字段添加成功：title");
        } catch (Exception e) {
            if (e.getMessage().contains("Duplicate column name")) {
                System.out.println("数据库字段已存在：title");
            } else {
                System.out.println("数据库字段添加失败：" + e.getMessage());
            }
        }
    }
}
