Skip to content

Commit

Permalink
Merge branch 'master' into import-nand-lal
Browse files Browse the repository at this point in the history
  • Loading branch information
Harjot1Singh committed Jun 21, 2019
2 parents 91b0c62 + d00d4f1 commit 100ff41
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { Lines, Shabads, Sources, TranslationSources, Translations, knex } = requ
const { generateId } = require( './utils' )
require( './string-colors' )

const columnOpts = [ 'shabadId', 'translation', 'page', 'line', 'sttm', 'gurmukhi', 'orderBy', 'source' ]
const columnOpts = [ 'shabadId', 'translation', 'page', 'line', 'sttmId', 'gurmukhi', 'orderBy', 'source' ]

const findIds = async ( model, length, count ) => {
// Grab ids to exclude from database
Expand Down Expand Up @@ -57,6 +57,7 @@ const main = async () => {
const lines = await db.all( `SELECT * FROM ${tableName} ORDER BY ${orderBy}` )
const shabadIds = ( await db.all( `SELECT DISTINCT ${shabadId} FROM ${tableName}` ) ).map( x => x[ shabadId ] )
const sources = ( await db.all( `SELECT DISTINCT ${source} FROM ${tableName}` ) ).map( x => x[ source ] )
const sttmIds = ( await db.all( `SELECT DISTINCT ${sttmId} FROM ${tableName}` ) ).map( x => x[ sttmId ] )
await db.close()

// Generate some Line and Shabad IDs and map them in
Expand Down Expand Up @@ -96,12 +97,17 @@ const main = async () => {
page_name_gurmukhi: -( index + 1 ),
} ) )

if ( sttmIds && sttmIds.length !== shabadIds.length ) {
console.log( 'Different number of STTM IDs to Shabads'.error )
return
}

// Generate new Shabads
const newShabads = shabadIds.map( ( id, index ) => ( {
id: shabadIDMap[ id ],
writer_id: -1,
section_id: -1,
sttm_id: lines[ sttmId ],
sttm_id: sttmIds[ index ],
order_id: shabadOrderId + index + 1,
source_id: sourceMap[ id ],
} ) )
Expand Down

0 comments on commit 100ff41

Please sign in to comment.