Initial commit
This commit is contained in:
28
scripts/import_categories.js
Normal file
28
scripts/import_categories.js
Normal file
@ -0,0 +1,28 @@
|
||||
const PocketBase = require('pocketbase').default
|
||||
|
||||
// Initialize the PocketBase client
|
||||
const pb = new PocketBase('http://127.0.0.1:8090')
|
||||
|
||||
async function main () {
|
||||
try {
|
||||
// Authenticate as an admin
|
||||
await pb.admins.authWithPassword('karkinge@gmail.com', 'PBk4rk1ng3*') // Replace with your admin credentials
|
||||
|
||||
// Parse JSON file with categories
|
||||
const data = require('../../gyoza/database_backups/20250320.json')
|
||||
console.log(data.categories)
|
||||
|
||||
// Perform some operations, e.g., create a new record in the 'categories' collection
|
||||
for (let category of data.categories) {
|
||||
const newCategory = await pb.collection('categories').create({
|
||||
code: category.code,
|
||||
name: category.name
|
||||
})
|
||||
console.log('New category created:', newCategory)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error:', error)
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
37
scripts/import_history.js
Normal file
37
scripts/import_history.js
Normal file
@ -0,0 +1,37 @@
|
||||
const PocketBase = require('pocketbase').default
|
||||
|
||||
// Initialize the PocketBase client
|
||||
const pb = new PocketBase('http://127.0.0.1:8090')
|
||||
|
||||
async function main () {
|
||||
try {
|
||||
// Authenticate as an admin
|
||||
await pb.admins.authWithPassword('karkinge@gmail.com', 'PBk4rk1ng3*') // Replace with your admin credentials
|
||||
|
||||
// Parse JSON file with categories
|
||||
const data = require('../../gyoza/database_backups/20250320.json')
|
||||
|
||||
// Perform some operations, e.g., create a new record in the 'categories' collection
|
||||
for (let history of data.history) {
|
||||
if (!history) continue
|
||||
if (history.image) {
|
||||
// Extract the filename from a url like : "https://firebasestorage.googleapis.com/v0/b/gyoza-hfs-stock.appspot.com/o/1678571846485IMG_20230311_225636.jpg?alt=media&token=215c00a8-e873-497f-8f11-b75c7e2fab42"
|
||||
const filename = history.image.split('?')[0].split('/').pop()
|
||||
history.image = filename
|
||||
}
|
||||
let newData = {
|
||||
ref: history.ref,
|
||||
text: history.text,
|
||||
user: history.user,
|
||||
image: history.image,
|
||||
date: new Date(history.timestamp).toISOString()
|
||||
}
|
||||
console.log(newData)
|
||||
const newHistory = await pb.collection('history').create(newData)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error:', error)
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
37
scripts/import_history_files.js
Normal file
37
scripts/import_history_files.js
Normal file
@ -0,0 +1,37 @@
|
||||
const PocketBase = require('pocketbase').default
|
||||
const sharp = require('sharp')
|
||||
|
||||
// Initialize the PocketBase client
|
||||
const pb = new PocketBase('http://127.0.0.1:8090')
|
||||
|
||||
async function main () {
|
||||
try {
|
||||
// Authenticate as an admin
|
||||
await pb.admins.authWithPassword('karkinge@gmail.com', 'PBk4rk1ng3*') // Replace with your admin credentials
|
||||
|
||||
// Parse JSON file with categories
|
||||
const filesPath = '../gyoza/storage/'
|
||||
|
||||
// Get history collection
|
||||
const historyCollection = await pb.collection('history').getFullList({ filter: 'image_file = null' })
|
||||
for (let hist of historyCollection) {
|
||||
if (hist.image) {
|
||||
console.log(hist)
|
||||
let fullPath = filesPath + hist.image
|
||||
// Compress the image with a 80% quality
|
||||
const compressedImage = await sharp(fullPath)
|
||||
.resize({ width: 2000, height: 2000, fit: 'inside' })
|
||||
.jpeg({ quality: 80 })
|
||||
.toBuffer()
|
||||
|
||||
// Create a JS file object from the file's content
|
||||
const file = new File([compressedImage], hist.image)
|
||||
await pb.collection('history').update(hist.id, { image_file: file })
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error:', error)
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
36
scripts/import_stock.js
Normal file
36
scripts/import_stock.js
Normal file
@ -0,0 +1,36 @@
|
||||
const PocketBase = require('pocketbase').default
|
||||
|
||||
// Initialize the PocketBase client
|
||||
const pb = new PocketBase('http://127.0.0.1:8090')
|
||||
|
||||
async function main () {
|
||||
try {
|
||||
// Authenticate as an admin
|
||||
await pb.admins.authWithPassword('karkinge@gmail.com', 'PBk4rk1ng3*') // Replace with your admin credentials
|
||||
|
||||
// Parse JSON file with categories
|
||||
const data = require('../../gyoza/database_backups/20250320.json')
|
||||
console.log('Data ok:', data.categories)
|
||||
|
||||
// Perform some operations, e.g., create a new record in the 'categories' collection
|
||||
for (let stock of data.stock) {
|
||||
if (!stock) continue
|
||||
const newStock = await pb.collection('stock').create({
|
||||
available: stock.available,
|
||||
comment: stock.comment,
|
||||
deleted: stock.deleted,
|
||||
name: stock.name,
|
||||
owner: stock.owner,
|
||||
ref: stock.ref,
|
||||
state: stock.state,
|
||||
type: stock.type,
|
||||
working: stock.working
|
||||
})
|
||||
console.log('New stock created:', newStock)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error:', error)
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
Reference in New Issue
Block a user