Skip to content

Commit 9301cdf

Browse files
fix: attempt to fix migration_dir path
Signed-off-by: Anatoli Nicolae <an@thundersquared.com> fix: look up one more level Signed-off-by: Anatoli Nicolae <an@thundersquared.com> fix: make sure dir exists, claude asked that Signed-off-by: Anatoli Nicolae <an@thundersquared.com> fix: delegate find to localhost Signed-off-by: Anatoli Nicolae <an@thundersquared.com> fix: change store behavior Signed-off-by: Anatoli Nicolae <an@thundersquared.com> fix: fail hard on duplicates, don’t ignore Signed-off-by: Anatoli Nicolae <an@thundersquared.com> refactor: improve reliability Signed-off-by: Anatoli Nicolae <an@thundersquared.com> refactor: improve reliability Signed-off-by: Anatoli Nicolae <an@thundersquared.com> fix: resolve reliabilty issues Signed-off-by: Anatoli Nicolae <an@thundersquared.com>
1 parent 8edf3ec commit 9301cdf

File tree

4 files changed

+156
-24
lines changed
  • mx1/ansible/roles/system/migrations/tasks
  • web1/ansible/roles/system/migrations/tasks
  • web2/ansible/roles/system/migrations/tasks
  • web3/ansible/roles/system/migrations/tasks

4 files changed

+156
-24
lines changed

mx1/ansible/roles/system/migrations/tasks/main.yml

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,53 @@
2424
set_fact:
2525
applied_migrations: "{{ applied_migrations_output.stdout_lines | select | list }}"
2626

27+
- name: Show applied migrations
28+
debug:
29+
msg: "Already applied migrations: {{ applied_migrations }}"
30+
verbosity: 1
31+
no_log: false
32+
2733
- name: Find migration files
2834
find:
2935
paths: "{{ migration_dir }}"
3036
patterns: "*.yml"
3137
recurse: no
38+
delegate_to: localhost
3239
register: migration_files
3340

41+
- name: Extract migration IDs from files
42+
set_fact:
43+
pending_migrations: |
44+
{{ migration_files.files | map(attribute='path') | map('basename') | map('regex_replace', '\.yml$', '') | reject('in', applied_migrations) | list }}
45+
46+
- name: Show pending migrations
47+
debug:
48+
msg: "Pending migrations to apply: {{ pending_migrations }}"
49+
verbosity: 1
50+
no_log: false
51+
3452
- name: Run pending migrations
35-
include_tasks: "{{ item.path }}"
36-
loop: "{{ migration_files.files }}"
37-
when: "item.path | basename | regex_replace('\\.yml$', '') not in applied_migrations"
53+
include_tasks: "{{ migration_dir }}/{{ item }}.yml"
54+
loop: "{{ pending_migrations }}"
3855
register: migration_results
3956

4057
- name: Record applied migrations
41-
command: sqlite3 {{ migration_state_file }} "INSERT OR IGNORE INTO migrations (id) VALUES ('{{ item.item.path | basename | regex_replace('\\.yml$', '') }}');"
42-
loop: "{{ migration_results.results | rejectattr('skipped', 'equalto', true) | list }}"
43-
when: not (item.failed | default(false))
58+
command: sqlite3 {{ migration_state_file }} "INSERT INTO migrations (id) VALUES ('{{ item }}');"
59+
loop: "{{ pending_migrations }}"
60+
loop_control:
61+
index_var: migration_index
62+
when:
63+
- migration_results.results is defined
64+
- migration_results.results | length > 0
65+
- not (migration_results.results[migration_index].failed | default(false))
66+
67+
- name: Verify migrations were recorded
68+
command: sqlite3 {{ migration_state_file }} "SELECT id FROM migrations;"
69+
register: final_migrations
70+
changed_when: false
71+
72+
- name: Show all recorded migrations
73+
debug:
74+
msg: "All recorded migrations: {{ final_migrations.stdout_lines }}"
75+
verbosity: 1
76+
no_log: false

