]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/user.js
Server: add unique to unique indexes
[github/Chocobozzz/PeerTube.git] / server / models / user.js
index 631cd96c98cbe014aa65e6ef1ac962e39fc3e12f..6cb9eec3fd435ba247061e24194b764c34722796 100644 (file)
@@ -40,7 +40,8 @@ module.exports = function (sequelize, DataTypes) {
     {
       indexes: [
         {
-          fields: [ 'username' ]
+          fields: [ 'username' ],
+          unique: true
         }
       ],
       classMethods: {
@@ -94,6 +95,11 @@ function toFormatedJSON () {
 // ------------------------------ STATICS ------------------------------
 
 function associate (models) {
+  this.hasOne(models.Author, {
+    foreignKey: 'userId',
+    onDelete: 'cascade'
+  })
+
   this.hasMany(models.OAuthToken, {
     foreignKey: 'userId',
     onDelete: 'cascade'