Update from 3.0 to 3.1

Script for MySQL database migration:

ALTER TABLE `user`
MODIFY COLUMN name VARCHAR(128) NOT NULL,
MODIFY COLUMN email VARCHAR(128) NOT NULL,
MODIFY COLUMN hashedPassword VARCHAR(128) NOT NULL,
MODIFY COLUMN salt VARCHAR(128) DEFAULT '' NOT NULL,
MODIFY COLUMN readonly BIT DEFAULT 0 NOT NULL,
MODIFY COLUMN admin BIT DEFAULT 0 NOT NULL,
MODIFY COLUMN map VARCHAR(128),
MODIFY COLUMN language VARCHAR(128),
MODIFY COLUMN distanceUnit VARCHAR(128),
MODIFY COLUMN speedUnit VARCHAR(128),
MODIFY COLUMN latitude FLOAT DEFAULT 0 NOT NULL,
MODIFY COLUMN longitude FLOAT DEFAULT 0 NOT NULL;

ALTER TABLE device
MODIFY COLUMN name VARCHAR(128) NOT NULL,
MODIFY COLUMN uniqueId VARCHAR(128) NOT NULL,
MODIFY COLUMN status VARCHAR(128);

ALTER TABLE device DROP FOREIGN KEY device_ibfk_1;
ALTER TABLE device DROP FOREIGN KEY device_ibfk_2;
ALTER TABLE device ADD FOREIGN KEY (positionId) REFERENCES position (id) ON DELETE CASCADE;
ALTER TABLE device ADD FOREIGN KEY (dataId) REFERENCES data (id) ON DELETE CASCADE;

ALTER TABLE user_device
MODIFY COLUMN `read` BIT DEFAULT 1 NOT NULL,
MODIFY COLUMN `write` BIT DEFAULT 1 NOT NULL;

ALTER TABLE position
MODIFY COLUMN protocol VARCHAR(128),
MODIFY COLUMN valid BIT NOT NULL,
MODIFY COLUMN latitude FLOAT NOT NULL,
MODIFY COLUMN longitude FLOAT NOT NULL,
MODIFY COLUMN altitude FLOAT NOT NULL,
MODIFY COLUMN speed FLOAT NOT NULL,
MODIFY COLUMN course FLOAT NOT NULL,
MODIFY COLUMN address VARCHAR(512),
MODIFY COLUMN other VARCHAR(4096) NOT NULL;

CREATE INDEX position_deviceId_fixTime ON position (deviceId, fixTime);

ALTER TABLE data
MODIFY COLUMN protocol VARCHAR(128),
MODIFY COLUMN other VARCHAR(4096) NOT NULL;

ALTER TABLE data DROP FOREIGN KEY data_ibfk_1;
ALTER TABLE data ADD FOREIGN KEY (deviceId) REFERENCES device (id) ON DELETE CASCADE;

ALTER TABLE server
MODIFY COLUMN registration BIT NOT NULL,
ADD COLUMN map VARCHAR(128),
ADD COLUMN language VARCHAR(128),
ADD COLUMN distanceUnit VARCHAR(128),
ADD COLUMN speedUnit VARCHAR(128),
MODIFY COLUMN latitude FLOAT DEFAULT 0 NOT NULL,
MODIFY COLUMN longitude FLOAT DEFAULT 0 NOT NULL,
MODIFY COLUMN zoom INT DEFAULT 0 NOT NULL;

ALTER TABLE traccar
DROP COLUMN id,
ADD COLUMN version INT DEFAULT 0 NOT NULL;

INSERT INTO traccar (version) VALUES (301);