web1/ansible/roles/system/migrations/tasks/main.yml

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,53 @@
2424
set_fact:
2525
applied_migrations: "{{ applied_migrations_output.stdout_lines | select | list }}"
2626

27+
- name: Show applied migrations
28+
debug:
29+
msg: "Already applied migrations: {{ applied_migrations }}"
30+
verbosity: 1
31+
no_log: false
32+
2733
- name: Find migration files
2834
find:
2935
paths: "{{ migration_dir }}"
3036
patterns: "*.yml"
3137
recurse: no
38+
delegate_to: localhost
3239
register: migration_files
3340

41+
- name: Extract migration IDs from files
42+
set_fact:
43+
pending_migrations: |
44+
{{ migration_files.files | map(attribute='path') | map('basename') | map('regex_replace', '\.yml$', '') | reject('in', applied_migrations) | list }}
45+
46+
- name: Show pending migrations
47+
debug:
48+
msg: "Pending migrations to apply: {{ pending_migrations }}"
49+
verbosity: 1
50+
no_log: false
51+
3452
- name: Run pending migrations
35-
include_tasks: "{{ item.path }}"
36-
loop: "{{ migration_files.files }}"
37-
when: "item.path | basename | regex_replace('\\.yml$', '') not in applied_migrations"
53+
include_tasks: "{{ migration_dir }}/{{ item }}.yml"
54+
loop: "{{ pending_migrations }}"
3855
register: migration_results
3956

4057
- name: Record applied migrations
41-
command: sqlite3 {{ migration_state_file }} "INSERT OR IGNORE INTO migrations (id) VALUES ('{{ item.item.path | basename | regex_replace('\\.yml$', '') }}');"
42-
loop: "{{ migration_results.results | rejectattr('skipped', 'equalto', true) | list }}"
43-
when: not (item.failed | default(false))
58+
command: sqlite3 {{ migration_state_file }} "INSERT INTO migrations (id) VALUES ('{{ item }}');"
59+
loop: "{{ pending_migrations }}"
60+
loop_control:
61+
index_var: migration_index
62+
when:
63+
- migration_results.results is defined
64+
- migration_results.results | length > 0
65+
- not (migration_results.results[migration_index].failed | default(false))
66+
67+
- name: Verify migrations were recorded
68+
command: sqlite3 {{ migration_state_file }} "SELECT id FROM migrations;"
69+
register: final_migrations
70+
changed_when: false
71+
72+
- name: Show all recorded migrations
73+
debug:
74+
msg: "All recorded migrations: {{ final_migrations.stdout_lines }}"
75+
verbosity: 1
76+
no_log: false

web2/ansible/roles/system/migrations/tasks/main.yml

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,53 @@
2424
set_fact:
2525
applied_migrations: "{{ applied_migrations_output.stdout_lines | select | list }}"
2626

27+
- name: Show applied migrations
28+
debug:
29+
msg: "Already applied migrations: {{ applied_migrations }}"
30+
verbosity: 1
31+
no_log: false
32+
2733
- name: Find migration files
2834
find:
2935
paths: "{{ migration_dir }}"
3036
patterns: "*.yml"
3137
recurse: no
38+
delegate_to: localhost
3239
register: migration_files
3340

41+
- name: Extract migration IDs from files
42+
set_fact:
43+
pending_migrations: |
44+
{{ migration_files.files | map(attribute='path') | map('basename') | map('regex_replace', '\.yml$', '') | reject('in', applied_migrations) | list }}
45+
46+
- name: Show pending migrations
47+
debug:
48+
msg: "Pending migrations to apply: {{ pending_migrations }}"
49+
verbosity: 1
50+
no_log: false
51+
3452
- name: Run pending migrations
35-
include_tasks: "{{ item.path }}"
36-
loop: "{{ migration_files.files }}"
37-
when: "item.path | basename | regex_replace('\\.yml$', '') not in applied_migrations"
53+
include_tasks: "{{ migration_dir }}/{{ item }}.yml"
54+
loop: "{{ pending_migrations }}"
3855
register: migration_results
3956

