1

My problem is relatively simple as I try to make a migration with the help of the Flyway CLI.

The problem here is, that the system orders the migration files in the wrong order and my new file isn't viewed as the newest version. The files have the same version as the POM so we know in which version which changes came.

The current version is 1.4.11 but it's viewed as an older version.

V1_4_11.001 should be newer than V1_4_7.001

Why is that and how can I fix it without using the outOfOrder flag? The exact same files are in the right order on my MacBook.

-rw-r--r-- 1 501 staff  226 Oct 18 16:02 V1_1_0__patch.sql  
-rw-r--r-- 1 501 staff 3174 Oct 18 16:02 V1_2_0__patch.sql  
-rw-r--r-- 1 501 staff 1774 Oct 18 16:02 V1_2_2__patch.sql  
-rw-r--r-- 1 501 staff  130 Oct 18 16:02 V1_4_0.001__merge_skill_level_godlike.sql  
-rw-r--r-- 1 501 staff  111 Oct 18 16:02 V1_4_0.002__modify_publications.sql  
-rw-r--r-- 1 501 staff 2149 Oct 18 16:02 V1_4_0.003__create_v_competence_by_experience.sql  
-rw-r--r-- 1 501 staff   55 Oct 18 16:02 V1_4_11.001__add_profile_updated_on.sql  // Newest version
-rw-r--r-- 1 501 staff  712 Oct 18 16:02 V1_4_7.001__add_duration.sql
AdminBee
  • 22,803
Akagitsune
  • 21
  • 4

1 Answers1

1

The problem is that ls sorts its output according to a "lexicographical" sort order of the filenames. In that order, V1_4_11 comes after V1_4_1 and before V1_4_2 etc.

Since you are using Debian, there is a flag -v to ls that should do what you want:

-v natural sort of (version) numbers within text

E.g. if I create empty text files based on your example, the "normal" output order is:

myuser@myhost:~$ ls -l
-rw-r--r-- 1 myuser mygroup 0 Okt 19 00:47 V1_1_0__patch.sql  
-rw-r--r-- 1 myuser mygroup 0 Okt 19 00:47 V1_2_0__patch.sql  
-rw-r--r-- 1 myuser mygroup 0 Okt 19 00:47 V1_2_2__patch.sql  
-rw-r--r-- 1 myuser mygroup 0 Okt 19 00:47 V1_4_0.001__merge_skill_level_godlike.sql  
-rw-r--r-- 1 myuser mygroup 0 Okt 19 00:47 V1_4_0.002__modify_publications.sql  
-rw-r--r-- 1 myuser mygroup 0 Okt 19 00:47 V1_4_0.003__create_v_competence_by_experience.sql  
-rw-r--r-- 1 myuser mygroup 0 Okt 19 00:47 V1_4_11.001__add_profile_updated_on.sql
-rw-r--r-- 1 myuser mygroup 0 Okt 19 00:47 V1_4_7.001__add_duration.sql

If I use the -v flag, it gets:

myuser@myhost:~$ ls -lv
-rw-r--r-- 1 myuser mygroup 0 Okt 19 00:47 V1_1_0__patch.sql  
-rw-r--r-- 1 myuser mygroup 0 Okt 19 00:47 V1_2_0__patch.sql  
-rw-r--r-- 1 myuser mygroup 0 Okt 19 00:47 V1_2_2__patch.sql  
-rw-r--r-- 1 myuser mygroup 0 Okt 19 00:47 V1_4_0.001__merge_skill_level_godlike.sql  
-rw-r--r-- 1 myuser mygroup 0 Okt 19 00:47 V1_4_0.002__modify_publications.sql  
-rw-r--r-- 1 myuser mygroup 0 Okt 19 00:47 V1_4_0.003__create_v_competence_by_experience.sql  
-rw-r--r-- 1 myuser mygroup 0 Okt 19 00:47 V1_4_7.001__add_duration.sql
-rw-r--r-- 1 myuser mygroup 0 Okt 19 00:47 V1_4_11.001__add_profile_updated_on.sql

However, please note that this is really only the order in which the ls command outputs the files; it has nothing to do with how the files are internally organized on the file system. Also, you should not try to parse the output of ls in order to identify the latest file; if that is the ultimate goal, there are other ways to do this (but it would depend on which shell you are using and what exactly it is you want to do).

AdminBee
  • 22,803