Add scripts
This commit is contained in:
88
scripts/init-dialects.js
Normal file
88
scripts/init-dialects.js
Normal file
@@ -0,0 +1,88 @@
|
||||
const db = require('mantra-db-models');
|
||||
const prompt = require("prompt")
|
||||
|
||||
db.init().then(() => {
|
||||
// We could probably run the things in the seeders...
|
||||
db.Language.findAll()
|
||||
.then(languages => {
|
||||
if (languages.length == 0) {
|
||||
// TODO: Create languages
|
||||
return db.Language.bulkCreate([
|
||||
{
|
||||
id: "en",
|
||||
name: "English",
|
||||
displayName: "English",
|
||||
},
|
||||
{
|
||||
id: "st",
|
||||
name: "Sesotho",
|
||||
displayName: "Sesotho",
|
||||
},
|
||||
{
|
||||
id: "zu",
|
||||
name: "Isizulu",
|
||||
displayName: "Isizulu",
|
||||
}
|
||||
])
|
||||
} else {
|
||||
return languages
|
||||
}
|
||||
}).then(languages => {
|
||||
return db.Continent.findAll()
|
||||
}).then(continents => {
|
||||
if (continents.length == 0) {
|
||||
return db.Continent.bulkCreate([
|
||||
{
|
||||
id: "afr",
|
||||
name: "Africa"
|
||||
}
|
||||
])
|
||||
} else {
|
||||
return continents
|
||||
}
|
||||
}).then(continents => {
|
||||
return db.Country.findAll()
|
||||
}).then(countries => {
|
||||
if (countries.length == 0) {
|
||||
return db.Country.bulkCreate([
|
||||
{
|
||||
id: "int",
|
||||
name: "International"
|
||||
},
|
||||
{
|
||||
id: "zaf",
|
||||
name: "South Africa"
|
||||
}
|
||||
])
|
||||
} else {
|
||||
return countries
|
||||
}
|
||||
}).then(countries => {
|
||||
return db.Dialect.findAll()
|
||||
}).then(dialects => {
|
||||
if (dialects.length == 0) {
|
||||
// TODO: Create dialects
|
||||
return db.Dialect.bulkCreate([
|
||||
{
|
||||
name: "English",
|
||||
countryId: "int",
|
||||
languageId: "en"
|
||||
},
|
||||
{
|
||||
name: "Sesotho",
|
||||
countryId: "zaf",
|
||||
languageId: "st"
|
||||
},
|
||||
{
|
||||
name: "Zulu",
|
||||
countryId: "zaf",
|
||||
languageId: "zu"
|
||||
}
|
||||
])
|
||||
} else {
|
||||
return dialects
|
||||
}
|
||||
}).catch(error => {
|
||||
console.error("Error: ", error)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user