Commit 2a77fa30 authored by Aleksey Shirokih's avatar Aleksey Shirokih
Browse files

Add uniq indecies for models

parent 1024ff7e
......@@ -10,7 +10,7 @@
from __future__ import absolute_import
import json
import logging
import peewee
# Third-party modules
import tornado.gen
from tornado.web import HTTPError
......@@ -75,6 +75,8 @@ class JSONRPCHandler(BaseHandler):
response["result"] = result
except APIError as why:
response["error"] = str(why)
except peewee.IntegrityError as why:
response["error"] = str(why)
# Return response
self.set_header("Content-Type", self.MIME_TYPE)
self.write(json.dumps(response))
def migrate(migrator):
migrator.add_index(
"datacenter",
("name",),
unique=True
)
migrator.add_index(
"environment",
("name",),
unique=True
)
migrator.add_index(
"node",
("environment_id", "datacenter_id", "name",),
unique=True
)
migrator.add_index(
"user",
("name",),
unique=True
)
migrator.add_index(
"role",
("environment_id", "name",),
unique=True
)
\ No newline at end of file
......@@ -61,8 +61,11 @@ class Role(Model):
class Meta:
database = db
db_table = "role"
indexes = (
(("environment", "name"), True),
)
name = CharField(unique=True)
name = CharField()
description = TextField()
link = CharField()
environment = ForeignKeyField(Environment, on_delete="RESTRICT")
......
......@@ -41,7 +41,7 @@ var datacenter_logic = {
Tower.msg.complete("Created");
},
function (err) {
Tower.msg.failed("Failed to create");
Tower.msg.failed("Failed to create " + err);
}
);
} else {
......@@ -53,7 +53,7 @@ var datacenter_logic = {
Tower.msg.complete("Changed");
},
function (err) {
Tower.msg.failed("Failed to change");
Tower.msg.failed("Failed to change " + err);
}
);
}
......
......@@ -52,7 +52,7 @@ var environment_logic = {
Tower.msg.complete("Created");
},
function (err) {
Tower.msg.failed("Failed to create");
Tower.msg.failed("Failed to create " + err);
}
);
} else {
......@@ -64,7 +64,7 @@ var environment_logic = {
Tower.msg.complete("Changed");
},
function (err) {
Tower.msg.failed("Failed to change");
Tower.msg.failed("Failed to change" + err);
}
);
}
......
......@@ -50,7 +50,7 @@ var node_logic = {
Tower.msg.complete("Created");
},
function (err) {
Tower.msg.failed("Failed to create");
Tower.msg.failed("Failed to create " + err);
}
);
} else {
......@@ -62,7 +62,7 @@ var node_logic = {
Tower.msg.complete("Changed");
},
function (err) {
Tower.msg.failed("Failed to change");
Tower.msg.failed("Failed to change "+ err);
}
);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment