Fix upgrade script when maps are present

The creation of the NOT NULL index column
failed the upgrade script for databases
with any maps present. By using the window
function `row_number` we can set the ordered
list according to the alphanumerical sorting
of the key.