<commit_before>var knex = require('./knex-config');
var bookshelf = require('bookshelf')(knex);

bookshelf.knex.schema.hasTable('Users').then(function(exists) {
  if (!exists) {
    bookshelf.knex.schema.createTable('Users', function (user) {
      user.increments('id').primary().unsigned();
      user.string('email', 50).unique().notNullable();
      user.string('password', 100);
      user.string('oauth', 30);
      user.string('display_name', 50);
      user.string('icon', 100);
      user.string('location', 100);
      user.timestamps();
    }).then(function (table) {
      console.log('Created Table Users');
    });
  }
});

bookshelf.knex.schema.hasTable('Playlists').then(function(exists) {
  if (!exists) {
    bookshelf.knex.schema.createTable('Playlists', function (playlist) {
      playlist.increments('id').primary().unsigned();
      playlist.integer('user_id').unsigned().references('id').inTable('Users');
      playlist.string('name', 50).notNullable();
      playlist.integer('current_media_index').unsigned();
      playlist.timestamps();
    }).then(function (table) {
      console.log('Created Table Playlists');
    });
  }
});

bookshelf.knex.schema.hasTable('Medias').then(function(exists) {
  if (!exists) {
    bookshelf.knex.schema.createTable('Medias', function (media) {
      media.increments('id').primary().unsigned();
      media.string('youtube_id', 100);
      media.integer('youtube_link', 100);
      media.integer('play_count').unsigned().defaultTo(0);
      media.string('name', 255).defaultTo('');
      media.timestamps();
    }).then(function (table) {
      console.log('Created Table Medias');
    });
  }
});

bookshelf.knex.schema.hasTable('Media_Playlists').then(function(exists) {
  if (!exists) {
    bookshelf.knex.schema.createTable('Media_Playlists', function (playlist) {
      playlist.increments('id').primary().unsigned();
      playlist.integer('playlist_id').unsigned().references('id').inTable('Playlists');
      playlist.integer('media_id').unsigned().references('id').inTable('Medias');
      playlist.integer('order', 8).unsigned();
      playlist.unique(['media_id', 'order']);
    }).then(function (table) {
      console.log('Created Table Media Playlists');
    });
  }
});

bookshelf.knex.schema.hasTable('Rooms').then(function(exists) {
  if (!exists) {
    bookshelf.knex.schema.createTable('Rooms', function (room) {
      room.increments('id').primary().unsigned();
      room.string('name', 50);
      room.boolean('private').defaultTo(false);
      room.string('password', <PASSWORD>);
      room.timestamps();
    }).then(function (table) {
      console.log('Created Table Rooms');
    });
  }
});

bookshelf.knex.schema.hasTable('Users_Rooms').then(function(exists) {
  if (!exists) {
    bookshelf.knex.schema.createTable('Users_Rooms', function (room) {
      room.increments('id').primary().unsigned();
      room.integer('user_id').unsigned().references('id').inTable('Users');
      room.integer('room_id').unsigned().references('id').inTable('Rooms');
      room.timestamps();
    }).then(function (table) {
      console.log('Created Table Users_Rooms');
    });
  }
});

// console.log('piTunes DB Tables created');


module.exports = bookshelf;
<commit_msg>(feature) added new column feature to database. Resorted DB table creations<commit_after>var knex = require('./knex-config');
var bookshelf = require('bookshelf')(knex);

bookshelf.knex.schema.hasTable('Rooms').then(function(exists) {
  if (!exists) {
    bookshelf.knex.schema.createTable('Rooms', function (room) {
      room.increments('id').primary();
      room.string('name', 50).notNullable();
      room.boolean('private').defaultTo(false);
      room.string('password', 100).defaultTo('');
      room.timestamps();
    }).then(function (table) {
      console.log('Created Table Rooms');
    });
  }
});

bookshelf.knex.schema.hasTable('Medias').then(function(exists) {
  if (!exists) {
    bookshelf.knex.schema.createTable('Medias', function (media) {
      media.increments('id').primary();
      media.string('youtube_id', 100);
      media.integer('youtube_link', 100);
      media.integer('play_count').unsigned().defaultTo(0);
      media.string('name', 255).defaultTo('');
      media.timestamps();
    }).then(function (table) {
      console.log('Created Table Medias');
    });
  }
});

bookshelf.knex.schema.hasTable('Users').then(function(exists) {
  if (!exists) {
    bookshelf.knex.schema.createTable('Users', function (user) {
      user.increments('id').primary();
      user.string('email', 50).unique().notNullable();
      user.string('password', <PASSWORD>);
      user.string('oauth', 30);
      user.string('display_name', 50).notNullable();
      user.string('icon', 100);
      user.string('location', 100);
      user.integer('current_playlist_id').unsigned().defaultTo(0);//.references('id').inTable('Playlists');
      user.timestamps();
    }).then(function (table) {
      console.log('Created Table Users');
      bookshelf.knex.schema.hasTable('Playlists').then(function(exists) {
        if (!exists) {
          bookshelf.knex.schema.createTable('Playlists', function (playlist) {
            playlist.increments('id').primary();
            playlist.integer('user_id').unsigned().references('id').inTable('Users');
            playlist.string('name', 50).notNullable();
            playlist.integer('current_media_index').defaultTo(0);//.references('order').inTable('Media_Playlists');
            // playlist.boolean('current');
            // playlist.unique(['user_id', 'current']);
            playlist.timestamps();
          }).then(function (table) {
            console.log('Created Table Playlists');
            bookshelf.knex.schema.hasTable('Media_Playlists').then(function(exists) {
              if (!exists) {
                bookshelf.knex.schema.createTable('Media_Playlists', function (playlist) {
                  playlist.increments('id').primary();
                  playlist.integer('playlist_id').unsigned().references('id').inTable('Playlists');
                  playlist.integer('media_id').unsigned().references('id').inTable('Medias');
                  playlist.integer('order', 8).unsigned();
                  playlist.unique(['media_id', 'order']);
                }).then(function (table) {
                  console.log('Created Table Media Playlists');
                });
              }
            });
          });
        }
      });
    });
  }
});

bookshelf.knex.schema.hasTable('Users_Rooms').then(function(exists) {
  if (!exists) {
    bookshelf.knex.schema.createTable('Users_Rooms', function (room) {
      room.increments('id').primary();
      room.integer('user_id').unsigned().references('id').inTable('Users');
      room.integer('room_id').unsigned().references('id').inTable('Rooms');
      room.timestamps();
    }).then(function (table) {
      console.log('Created Table Users_Rooms');
    });
  }
});

module.exports = bookshelf;

{'fraction_non_alphanumeric': 0.19135537426649493, 'fraction_numerical': 0.0088736224416774, 'mean_word_length': 3.4623243933588763, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5789410', 'n_tokens_mistral': 2188, 'n_tokens_neox': 2075, 'n_words': 262}