mirror of
https://github.com/ansible/awx.git
synced 2026-05-17 06:17:36 -02:30
Working on migrations
This commit is contained in:
2
Makefile
2
Makefile
@@ -30,7 +30,7 @@ runserver:
|
|||||||
|
|
||||||
dbchange:
|
dbchange:
|
||||||
# run this each time we make changes to the model
|
# run this each time we make changes to the model
|
||||||
python manage.py schemamigration main --auto
|
python manage.py schemamigration main changes --auto
|
||||||
|
|
||||||
migrate:
|
migrate:
|
||||||
# run this to apply changes to the model
|
# run this to apply changes to the model
|
||||||
|
|||||||
@@ -1,13 +1,8 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.db.models import CASCADE, SET_NULL, PROTECT
|
||||||
|
|
||||||
# TODO: jobs and events model
|
# TODO: jobs and events model TBD
|
||||||
# TODO: how to link up with Django user auth
|
# TODO: reporting model TBD
|
||||||
# TODO: general schema review/organization
|
|
||||||
# TODO: audit cascade behavior and defaults
|
|
||||||
# TODO: set related names
|
|
||||||
|
|
||||||
SET_NULL = models.SET_NULL
|
|
||||||
PROTECT = models.PROTECT
|
|
||||||
|
|
||||||
class CommonModel(models.Model):
|
class CommonModel(models.Model):
|
||||||
'''
|
'''
|
||||||
@@ -22,12 +17,16 @@ class CommonModel(models.Model):
|
|||||||
creation_date = models.DateField()
|
creation_date = models.DateField()
|
||||||
tags = models.ManyToManyField('Tag', related_name='%(class)s_tags')
|
tags = models.ManyToManyField('Tag', related_name='%(class)s_tags')
|
||||||
audit_trail = models.ManyToManyField('AuditTrail', related_name='%(class)s_audit_trails')
|
audit_trail = models.ManyToManyField('AuditTrail', related_name='%(class)s_audit_trails')
|
||||||
|
active = models.BooleanField(default=True)
|
||||||
|
|
||||||
class Tag(models.Model):
|
class Tag(models.Model):
|
||||||
'''
|
'''
|
||||||
any type of object can be given a search tag
|
any type of object can be given a search tag
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
app_label = 'main'
|
||||||
|
|
||||||
name = models.TextField()
|
name = models.TextField()
|
||||||
|
|
||||||
|
|
||||||
@@ -36,18 +35,24 @@ class AuditTrail(CommonModel):
|
|||||||
changing any object records the change
|
changing any object records the change
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
app_label = 'main'
|
||||||
|
|
||||||
resource_type = models.TextField()
|
resource_type = models.TextField()
|
||||||
modified_by = models.ForeignKey('User')
|
modified_by = models.ForeignKey('User', on_delete=SET_NULL, null=True)
|
||||||
delta = models.TextField() # FIXME: switch to JSONField
|
delta = models.TextField() # FIXME: switch to JSONField
|
||||||
detail = models.TextField()
|
detail = models.TextField()
|
||||||
comment = models.TextField()
|
comment = models.TextField()
|
||||||
tag = models.ForeignKey('Tag')
|
tag = models.ForeignKey('Tag', on_delete=SET_NULL, null=True)
|
||||||
|
|
||||||
class Organization(CommonModel):
|
class Organization(CommonModel):
|
||||||
'''
|
'''
|
||||||
organizations are the basic unit of multi-tenancy divisions
|
organizations are the basic unit of multi-tenancy divisions
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
app_label = 'main'
|
||||||
|
|
||||||
users = models.ManyToManyField('User', related_name='organizations')
|
users = models.ManyToManyField('User', related_name='organizations')
|
||||||
admins = models.ManyToManyField('User', related_name='admin_of_organizations')
|
admins = models.ManyToManyField('User', related_name='admin_of_organizations')
|
||||||
projects = models.ManyToManyField('Project', related_name='organizations')
|
projects = models.ManyToManyField('Project', related_name='organizations')
|
||||||
@@ -57,14 +62,20 @@ class Inventory(CommonModel):
|
|||||||
an inventory source contains lists and hosts.
|
an inventory source contains lists and hosts.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
organization = models.ForeignKey(Organization, related_name='inventories')
|
class Meta:
|
||||||
|
app_label = 'main'
|
||||||
|
|
||||||
|
organization = models.ForeignKey(Organization, null=True, on_delete=SET_NULL, related_name='inventories')
|
||||||
|
|
||||||
class Host(CommonModel):
|
class Host(CommonModel):
|
||||||
'''
|
'''
|
||||||
A managed node
|
A managed node
|
||||||
'''
|
'''
|
||||||
|
|
||||||
inventory = models.ForeignKey('Inventory', related_name='hosts')
|
class Meta:
|
||||||
|
app_label = 'main'
|
||||||
|
|
||||||
|
inventory = models.ForeignKey('Inventory', null=True, on_delete=SET_NULL, related_name='hosts')
|
||||||
|
|
||||||
|
|
||||||
class Group(CommonModel):
|
class Group(CommonModel):
|
||||||
@@ -72,7 +83,10 @@ class Group(CommonModel):
|
|||||||
A group of managed nodes. May belong to multiple groups
|
A group of managed nodes. May belong to multiple groups
|
||||||
'''
|
'''
|
||||||
|
|
||||||
inventory = models.ForeignKey('Inventory', related_name='groups')
|
class Meta:
|
||||||
|
app_label = 'main'
|
||||||
|
|
||||||
|
inventory = models.ForeignKey('Inventory', null=True, on_delete=SET_NULL, related_name='groups')
|
||||||
parents = models.ManyToManyField('self', related_name='children')
|
parents = models.ManyToManyField('self', related_name='children')
|
||||||
|
|
||||||
# FIXME: audit nullables
|
# FIXME: audit nullables
|
||||||
@@ -83,8 +97,11 @@ class VariableData(CommonModel):
|
|||||||
A set of host or group variables
|
A set of host or group variables
|
||||||
'''
|
'''
|
||||||
|
|
||||||
host = models.ForeignKey('Host', null=True, default=None, blank=True, related_name='variable_data')
|
class Meta:
|
||||||
group = models.ForeignKey('Group', null=True, default=None, blank=True, related_name='variable_data')
|
app_label = 'main'
|
||||||
|
|
||||||
|
host = models.ForeignKey('Host', null=True, default=None, blank=True, on_delete=CASCADE, related_name='variable_data')
|
||||||
|
group = models.ForeignKey('Group', null=True, default=None, blank=True, on_delete=CASCADE, related_name='variable_data')
|
||||||
data = models.TextField() # FIXME: JsonField
|
data = models.TextField() # FIXME: JsonField
|
||||||
|
|
||||||
class User(CommonModel):
|
class User(CommonModel):
|
||||||
@@ -92,6 +109,9 @@ class User(CommonModel):
|
|||||||
Basic user class
|
Basic user class
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
app_label = 'main'
|
||||||
|
|
||||||
# FIXME: how to integrate with Django auth?
|
# FIXME: how to integrate with Django auth?
|
||||||
|
|
||||||
auth_user = models.OneToOneField('auth.User', related_name='application_user')
|
auth_user = models.OneToOneField('auth.User', related_name='application_user')
|
||||||
@@ -103,9 +123,12 @@ class Credential(CommonModel):
|
|||||||
If used with sudo, a sudo password should be set if required.
|
If used with sudo, a sudo password should be set if required.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
user = models.ForeignKey('User', null=True, default=None, blank=True, related_name='credentials')
|
class Meta:
|
||||||
project = models.ForeignKey('Project', null=True, default=None, blank=True, related_name='credentials')
|
app_label = 'main'
|
||||||
team = models.ForeignKey('Team', null=True, default=None, blank=True, related_name='credentials')
|
|
||||||
|
user = models.ForeignKey('User', null=True, default=None, blank=True, on_delete=SET_NULL, related_name='credentials')
|
||||||
|
project = models.ForeignKey('Project', null=True, default=None, blank=True, on_delete=SET_NULL, related_name='credentials')
|
||||||
|
team = models.ForeignKey('Team', null=True, default=None, blank=True, on_delete=SET_NULL, related_name='credentials')
|
||||||
|
|
||||||
ssh_key_path = models.TextField(blank=True, default='')
|
ssh_key_path = models.TextField(blank=True, default='')
|
||||||
ssh_key_data = models.TextField(blank=True, default='') # later
|
ssh_key_data = models.TextField(blank=True, default='') # later
|
||||||
@@ -119,6 +142,9 @@ class Team(CommonModel):
|
|||||||
A team is a group of users that work on common projects.
|
A team is a group of users that work on common projects.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
app_label = 'main'
|
||||||
|
|
||||||
projects = models.ManyToManyField('Project', related_name='teams')
|
projects = models.ManyToManyField('Project', related_name='teams')
|
||||||
users = models.ManyToManyField('User', related_name='teams')
|
users = models.ManyToManyField('User', related_name='teams')
|
||||||
organization = models.ManyToManyField('Organization', related_name='teams')
|
organization = models.ManyToManyField('Organization', related_name='teams')
|
||||||
@@ -128,6 +154,9 @@ class Project(CommonModel):
|
|||||||
A project represents a playbook git repo that can access a set of inventories
|
A project represents a playbook git repo that can access a set of inventories
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
app_label = 'main'
|
||||||
|
|
||||||
inventories = models.ManyToManyField('Inventory', related_name='projects')
|
inventories = models.ManyToManyField('Inventory', related_name='projects')
|
||||||
local_repository = models.TextField()
|
local_repository = models.TextField()
|
||||||
scm_type = models.TextField()
|
scm_type = models.TextField()
|
||||||
@@ -138,9 +167,12 @@ class Permission(CommonModel):
|
|||||||
A permission allows a user, project, or team to be able to use an inventory source.
|
A permission allows a user, project, or team to be able to use an inventory source.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
user = models.ForeignKey('User', related_name='permissions')
|
class Meta:
|
||||||
project = models.ForeignKey('Project', related_name='permissions')
|
app_label = 'main'
|
||||||
team = models.ForeignKey('Team', related_name='permissions')
|
|
||||||
|
user = models.ForeignKey('User', null=True, on_delete=SET_NULL, related_name='permissions')
|
||||||
|
project = models.ForeignKey('Project', null=True, on_delete=SET_NULL, related_name='permissions')
|
||||||
|
team = models.ForeignKey('Team', null=True, on_delete=SET_NULL, related_name='permissions')
|
||||||
job_type = models.TextField()
|
job_type = models.TextField()
|
||||||
|
|
||||||
# TODO: other job types (later)
|
# TODO: other job types (later)
|
||||||
@@ -150,10 +182,13 @@ class LaunchJob(CommonModel):
|
|||||||
a launch job is a request to apply a project to an inventory source with a given credential
|
a launch job is a request to apply a project to an inventory source with a given credential
|
||||||
'''
|
'''
|
||||||
|
|
||||||
inventory = models.ForeignKey('Inventory', null=True, default=None, blank=True, related_name='launch_jobs')
|
class Meta:
|
||||||
credential = models.ForeignKey('Credential', null=True, default=None, blank=True, related_name='launch_jobs')
|
app_label = 'main'
|
||||||
project = models.ForeignKey('Project', null=True, default=None, blank=True, related_name='launch_jobs')
|
|
||||||
user = models.ForeignKey('User', null=True, default=None, blank=True, related_name='launch_jobs')
|
inventory = models.ForeignKey('Inventory', on_delete=SET_NULL, null=True, default=None, blank=True, related_name='launch_jobs')
|
||||||
|
credential = models.ForeignKey('Credential', on_delete=SET_NULL, null=True, default=None, blank=True, related_name='launch_jobs')
|
||||||
|
project = models.ForeignKey('Project', on_delete=SET_NULL, null=True, default=None, blank=True, related_name='launch_jobs')
|
||||||
|
user = models.ForeignKey('User', on_delete=SET_NULL, null=True, default=None, blank=True, related_name='launch_jobs')
|
||||||
job_type = models.TextField()
|
job_type = models.TextField()
|
||||||
|
|
||||||
|
|
||||||
@@ -162,7 +197,10 @@ class LaunchJob(CommonModel):
|
|||||||
|
|
||||||
class LaunchJobStatus(CommonModel):
|
class LaunchJobStatus(CommonModel):
|
||||||
|
|
||||||
launch_job = models.ForeignKey('LaunchJob', related_name='launch_job_statuses')
|
class Meta:
|
||||||
|
app_label = 'main'
|
||||||
|
|
||||||
|
launch_job = models.ForeignKey('LaunchJob', null=True, on_delete=SET_NULL, related_name='launch_job_statuses')
|
||||||
status = models.IntegerField()
|
status = models.IntegerField()
|
||||||
result_data = models.TextField()
|
result_data = models.TextField()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user