luk707 / luk707/trmnl-server

Create device name column in DB

Open
#3 0 comments 0 reactions 1 assignee View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

It would be nice to have human readable names for the TRMNL devices, such as "Luke's TRMNL". In order to do this, we need to add a new column to the database for the device name.

We can save adding an endpoint to set this name until later, this task just requires us to add a new column called `name` (NOT NULL) which will default to "Device {ID}" or "Virtual device {ID}" based on device mac address presence in db.

We will need to update any endpoint that returns DeviceInfo to also include this name.

AC:

- [ ] Create a migration to add a new `name` column to the devices table. Existing devices should have their name automatically set
- [ ] Update the DeviceInfo model to include `name` as an Optional and fix any endpoints that now need to include the name in their query
- [ ] Update the `/api/setup` logic to set the device name when a new device is created
- [ ] Update any affected unit & integration tests

Migration:

```sql
-- Rename the existing table
ALTER TABLE devices RENAME TO devices_old;

-- Create the new table with the additional `name` column (NOT NULL)
CREATE TABLE devices (
id TEXT NOT NULL PRIMARY KEY,
mac TEXT,
api_key TEXT NOT NULL UNIQUE,
name TEXT NOT NULL,
rssi INTEGER,
battery_voltage REAL,
fw_version TEXT,
refresh_rate INTEGER,
images_json TEXT NOT NULL DEFAULT '[]'
);

-- Copy existing data, setting `name` based on mac
INSERT INTO devices (
id, mac, api_key, name, rssi, battery_voltage, fw_version, refresh_rate, images_json
)
SELECT
id,
mac,
api_key,
CASE
WHEN mac IS NOT NULL THEN 'Device ' || id
ELSE 'Virtual device ' || id
END AS name,
rssi,
battery_voltage,
fw_version,
refresh_rate,
images_json
FROM devices_old;

-- Drop the old table
DROP TABLE devices_old;

```

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.