Skip to content

Commit

Permalink
Set oui as primary key for OUI model
Browse files Browse the repository at this point in the history
  • Loading branch information
stveit committed Aug 22, 2024
1 parent cafcfa1 commit 0029ccb
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion python/nav/models/oui.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
class OUI(models.Model):
"""Defines an OUI and the name of the vendor the OUI belongs to"""

oui = models.CharField(max_length=17, primary_key=True)
vendor = VarcharField()
oui = models.CharField(max_length=17, unique=True)

def __str__(self):
return self.oui
Expand Down
3 changes: 1 addition & 2 deletions python/nav/models/sql/changes/sc.05.10.0002.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
CREATE TABLE manage.oui (
id SERIAL PRIMARY KEY,
oui MACADDR PRIMARY KEY,
vendor VARCHAR NOT NULL,
oui MACADDR NOT NULL UNIQUE,
CHECK (oui=trunc(oui))
);
6 changes: 2 additions & 4 deletions tests/integration/models/oui_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ def valid_oui():
oui = "aa:bb:cc:00:00:00"
instance = OUI(oui=oui, vendor="myvendor")
yield instance
if instance.id:
instance.delete()
instance.delete()


@pytest.fixture()
def invalid_oui():
oui = "aa:bb:cc:dd:ee:ff"
instance = OUI(oui=oui, vendor="myvendor")
yield instance
if instance.id:
instance.delete()
instance.delete()

0 comments on commit 0029ccb

Please sign in to comment.