-
Notifications
You must be signed in to change notification settings - Fork 0
SPACEDF-21727: [SpaceDF] - [BE] Add APIDevice model for non-LoRa devices #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ngovinh2k2
wants to merge
5
commits into
dev
Choose a base branch
from
feat/spacedf-21727-be-add-apidevice-model-for-non-lora-devices
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f651679
SPACEDF-21727: [SpaceDF] - [BE] Add APIDevice model for non-LoRa devices
ngovinh2k2 60f420a
chore: update nested device handler dispatch
ngovinh2k2 d79d2ef
fix: remove duplicate id migration
ngovinh2k2 e403b0c
refactor: improve perf by not looping through handlers
lethanhdat762003 b2bd18e
chore: remove codex generated marker
ngovinh2k2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
129 changes: 129 additions & 0 deletions
129
apps/device/migrations/0021_move_network_server_claim_code_and_add_api_device.py
This file contains hidden or 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,129 @@ | ||
| # Generated by Codex on 2026-08-24 | ||
|
|
||
| import uuid | ||
|
|
||
| import django.db.models.deletion | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| def copy_device_fields_forward(apps, schema_editor): | ||
| Device = apps.get_model("device", "Device") | ||
| LorawanDevice = apps.get_model("device", "LorawanDevice") | ||
|
|
||
| for lorawan_device in LorawanDevice.objects.values( | ||
| "id", | ||
| "device_id", | ||
| "claim_code", | ||
| "device__network_server_id", | ||
| ).iterator(): | ||
| network_server_id = lorawan_device["device__network_server_id"] | ||
| if network_server_id: | ||
| LorawanDevice.objects.filter(id=lorawan_device["id"]).update( | ||
| network_server_id=network_server_id | ||
| ) | ||
|
|
||
| claim_code = lorawan_device["claim_code"] | ||
| if claim_code: | ||
| Device.objects.filter(id=lorawan_device["device_id"]).update( | ||
| claim_code=claim_code | ||
| ) | ||
|
|
||
|
|
||
| def copy_device_fields_backward(apps, schema_editor): | ||
| Device = apps.get_model("device", "Device") | ||
| LorawanDevice = apps.get_model("device", "LorawanDevice") | ||
|
|
||
| for lorawan_device in LorawanDevice.objects.values( | ||
| "id", | ||
| "device_id", | ||
| "network_server_id", | ||
| "device__claim_code", | ||
| ).iterator(): | ||
| network_server_id = lorawan_device["network_server_id"] | ||
| if network_server_id: | ||
| Device.objects.filter(id=lorawan_device["device_id"]).update( | ||
| network_server_id=network_server_id | ||
| ) | ||
|
|
||
| claim_code = lorawan_device["device__claim_code"] | ||
| if claim_code: | ||
| LorawanDevice.objects.filter(id=lorawan_device["id"]).update( | ||
| claim_code=claim_code | ||
| ) | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("device", "0020_move_location_to_device"), | ||
| ("network_server", "0004_alter_networkserver_logo"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="device", | ||
| name="claim_code", | ||
| field=models.CharField( | ||
| blank=True, | ||
| max_length=100, | ||
| null=True, | ||
| unique=True, | ||
| ), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="lorawandevice", | ||
| name="network_server", | ||
| field=models.ForeignKey( | ||
| blank=True, | ||
| null=True, | ||
| on_delete=django.db.models.deletion.CASCADE, | ||
| related_name="lorawan_devices", | ||
| to="network_server.networkserver", | ||
| ), | ||
| ), | ||
| migrations.CreateModel( | ||
| name="APIDevice", | ||
| fields=[ | ||
| ( | ||
| "created_at", | ||
| models.DateTimeField(auto_now_add=True), | ||
| ), | ||
| ( | ||
| "updated_at", | ||
| models.DateTimeField(auto_now=True), | ||
| ), | ||
| ( | ||
| "id", | ||
| models.UUIDField( | ||
| default=uuid.uuid4, | ||
| editable=False, | ||
| primary_key=True, | ||
| serialize=False, | ||
| ), | ||
| ), | ||
| ( | ||
| "serial_number", | ||
| models.CharField(max_length=100, unique=True), | ||
| ), | ||
| ( | ||
| "device", | ||
| models.OneToOneField( | ||
| on_delete=django.db.models.deletion.CASCADE, | ||
| related_name="api_device", | ||
| to="device.device", | ||
| ), | ||
| ), | ||
| ], | ||
| options={ | ||
| "abstract": False, | ||
| }, | ||
| ), | ||
| migrations.RunPython(copy_device_fields_forward, copy_device_fields_backward), | ||
| migrations.RemoveField( | ||
| model_name="device", | ||
| name="network_server", | ||
| ), | ||
| migrations.RemoveField( | ||
| model_name="lorawandevice", | ||
| name="claim_code", | ||
| ), | ||
| ] |
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.