remove keycloak
This commit is contained in:
68
bizmatch-server/src/drizzle/importFromExported.ts
Normal file
68
bizmatch-server/src/drizzle/importFromExported.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import 'dotenv/config';
|
||||
import { drizzle } from 'drizzle-orm/node-postgres';
|
||||
import { readFileSync } from 'fs';
|
||||
import { Pool } from 'pg';
|
||||
import { BusinessListingService } from 'src/listings/business-listing.service';
|
||||
import { CommercialPropertyService } from 'src/listings/commercial-property.service';
|
||||
import { UserService } from 'src/user/user.service';
|
||||
import winston from 'winston';
|
||||
import { BusinessListing, CommercialPropertyListing, User } from '../models/db.model';
|
||||
import * as schema from './schema';
|
||||
|
||||
(async () => {
|
||||
const connectionString = process.env.DATABASE_URL;
|
||||
const client = new Pool({ connectionString });
|
||||
const db = drizzle(client, { schema, logger: true });
|
||||
const logger = winston.createLogger({
|
||||
transports: [new winston.transports.Console()],
|
||||
});
|
||||
const commService = new CommercialPropertyService(null, db);
|
||||
const businessService = new BusinessListingService(null, db);
|
||||
const userService = new UserService(null, db, null, null);
|
||||
|
||||
//Delete Content
|
||||
await db.delete(schema.commercials);
|
||||
await db.delete(schema.businesses);
|
||||
await db.delete(schema.users);
|
||||
|
||||
let filePath = `./data/users_export.json`;
|
||||
let data: string = readFileSync(filePath, 'utf8');
|
||||
const usersData: User[] = JSON.parse(data); // Erwartet ein Array von Objekten
|
||||
for (let index = 0; index < usersData.length; index++) {
|
||||
const user = usersData[index];
|
||||
delete user.id;
|
||||
const u = await userService.saveUser(user, false);
|
||||
logger.info(`user_${index} inserted`);
|
||||
}
|
||||
|
||||
//Corporate Listings
|
||||
filePath = `./data/commercials_export.json`;
|
||||
data = readFileSync(filePath, 'utf8');
|
||||
const commercialJsonData = JSON.parse(data) as CommercialPropertyListing[]; // Erwartet ein Array von Objekten
|
||||
for (let index = 0; index < commercialJsonData.length; index++) {
|
||||
const commercial = commercialJsonData[index];
|
||||
delete commercial.id;
|
||||
const result = await commService.createListing(commercial);
|
||||
}
|
||||
|
||||
//Business Listings
|
||||
filePath = `./data/businesses_export.json`;
|
||||
data = readFileSync(filePath, 'utf8');
|
||||
const businessJsonData = JSON.parse(data) as BusinessListing[]; // Erwartet ein Array von Objekten
|
||||
for (let index = 0; index < businessJsonData.length; index++) {
|
||||
const business = businessJsonData[index];
|
||||
delete business.id;
|
||||
await businessService.createListing(business);
|
||||
}
|
||||
|
||||
//End
|
||||
await client.end();
|
||||
})();
|
||||
function getRandomItem<T>(arr: T[]): T {
|
||||
if (arr.length === 0) {
|
||||
throw new Error('The array is empty.');
|
||||
}
|
||||
|
||||
const randomIndex = Math.floor(Math.random() * arr.length);
|
||||
return arr[randomIndex];
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import 'dotenv/config';
|
||||
import { drizzle } from 'drizzle-orm/node-postgres';
|
||||
import pkg from 'pg';
|
||||
import * as schema from './schema';
|
||||
const { Pool } = pkg;
|
||||
const connectionString = process.env.DATABASE_URL;
|
||||
const pool = new Pool({ connectionString });
|
||||
const db = drizzle(pool, { schema });
|
||||
// This will run migrations on the database, skipping the ones already applied
|
||||
//await migrate(db, { migrationsFolder: './src/drizzle/migrations' });
|
||||
// Don't forget to close the connection, otherwise the script will hang
|
||||
//await pool.end();
|
||||
Reference in New Issue
Block a user