mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-12-20 18:59:37 +00:00
Populate deviceIds from disk
This commit is contained in:
parent
41a288bcdf
commit
5582a68546
2 changed files with 58 additions and 36 deletions
|
|
@ -6,6 +6,7 @@ const { DataTypes, Sequelize } = require('sequelize')
|
|||
const Logger = require('../../../server/Logger')
|
||||
|
||||
const { up, down, migrationName } = require('../../../server/migrations/v2.29.0-add-deviceId')
|
||||
const { stubFileUtils, getMockFileInfo } = require('../MockDatabase')
|
||||
|
||||
const normalizeWhitespaceAndBackticks = (str) => str.replace(/\s+/g, ' ').trim().replace(/`/g, '')
|
||||
|
||||
|
|
@ -13,15 +14,23 @@ describe(`Migration ${migrationName}`, () => {
|
|||
let sequelize
|
||||
let queryInterface
|
||||
let loggerInfoStub
|
||||
let mockFileInfo, file1stats, file2stats
|
||||
|
||||
beforeEach(async () => {
|
||||
sequelize = new Sequelize({ dialect: 'sqlite', storage: ':memory:', logging: false })
|
||||
queryInterface = sequelize.getQueryInterface()
|
||||
loggerInfoStub = sinon.stub(Logger, 'info')
|
||||
|
||||
mockFileInfo = getMockFileInfo()
|
||||
file1stats = mockFileInfo.get('/test/file.pdf')
|
||||
file2stats = mockFileInfo.get('/mnt/drive/file-same-ino-different-dev.pdf')
|
||||
|
||||
stubFileUtils(mockFileInfo)
|
||||
|
||||
await queryInterface.createTable('libraryItems', {
|
||||
id: { type: DataTypes.INTEGER, allowNull: false, primaryKey: true, unique: true },
|
||||
ino: { type: DataTypes.STRING },
|
||||
path: { type: DataTypes.STRING },
|
||||
mediaId: { type: DataTypes.INTEGER, allowNull: false },
|
||||
mediaType: { type: DataTypes.STRING, allowNull: false },
|
||||
libraryId: { type: DataTypes.INTEGER, allowNull: false }
|
||||
|
|
@ -46,8 +55,8 @@ describe(`Migration ${migrationName}`, () => {
|
|||
})
|
||||
|
||||
await queryInterface.bulkInsert('libraryItems', [
|
||||
{ id: 1, mediaId: 1, mediaType: 'book', libraryId: 1, ino: '1' },
|
||||
{ id: 2, mediaId: 2, mediaType: 'book', libraryId: 1, ino: '2' }
|
||||
{ id: 1, ino: file1stats.ino, mediaId: 1, path: file1stats.path, mediaType: 'book', libraryId: 1 },
|
||||
{ id: 2, ino: file2stats.ino, mediaId: 2, path: file2stats.path, mediaType: 'book', libraryId: 1 }
|
||||
])
|
||||
|
||||
await queryInterface.bulkInsert('authors', [
|
||||
|
|
@ -80,17 +89,17 @@ describe(`Migration ${migrationName}`, () => {
|
|||
const libraryItems = await queryInterface.describeTable('libraryItems')
|
||||
expect(libraryItems.deviceId).to.exist
|
||||
})
|
||||
/* TODO
|
||||
it('should populate the deviceId columns from the filesystem for each libraryItem', async () => {
|
||||
|
||||
it('should populate the deviceId columns from the filesystem for each libraryItem', async function () {
|
||||
this.timeout(0)
|
||||
await up({ context: { queryInterface, logger: Logger } })
|
||||
|
||||
const [libraryItems] = await queryInterface.sequelize.query('SELECT * FROM libraryItems')
|
||||
expect(libraryItems).to.deep.equal([
|
||||
{ id: 1, mediaId: 1, mediaType: 'book', libraryId: 1, authorNamesFirstLast: 'John Smith, John Doe', authorNamesLastFirst: 'Smith, John, Doe, John' },
|
||||
{ id: 2, mediaId: 2, mediaType: 'book', libraryId: 1, authorNamesFirstLast: 'Jane Smith', authorNamesLastFirst: 'Smith, Jane' }
|
||||
{ id: 1, ino: file1stats.ino, deviceId: file1stats.dev, mediaId: 1, path: file1stats.path, mediaType: 'book', libraryId: 1 },
|
||||
{ id: 2, ino: file2stats.ino, deviceId: file2stats.dev, mediaId: 2, path: file2stats.path, mediaType: 'book', libraryId: 1 }
|
||||
])
|
||||
})
|
||||
*/
|
||||
|
||||
it('should add an index on ino and deviceId to the libraryItems table', async () => {
|
||||
await up({ context: { queryInterface, logger: Logger } })
|
||||
|
|
@ -119,8 +128,8 @@ describe(`Migration ${migrationName}`, () => {
|
|||
|
||||
const [libraryItems] = await queryInterface.sequelize.query(`SELECT * FROM libraryItems`)
|
||||
expect(libraryItems).to.deep.equal([
|
||||
{ id: 1, ino: '1', deviceId: null, mediaId: 1, mediaType: 'book', libraryId: 1 },
|
||||
{ id: 2, ino: '2', deviceId: null, mediaId: 2, mediaType: 'book', libraryId: 1 }
|
||||
{ id: 1, ino: file1stats.ino, deviceId: file1stats.dev, path: file1stats.path, mediaId: 1, mediaType: 'book', libraryId: 1 },
|
||||
{ id: 2, ino: file2stats.ino, deviceId: file2stats.dev, path: file2stats.path, mediaId: 2, mediaType: 'book', libraryId: 1 }
|
||||
])
|
||||
})
|
||||
})
|
||||
|
|
@ -135,8 +144,8 @@ describe(`Migration ${migrationName}`, () => {
|
|||
|
||||
const [libraryItems] = await queryInterface.sequelize.query(`SELECT * FROM libraryItems`)
|
||||
expect(libraryItems).to.deep.equal([
|
||||
{ id: 1, mediaId: 1, mediaType: 'book', libraryId: 1, ino: '1' },
|
||||
{ id: 2, mediaId: 2, mediaType: 'book', libraryId: 1, ino: '2' }
|
||||
{ id: 1, ino: file1stats.ino, mediaId: 1, path: file1stats.path, mediaType: 'book', libraryId: 1 },
|
||||
{ id: 2, ino: file2stats.ino, mediaId: 2, path: file2stats.path, mediaType: 'book', libraryId: 1 }
|
||||
])
|
||||
})
|
||||
|
||||
|
|
@ -158,8 +167,8 @@ describe(`Migration ${migrationName}`, () => {
|
|||
|
||||
const [libraryItems] = await queryInterface.sequelize.query(`SELECT * FROM libraryItems`)
|
||||
expect(libraryItems).to.deep.equal([
|
||||
{ id: 1, ino: '1', mediaId: 1, mediaType: 'book', libraryId: 1 },
|
||||
{ id: 2, ino: '2', mediaId: 2, mediaType: 'book', libraryId: 1 }
|
||||
{ id: 1, ino: file1stats.ino, path: file1stats.path, mediaId: 1, mediaType: 'book', libraryId: 1 },
|
||||
{ id: 2, ino: file2stats.ino, path: file2stats.path, mediaId: 2, mediaType: 'book', libraryId: 1 }
|
||||
])
|
||||
|
||||
const [[{ count: count6 }]] = await queryInterface.sequelize.query(`SELECT COUNT(*) as count FROM sqlite_master WHERE type='index' AND name='library_items_ino_device_id'`)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue