-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94af712
commit 75948bb
Showing
12 changed files
with
303 additions
and
169 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
stats-backend/api2/migrations/0031_update_nodestatushistory.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from django.db import migrations, models | ||
|
||
def update_nodestatushistory(apps, schema_editor): | ||
NodeStatusHistory = apps.get_model('api2', 'NodeStatusHistory') | ||
Node = apps.get_model('api2', 'Node') | ||
|
||
for history in NodeStatusHistory.objects.all(): | ||
if history.provider: | ||
history.node_id = history.provider.node_id | ||
history.save() | ||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('api2', '0030_relaynodes_ip_address_relaynodes_port'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='nodestatushistory', | ||
name='node_id', | ||
field=models.CharField(max_length=42, null=True), | ||
), | ||
migrations.RunPython(update_nodestatushistory), | ||
migrations.RemoveField( | ||
model_name='nodestatushistory', | ||
name='provider', | ||
), | ||
migrations.AlterField( | ||
model_name='nodestatushistory', | ||
name='node_id', | ||
field=models.CharField(max_length=42), | ||
), | ||
|
||
] |
24 changes: 24 additions & 0 deletions
24
.../api2/migrations/0032_remove_nodestatushistory_api2_nodest_provide_64b3a2_idx_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Generated by Django 4.1.7 on 2024-09-24 11:13 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('api2', '0031_update_nodestatushistory'), | ||
] | ||
|
||
operations = [ | ||
|
||
migrations.AlterField( | ||
model_name='nodestatushistory', | ||
name='is_online', | ||
field=models.BooleanField(), | ||
), | ||
migrations.AlterField( | ||
model_name='nodestatushistory', | ||
name='timestamp', | ||
field=models.DateTimeField(auto_now_add=True), | ||
), | ||
] |
23 changes: 23 additions & 0 deletions
23
stats-backend/api2/migrations/0033_alter_nodestatushistory_is_online_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 4.1.7 on 2024-09-24 11:14 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('api2', '0032_remove_nodestatushistory_api2_nodest_provide_64b3a2_idx_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='nodestatushistory', | ||
name='is_online', | ||
field=models.BooleanField(db_index=True), | ||
), | ||
migrations.AlterField( | ||
model_name='nodestatushistory', | ||
name='timestamp', | ||
field=models.DateTimeField(auto_now_add=True, db_index=True), | ||
), | ||
] |
17 changes: 17 additions & 0 deletions
17
stats-backend/api2/migrations/0034_nodestatushistory_api2_nodest_node_id_220bdf_idx.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Generated by Django 4.1.7 on 2024-09-24 11:14 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('api2', '0033_alter_nodestatushistory_is_online_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddIndex( | ||
model_name='nodestatushistory', | ||
index=models.Index(fields=['node_id', 'timestamp'], name='api2_nodest_node_id_220bdf_idx'), | ||
), | ||
] |
17 changes: 17 additions & 0 deletions
17
...s-backend/api2/migrations/0035_remove_nodestatushistory_api2_nodest_provide_64b3a2_idx.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Generated by Django 4.1.7 on 2024-09-24 11:14 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('api2', '0034_nodestatushistory_api2_nodest_node_id_220bdf_idx'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveIndex( | ||
model_name='nodestatushistory', | ||
name='api2_nodest_provide_64b3a2_idx', | ||
), | ||
] |
34 changes: 34 additions & 0 deletions
34
stats-backend/api2/migrations/0036_nodestatushistory_remove_duplicate.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Generated by Django 4.1.7 on 2024-09-24 12:00 | ||
|
||
from django.db import migrations | ||
from django.db.models import F | ||
|
||
def cleanup_nodestatushistory(apps, schema_editor): | ||
NodeStatusHistory = apps.get_model('api2', 'NodeStatusHistory') | ||
|
||
# Get all node_ids | ||
node_ids = NodeStatusHistory.objects.values_list('node_id', flat=True).distinct() | ||
|
||
for node_id in node_ids: | ||
entries = NodeStatusHistory.objects.filter(node_id=node_id).order_by('timestamp') | ||
previous_status = None | ||
to_delete = [] | ||
|
||
for entry in entries: | ||
if previous_status is not None and entry.is_online == previous_status: | ||
to_delete.append(entry.id) | ||
else: | ||
previous_status = entry.is_online | ||
|
||
# Delete duplicate entries for this node | ||
NodeStatusHistory.objects.filter(id__in=to_delete).delete() | ||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('api2', '0035_remove_nodestatushistory_api2_nodest_provide_64b3a2_idx'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(cleanup_nodestatushistory), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.