4057
- name: Record applied migrations
41-
command: sqlite3 {{ migration_state_file }} "INSERT OR IGNORE INTO migrations (id) VALUES ('{{ item.item.path | basename | regex_replace('\\.yml$', '') }}');"
42-
loop: "{{ migration_results.results | rejectattr('skipped', 'equalto', true) | list }}"
43-
when: not (item.failed | default(false))
58+
command: sqlite3 {{ migration_state_file }} "INSERT INTO migrations (id) VALUES ('{{ item }}');"
59+
loop: "{{ pending_migrations }}"
60+
loop_control:
61+
index_var: migration_index
62+
when:
63+
- migration_results.results is defined
64+
- migration_results.results | length > 0
65+
- not (migration_results.results[migration_index].failed | default(false))
66+
67+
- name: Verify migrations were recorded
68+
command: sqlite3 {{ migration_state_file }} "SELECT id FROM migrations;"
69+
register: final_migrations
70+
changed_when: false
71+
72+
- name: Show all recorded migrations
73+
debug:
74+
msg: "All recorded migrations: {{ final_migrations.stdout_lines }}"
75+
verbosity: 1
76+
no_log: false

web3/ansible/roles/system/migrations/tasks/main.yml

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,53 @@
2424
set_fact:
2525
applied_migrations: "{{ applied_migrations_output.stdout_lines | select | list }}"
2626

27+
- name: Show applied migrations
28+
debug:
29+
msg: "Already applied migrations: {{ applied_migrations }}"
30+
verbosity: 1
31+
no_log: false
32+
2733
- name: Find migration files
2834
find:
2935
paths: "{{ migration_dir }}"
3036
patterns: "*.yml"
3137
recurse: no
38+
delegate_to: localhost
3239
register: migration_files
3340

41+
- name: Extract migration IDs from files
42+
set_fact:
43+
pending_migrations: |
44+
{{ migration_files.files | map(attribute='path') | map('basename') | map('regex_replace', '\.yml$', '') | reject('in', applied_migrations) | list }}
45+
46+
- name: Show pending migrations
47+
debug:
48+
msg: "Pending migrations to apply: {{ pending_migrations }}"
49+
verbosity: 1
50+
no_log: false
51+
3452
- name: Run pending migrations
35-
include_tasks: "{{ item.path }}"
36-
loop: "{{ migration_files.files }}"
37-
when: "item.path | basename | regex_replace('\\.yml$', '') not in applied_migrations"
53+
include_tasks: "{{ migration_dir }}/{{ item }}.yml"
54+
loop: "{{ pending_migrations }}"
3855
register: migration_results
3956

4057
- name: Record applied migrations
41-
command: sqlite3 {{ migration_state_file }} "INSERT OR IGNORE INTO migrations (id) VALUES ('{{ item.item.path | basename | regex_replace('\\.yml$', '') }}');"
42-
loop: "{{ migration_results.results | rejectattr('skipped', 'equalto', true) | list }}"
43-
when: not (item.failed | default(false))
58+
command: sqlite3 {{ migration_state_file }} "INSERT INTO migrations (id) VALUES ('{{ item }}');"
59+
loop: "{{ pending_migrations }}"
60+
loop_control:
61+
index_var: migration_index
62+
when:
63+
- migration_results.results is defined
64+
- migration_results.results | length > 0
65+
- not (migration_results.results[migration_index].failed | default(false))
66+
67+
- name: Verify migrations were recorded
68+
command: sqlite3 {{ migration_state_file }} "SELECT id FROM migrations;"
69+
register: final_migrations
70+
changed_when: false
71+
72+
- name: Show all recorded migrations
73+
debug:
74+
msg: "All recorded migrations: {{ final_migrations.stdout_lines }}"
75+
verbosity: 1
76+
no_log: false

0 commit comments

Comments
 (0)