mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 17:28:53 +00:00
Added some modules + Experimental SQL auto-migration stuff
This commit is contained in:
@@ -15,3 +15,4 @@ OnESX = function(cb)
|
||||
|
||||
end
|
||||
|
||||
exports('OnESX', OnESX)
|
||||
+48
-43
@@ -1,49 +1,54 @@
|
||||
CREATE DATABASE IF NOT EXISTS `es_extended`;
|
||||
CREATE DATABASE IF NOT EXISTS `es_extended`
|
||||
USE `es_extended`;
|
||||
|
||||
CREATE TABLE `users` (
|
||||
`identifier` VARCHAR(40) NOT NULL,
|
||||
`accounts` LONGTEXT NULL DEFAULT NULL,
|
||||
`group` VARCHAR(50) NULL DEFAULT 'user',
|
||||
`inventory` LONGTEXT NULL DEFAULT NULL,
|
||||
`job` VARCHAR(20) NULL DEFAULT 'unemployed',
|
||||
`job_grade` INT(11) NULL DEFAULT 0,
|
||||
`loadout` LONGTEXT NULL DEFAULT NULL,
|
||||
`position` VARCHAR(53) NULL DEFAULT '{"x":-269.4,"y":-955.3,"z":31.2,"heading":205.8}',
|
||||
CREATE TABLE IF NOT EXISTS `migrations` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`module` varchar(50) NOT NULL,
|
||||
`last` int(11) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
PRIMARY KEY (`identifier`)
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS `items` (
|
||||
`name` varchar(50) NOT NULL,
|
||||
`label` varchar(50) NOT NULL,
|
||||
`weight` int(11) NOT NULL DEFAULT 1,
|
||||
`rare` tinyint(1) NOT NULL DEFAULT 0,
|
||||
`can_remove` tinyint(1) NOT NULL DEFAULT 1,
|
||||
PRIMARY KEY (`name`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE `items` (
|
||||
`name` VARCHAR(50) NOT NULL,
|
||||
`label` VARCHAR(50) NOT NULL,
|
||||
`weight` INT(11) NOT NULL DEFAULT 1,
|
||||
`rare` TINYINT(1) NOT NULL DEFAULT 0,
|
||||
`can_remove` TINYINT(1) NOT NULL DEFAULT 1,
|
||||
CREATE TABLE IF NOT EXISTS `jobs` (
|
||||
`name` varchar(50) NOT NULL,
|
||||
`label` varchar(50) DEFAULT NULL,
|
||||
PRIMARY KEY (`name`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
PRIMARY KEY (`name`)
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS `job_grades` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`job_name` varchar(50) DEFAULT NULL,
|
||||
`grade` int(11) NOT NULL,
|
||||
`name` varchar(50) NOT NULL,
|
||||
`label` varchar(50) NOT NULL,
|
||||
`salary` int(11) NOT NULL,
|
||||
`skin_male` longtext NOT NULL,
|
||||
`skin_female` longtext NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE `job_grades` (
|
||||
`id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`job_name` VARCHAR(50) DEFAULT NULL,
|
||||
`grade` INT(11) NOT NULL,
|
||||
`name` VARCHAR(50) NOT NULL,
|
||||
`label` VARCHAR(50) NOT NULL,
|
||||
`salary` INT(11) NOT NULL,
|
||||
`skin_male` LONGTEXT NOT NULL,
|
||||
`skin_female` LONGTEXT NOT NULL,
|
||||
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
|
||||
INSERT INTO `job_grades` VALUES (1,'unemployed',0,'unemployed','Unemployed',200,'{}','{}');
|
||||
|
||||
CREATE TABLE `jobs` (
|
||||
`name` VARCHAR(50) NOT NULL,
|
||||
`label` VARCHAR(50) DEFAULT NULL,
|
||||
|
||||
PRIMARY KEY (`name`)
|
||||
);
|
||||
|
||||
INSERT INTO `jobs` VALUES ('unemployed','Unemployed');
|
||||
CREATE TABLE IF NOT EXISTS `users` (
|
||||
`identifier` varchar(40) NOT NULL,
|
||||
`accounts` longtext DEFAULT NULL,
|
||||
`group` varchar(50) DEFAULT 'user',
|
||||
`inventory` longtext DEFAULT NULL,
|
||||
`job` varchar(20) DEFAULT 'unemployed',
|
||||
`job_grade` int(11) DEFAULT 0,
|
||||
`loadout` longtext DEFAULT NULL,
|
||||
`position` varchar(53) DEFAULT '{"x":-269.4,"y":-955.3,"z":31.2,"heading":205.8}',
|
||||
`skin` longtext DEFAULT NULL,
|
||||
`phone_number` int(11) DEFAULT NULL,
|
||||
`name` varchar(255) DEFAULT NULL,
|
||||
`status` longtext DEFAULT NULL,
|
||||
`is_dead` tinyint(1) DEFAULT 0,
|
||||
PRIMARY KEY (`identifier`),
|
||||
UNIQUE KEY `index_users_phone_number` (`phone_number`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
+21
-8
@@ -34,7 +34,9 @@ server_scripts {
|
||||
|
||||
'common/modules/math.lua',
|
||||
'common/modules/table.lua',
|
||||
'common/functions.lua'
|
||||
'common/functions.lua',
|
||||
|
||||
'common/bootstrap.lua',
|
||||
}
|
||||
|
||||
client_scripts {
|
||||
@@ -66,6 +68,8 @@ client_scripts {
|
||||
'common/modules/math.lua',
|
||||
'common/modules/table.lua',
|
||||
'common/functions.lua',
|
||||
|
||||
'common/bootstrap.lua',
|
||||
}
|
||||
|
||||
ui_page {
|
||||
@@ -108,11 +112,20 @@ esxmodule = function(name)
|
||||
|
||||
end
|
||||
|
||||
esxmodule 'input'
|
||||
esxmodule 'hud'
|
||||
esxmodule 'menu_default'
|
||||
esxmodule 'menu_dialog'
|
||||
esxmodule 'menu_list'
|
||||
esxmodule 'interact'
|
||||
-- Misc
|
||||
esxmodule 'input' -- Evented input manager
|
||||
esxmodule 'interact' -- Interact menu (marker / npc)
|
||||
|
||||
esxmodule 'job_police'
|
||||
-- Extend
|
||||
esxmodule 'addonaccount' -- Addon account
|
||||
esxmodule 'addoninventory' -- Addon inventory
|
||||
esxmodule 'datastore' -- Arbitrary data store
|
||||
|
||||
-- UI
|
||||
esxmodule 'hud' -- Money / society etc... HUD
|
||||
esxmodule 'menu_default' -- Default menu
|
||||
esxmodule 'menu_dialog' -- Dialog menu
|
||||
esxmodule 'menu_list' -- List menu
|
||||
|
||||
-- Jobs
|
||||
esxmodule 'job_police' -- Job police
|
||||
|
||||
Submodule
+1
Submodule modules/addonaccount added at 9e6b9b2824
Submodule
+1
Submodule modules/addoninventory added at c339d44214
@@ -0,0 +1,3 @@
|
||||
ESX.Modules['container'] = {}
|
||||
local self = ESX.Modules['container']
|
||||
|
||||
Submodule
+1
Submodule modules/datastore added at 88fd62fe7c
@@ -6,7 +6,7 @@ Config.MarkerSize = {x = 1.5, y = 1.5, z = 0.5}
|
||||
Config.MarkerColor = {r = 50, g = 50, b = 204, a = 100}
|
||||
|
||||
Config.EnablePlayerManagement = false
|
||||
Config.EnableArmoryManagement = false
|
||||
Config.EnableArmoryManagement = true
|
||||
Config.EnableESXIdentity = false -- enable if you're using esx_identity
|
||||
Config.EnableLicenses = false -- enable if you're using esx_license
|
||||
|
||||
|
||||
@@ -1,3 +1,70 @@
|
||||
ESX.EnsureMigrations = function(module)
|
||||
|
||||
print('[esx] migrate => ' .. module)
|
||||
|
||||
local dir
|
||||
|
||||
if module == 'base' then
|
||||
dir = 'migrations'
|
||||
else
|
||||
dir = 'modules/' .. module .. '/migrations'
|
||||
end
|
||||
|
||||
local result = MySQL.Sync.fetchAll('SELECT * FROM `migrations` WHERE `module` = @module', {['@module'] = module})
|
||||
local initial = true
|
||||
local i = 0
|
||||
local hasmigrated = false
|
||||
|
||||
if #result > 0 then
|
||||
i = result[1].last + 1
|
||||
initial = false
|
||||
end
|
||||
|
||||
local sql = nil
|
||||
|
||||
repeat
|
||||
|
||||
sql = LoadResourceFile(GetCurrentResourceName(), dir .. '/' .. i .. '.sql')
|
||||
|
||||
if sql ~= nil then
|
||||
|
||||
print('[esx] [' .. module .. '] => running migration #' .. i)
|
||||
|
||||
MySQL.Sync.execute(sql)
|
||||
|
||||
if initial then
|
||||
MySQL.Sync.execute('INSERT INTO `migrations` (module, last) VALUES (@module, @last)', {['@module'] = module, ['@last'] = 0})
|
||||
else
|
||||
MySQL.Sync.execute('UPDATE `migrations` SET `last` = @last WHERE `module` = @module', {['@module'] = module, ['@last'] = i})
|
||||
end
|
||||
|
||||
hasmigrated = true
|
||||
|
||||
end
|
||||
|
||||
i = i + 1
|
||||
|
||||
until sql == nil
|
||||
|
||||
if not hasmigrated then
|
||||
print('[esx] [' .. module .. '] => no pending migration')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
ESX.FileExists = function(name)
|
||||
|
||||
local f=io.open(name, 'r')
|
||||
|
||||
if f~=nil then
|
||||
io.close(f)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
ESX.Trace = function(msg)
|
||||
if Config.EnableDebug then
|
||||
print(('[es_extended] [^2TRACE^7] %s^7'):format(msg))
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
MySQL.ready(function()
|
||||
|
||||
print('[esx] ensuring migrations')
|
||||
|
||||
TriggerEvent('esx:migrations:ensure', function(module)
|
||||
ESX.EnsureMigrations(module)
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
AddEventHandler('esx:migrations:ensure', function(register)
|
||||
register('base')
|
||||
end)
|
||||
|
||||
RegisterNetEvent('esx:onPlayerJoined')
|
||||
AddEventHandler('esx:onPlayerJoined', function()
|
||||
if not ESX.Players[source] then
|
||||
|
||||
Reference in New Issue
Block a user