30 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			30 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
local function EnsureRoofboxesTableExists()
 | 
						|
    local query = [[
 | 
						|
        SELECT COUNT(*) as count
 | 
						|
        FROM information_schema.tables
 | 
						|
        WHERE table_name = 'kq_roofboxes'
 | 
						|
    ]]
 | 
						|
    
 | 
						|
    local result = DB.SqlQuery(query)
 | 
						|
    if result and result[1] and result[1].count == 0 then
 | 
						|
        -- Table does not exist, create it
 | 
						|
        local createQuery = [[
 | 
						|
            CREATE TABLE IF NOT EXISTS `kq_roofboxes` (
 | 
						|
              `id` int(11) NOT NULL AUTO_INCREMENT,
 | 
						|
              `identifier` varchar(46) DEFAULT NULL,
 | 
						|
              `data` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '{}' CHECK (json_valid(`data`)),
 | 
						|
              `created_at` datetime NOT NULL DEFAULT current_timestamp(),
 | 
						|
              PRIMARY KEY (`id`),
 | 
						|
              UNIQUE KEY `identifier` (`identifier`)
 | 
						|
            ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
 | 
						|
        ]]
 | 
						|
        
 | 
						|
        DB.SqlMutate(createQuery)
 | 
						|
        print("^2kq_roofboxes table created successfully.")
 | 
						|
    end
 | 
						|
end
 | 
						|
 | 
						|
Citizen.CreateThread(function()
 | 
						|
    -- Call the function to ensure the table exists
 | 
						|
    Citizen.SetTimeout(500, EnsureRoofboxesTableExists)
 | 
						|
end)
 |