<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
    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-latest.xsd
                        http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">

    <!--
        Atered the entity EmissionFactor.
        * Data type change for column value, from  decimal(21,2) to decimal(21,4)
        * Add mandatory column: year
    -->
    <changeSet id="20241128171125-1" author="omg">
    	<modifyDataType tableName="emission_factor" columnName="value" newDataType="decimal(21,4)" />
    </changeSet>
    
    <changeSet id="20241128171125-2" author="omg">
	    <addColumn tableName="emission_factor">
	        <column name="year" type="int" afterColumn="code">
	        	<constraints nullable="false" />
	        </column>
	    </addColumn>
    </changeSet>
    
    <changeSet id="20241128171125-3" author="omg">
		<dropUniqueConstraint 
	        tableName="emission_factor"
	        constraintName="ux_emission_factor__code"/>
    </changeSet>
    
    <changeSet id="20241128171125-4" author="omg">
		<addUniqueConstraint 
        	tableName="emission_factor" 
        	columnNames="year,code"
        	constraintName="ux_emission_factor__year__code"/>
    </changeSet>
</databaseChangeLog>
