-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add seperated index command, remove duplication of index for te…
…mp table on import
- Loading branch information
1 parent
548318e
commit d98a450
Showing
9 changed files
with
81 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Pg } from '../helpers'; | ||
|
||
|
||
// Get the arguments | ||
const dataSetName = process.argv[2]; // dataset name | ||
|
||
const indexCommands = { | ||
sirene: ` | ||
CREATE INDEX IF NOT EXISTS idx_sirene_siren ON sirene(siren); | ||
CREATE INDEX IF NOT EXISTS idx_sirene_siret ON sirene(siret); | ||
`, | ||
ban: ` | ||
CREATE INDEX IF NOT EXISTS idx_ban_id ON ban(id); | ||
CREATE INDEX IF NOT EXISTS idx_ban_id_fantoir ON ban(id_fantoir); | ||
CREATE INDEX IF NOT EXISTS idx_ban_code_insee ON ban(code_insee); | ||
`, | ||
departementsfr: ` | ||
CREATE INDEX IF NOT EXISTS idx_departementsfr_code_departement ON departementsfr(code_departement); | ||
CREATE INDEX IF NOT EXISTS idx_departementsfr_code_region ON departementsfr(code_region); | ||
` | ||
}; | ||
|
||
export const indexTable = async (dataSetType: string) => { | ||
|
||
// In case of no matching dataset found | ||
if (!dataSetType) { | ||
console.log(` | ||
Please provide as argument the dataset name you want to create index on: ${Object.keys(indexCommands).join(' / ')}) | ||
`); | ||
} | ||
|
||
if (!Object.keys(indexCommands).includes(dataSetType)) { | ||
throw Error(`No dataset with key "${dataSetType}" exists. Please check available datasets in the docs.`); | ||
} | ||
|
||
const pool = Pg.getPool(); | ||
const client = await pool.connect(); | ||
|
||
try { | ||
await client.query(indexCommands[dataSetType]); | ||
} catch (error) { | ||
console.log(error); | ||
process.exit(1); // Error | ||
} finally { | ||
client.release(); | ||
} | ||
|
||
process.exit(0); | ||
}; | ||
|
||
indexTable(dataSetName); | ||
|
||
// Exit message | ||
process.on('exit', function (code) { | ||
if (code === 0) { | ||
console.log('\nSuccess!'); | ||
} else { | ||
console.log(`\nProcess exited with code ${code}.`); | ||
} | ||
|
||
return; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters