<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
  xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
                      http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">

  <changeSet author="author" id="changelog-3.2">

    <preConditions onFail="MARK_RAN">
      <not>
        <columnExists tableName="position" columnName="attributes" />
      </not>
    </preConditions>

    <dropDefaultValue tableName="user" columnName="latitude" />
    <dropNotNullConstraint tableName="user" columnName="latitude" columnDataType="FLOAT" />
    <modifyDataType tableName="user" columnName="latitude" newDataType="DOUBLE" />
    <addNotNullConstraint tableName="user" columnName="latitude" columnDataType="DOUBLE" />
    <addDefaultValue tableName="user" columnName="latitude" defaultValueNumeric="0" />
    <dropDefaultValue tableName="user" columnName="longitude" />
    <dropNotNullConstraint tableName="user" columnName="longitude" columnDataType="FLOAT" />
    <modifyDataType tableName="user" columnName="longitude" newDataType="DOUBLE" />
    <addNotNullConstraint tableName="user" columnName="longitude" columnDataType="DOUBLE" />
    <addDefaultValue tableName="user" columnName="longitude" defaultValueNumeric="0" />

    <dropColumn tableName="device" columnName="dataId" />

    <dropNotNullConstraint tableName="position" columnName="latitude" columnDataType="FLOAT" />
    <modifyDataType tableName="position" columnName="latitude" newDataType="DOUBLE" />
    <addNotNullConstraint tableName="position" columnName="latitude" columnDataType="DOUBLE" />
    <dropNotNullConstraint tableName="position" columnName="longitude" columnDataType="FLOAT" />
    <modifyDataType tableName="position" columnName="longitude" newDataType="DOUBLE" />
    <addNotNullConstraint tableName="position" columnName="longitude" columnDataType="DOUBLE" />
    <dropNotNullConstraint tableName="position" columnName="other" columnDataType="VARCHAR(4096)" />
    <renameColumn tableName="position" oldColumnName="other" newColumnName="attributes" columnDataType="VARCHAR(4096)" />
    <addNotNullConstraint tableName="position" columnName="attributes" columnDataType="VARCHAR(4096)" />

    <dropTable tableName="data" />

    <addColumn tableName="server">
      <column name="bingKey" type="VARCHAR(128)" />
    </addColumn>
    <addColumn tableName="server">
      <column name="mapUrl" type="VARCHAR(128)" />
    </addColumn>
    <dropDefaultValue tableName="server" columnName="latitude" />
    <dropNotNullConstraint tableName="server" columnName="latitude" columnDataType="FLOAT" />
    <modifyDataType tableName="server" columnName="latitude" newDataType="DOUBLE" />
    <addNotNullConstraint tableName="server" columnName="latitude" columnDataType="DOUBLE" />
    <addDefaultValue tableName="server" columnName="latitude" defaultValueNumeric="0" />
    <dropDefaultValue tableName="server" columnName="longitude" />
    <dropNotNullConstraint tableName="server" columnName="longitude" columnDataType="FLOAT" />
    <modifyDataType tableName="server" columnName="longitude" newDataType="DOUBLE" />
    <addNotNullConstraint tableName="server" columnName="longitude" columnDataType="DOUBLE" />
    <addDefaultValue tableName="server" columnName="longitude" defaultValueNumeric="0" />

    <update tableName="traccar">
      <column name="version" valueNumeric="302" />
    </update>

  </changeSet>
</databaseChangeLog>