Skip to content

Commit

Permalink
Add Default Organizations to Seed (optional)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvire committed Oct 18, 2023
1 parent b916a2e commit 88ebe0b
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 1 deletion.
10 changes: 10 additions & 0 deletions source/SIL.AppBuilder.Portal/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion source/SIL.AppBuilder.Portal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@types/node": "^20.8.6",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"commander": "^11.1.0",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-svelte": "^2.30.0",
Expand All @@ -40,5 +41,8 @@
"vite": "^4.4.2",
"vitest": "^0.32.2"
},
"type": "module"
"type": "module",
"volta": {
"node": "18.16.1"
}
}
177 changes: 177 additions & 0 deletions source/SIL.AppBuilder.Portal/prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import { PrismaClient } from '@prisma/client';
import { Command, Option } from 'commander';

const program = new Command();
program
.addOption(new Option('-v, --verbose [level]', 'verbose logging').argParser(parseInt).default(0))
.addOption(new Option('-o, --organizations', 'include default organizations'))
.addOption(new Option('-d, --data', 'include sample data'));
program.parse(process.argv);
const options = program.opts();
if (options.verbose) console.log(options);

const prisma = new PrismaClient();
async function main() {
Expand Down Expand Up @@ -338,6 +348,173 @@ async function main() {
create: data
});
}

if (options.organizations) {
const usersData = [
{
Id: 1,
Name: 'Chris Hubbard',
Email: 'chris_hubbard@sil.org',
ExternalId: 'google-oauth2|116747902156680384840',
FamilyName: 'Hubbard',
GivenName: 'Chris',
IsLocked: false
},
{
Id: 2,
Name: 'David Moore',
Email: 'david_moore1@sil.org',
ExternalId: 'google-oauth2|114981819181509824425',
FamilyName: 'Moore',
GivenName: 'David',
IsLocked: false
},
{
Id: 3,
Name: 'Bill Dyck',
Email: 'bill_dyck@sil.org',
ExternalId: 'google-oauth2|102643649500459434996',
FamilyName: 'Dyck',
GivenName: 'Bill',
IsLocked: false
},
{
Id: 4,
Name: 'Loren Hawthorne',
Email: 'loren_hawthorne@sil.org',
ExternalId: 'google-oauth2|116603781884964961816',
FamilyName: 'Hawthorne',
GivenName: 'Loren',
IsLocked: false
},
{
Id: 5,
Name: 'Chris Hubbard (Kalaam)',
Email: 'chris.kalaam@gmail.com',
ExternalId: 'auth0|5b578f6197af652b19f9bb41',
FamilyName: 'Hubbard',
GivenName: 'Chris',
IsLocked: false
}
];

for (const userData of usersData) {
await prisma.users.upsert({
where: { Id: userData.Id },
update: userData,
create: userData
});
}

const organizationsData = [
{
Id: 1,
Name: 'SIL International',
WebsiteUrl: 'https://sil.org',
BuildEngineUrl: 'https://replace.scriptoria.io:8443',
BuildEngineApiAccessToken: 'replace',
LogoUrl: 'https://sil-prd-aps-resources.s3.amazonaws.com/sil/sil_logo.png',
OwnerId: 1
},
{
Id: 2,
Name: 'Kalaam Media',
WebsiteUrl: 'https://kalaam.org',
BuildEngineUrl: 'https://replace.scriptoria.io:8443',
BuildEngineApiAccessToken: 'replace',
LogoUrl: 'https://s3.amazonaws.com/sil-prd-aps-resources/ips/wildfire_flame_logo.png',
OwnerId: 1
},
{
Id: 3,
Name: 'Faith Comes By Hearing',
WebsiteUrl: 'https://kalaam.org',
BuildEngineUrl: 'https://replace.scriptoria.io:8443',
BuildEngineApiAccessToken: 'replace',
LogoUrl:
'https://play-lh.googleusercontent.com/yXm_WKG7_DJxL3IPYFul6iYfRNzWGdSbOJad7acWt28Xc6jSdlJCXPgrJOc-mdkf5_OE',
OwnerId: 1
},
{
Id: 4,
Name: 'Scripture Earth',
WebsiteUrl: 'https://scriptureearth.org',
BuildEngineUrl: 'https://replace.scriptoria.io:8443',
BuildEngineApiAccessToken: 'replace',
LogoUrl: 'https://s3.amazonaws.com/sil-prd-aps-resources/scriptureearth/se_logo.png',
OwnerId: 1
}
];

for (const organizationData of organizationsData) {
await prisma.organizations.upsert({
where: { Id: organizationData.Id },
update: organizationData,
create: organizationData
});
}

const storesData = [
{
Id: 1,
Name: 'wycliffeusa',
Description: 'Wycliffe USA - Google Play',
StoreTypeId: 1
},
{
Id: 2,
Name: 'internetpublishingservice',
Description: 'Internet Publishing Service (Kalaam) - Google Play',
StoreTypeId: 1
},
{
Id: 3,
Name: 'indhack',
Description: 'Indigitous Hack - Google Play',
StoreTypeId: 1
}
];

for (const storeData of storesData) {
await prisma.stores.upsert({
where: { Id: storeData.Id },
update: storeData,
create: storeData
});
}

const organizationProductDefinitionsData = [
{
Id: 1,
OrganizationId: 1,
ProductDefinitionId: 1
},
{
Id: 2,
OrganizationId: 2,
ProductDefinitionId: 1
},
{
Id: 3,
OrganizationId: 3,
ProductDefinitionId: 1
}
];

for (const data of organizationProductDefinitionsData) {
await prisma.organizationProductDefinitions.upsert({
where: {
Id: data.Id
},
update: data,
create: data
});
}
}

if (options.data) {
console.log('Create sample data');
}
}
main()
.then(async () => {
Expand Down

0 comments on commit 88ebe0b

Please sign in to comment.