Commit 94c05307 authored by mechtelm's avatar mechtelm
Browse files

Add data import for staff

parent 32824402
const { Pool } = require('pg');
const fs = require('fs');
require('dotenv').config({path: './docker.env'});
const staff_data = fs.readFileSync('staff_data.txt').toString();
const all_lines = staff_data.split(/\n/);
const pool = new Pool({
user: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD,
database: process.env.POSTGRES_DB,
host: 'localhost',
port: 5432,
max: all_lines.length
})
all_lines.forEach(line => {
if (line) {
const data = line.split('###');
let date_splits = data[4].split('.');
const start_date = "Date('" + date_splits[2] + '-' + date_splits[1] + '-' + date_splits[0] + "')";
let end_date = "";
if (data[5] !== 'unbefristet') {
date_splits = data[5].split('.');
end_date = "Date('" + date_splits[2] + '-' + date_splits[1] + '-' + date_splits[0] + "')";
}
if (end_date) {
const valuesString = "'" + data[2] + "', '" + data[3] + "', '" + data[0] + "', " + start_date + ", " + end_date + ", '" + data[1] + "'";
const sql = 'INSERT INTO public.staff (name, surname, contract_type, contract_start, contract_end, cms_id) VALUES (' + valuesString + ');';
pool.query(sql, function(err, result){
console.log(err, result);
});
} else {
console.log('###');
const valuesString = "'" + data[2] + "', '" + data[3] + "', '" + data[0] + "', " + start_date + ", '" + data[1] + "'";
const sql = 'INSERT INTO public.staff (name, surname, contract_type, contract_start, cms_id) VALUES (' + valuesString + ');';
pool.query(sql, function(err, result){
console.log(err, result);
});
}
}
});
pool.end()
IQB-Vertrag###9648000363###Yung###Phong###01.11.2015###30.04.2024
IQB-Vertrag###9648000564###Schneider###Wolfgang###01.01.2014###unbefristet
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment