Merge pull request #1 from ManasluHQ/feat/add-seeder

added seeder script
This commit is contained in:
er-santosh 2024-07-27 19:31:02 +05:45 committed by GitHub
commit de243fded5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 65 additions and 11 deletions

View file

@ -32,12 +32,12 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: mr-smithers-excellent/docker-build-push@v6
name: Build & push Docker image to docker.io for ${{ matrix.db-type }}
with:
image: umamisoftware/umami
tags: ${{ matrix.db-type }}-${{ inputs.version }}, ${{ matrix.db-type }}-latest
buildArgs: DATABASE_TYPE=${{ matrix.db-type }}
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# - uses: mr-smithers-excellent/docker-build-push@v6
# name: Build & push Docker image to docker.io for ${{ matrix.db-type }}
# with:
# image: umamisoftware/umami
# tags: ${{ matrix.db-type }}-${{ inputs.version }}, ${{ matrix.db-type }}-latest
# buildArgs: DATABASE_TYPE=${{ matrix.db-type }}
# registry: docker.io
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}

View file

@ -14,7 +14,7 @@
"build": "npm-run-all check-env build-db check-db build-tracker build-geo build-app",
"start": "next start",
"build-docker": "npm-run-all build-db build-tracker build-geo build-app",
"start-docker": "npm-run-all check-db update-tracker start-server",
"start-docker": "npm-run-all check-db update-tracker seed start-server",
"start-env": "node scripts/start-env.js",
"start-server": "node server.js",
"build-app": "next build",
@ -45,7 +45,8 @@
"postbuild": "node scripts/postbuild.js",
"test": "jest",
"cypress-open": "cypress open cypress run",
"cypress-run": "cypress run cypress run"
"cypress-run": "cypress run cypress run",
"seed": "node scripts/seed.js"
},
"lint-staged": {
"**/*.{js,jsx,ts,tsx}": [

21
scripts/seed.js Normal file
View file

@ -0,0 +1,21 @@
/* eslint-disable no-console */
require('dotenv').config();
const { client: prismaClient } = require('@umami/prisma-client');
const { seedAdminUser } = require('./seeds/admin-user');
async function main() {
// seed admin user
await seedAdminUser();
console.log('Seeding complete.');
}
main()
.catch(e => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prismaClient.$disconnect();
});

View file

@ -0,0 +1,32 @@
const { hashPassword } = require('next-basics');
/* eslint-disable no-console */
const { client: prismaClient } = require('@umami/prisma-client');
async function seedAdminUser() {
const adminUserId = process.env.ADMIN_USER_ID;
const adminUsername = process.env.ADMIN_USERNAME;
const adminPassword = process.env.ADMIN_PASSWORD;
if (!adminUserId || !adminUsername || !adminPassword) {
console.error('Admin credentials are not set.');
process.exit(1);
}
await prismaClient.user.upsert({
where: { username: adminUsername },
update: {},
create: {
id: adminUserId,
username: adminUsername,
password: hashPassword(adminPassword),
role: 'admin',
},
});
console.log('Admin user seeded successfully.');
}
module.exports = {
seedAdminUser,
};