Générer des données pour une BDD, exemple Postgres

· 1 minute de lecture
Générer des données pour une BDD, exemple Postgres

CREATE TABLE IF NOT EXISTS user_info( 
    id text, 
    phone text, 
    name text, 
    job text, 
    address text 
);
CREATE TABLE IF NOT EXISTS payment_info( 
    id text, 
    account_number text, 
    intl_account_number text, 
    bank_country text 
);


from faker import Faker 

import uuid 

faker = Faker() 

# Remplacez cette plage par la valeur de votre 
choix ROW_COUNT = 1000000 

u_info = open('user_info.csv', 'w') 
acc_info = open('account_info.csv', 'w' ) 

for i in range(0, ROW_COUNT): 
    user_id = uuid.uuid4() 
    phone_number = faker.phone_number() 
    name = faker.name() 
    job = faker.job().replace(',', '') 
    adresse = faker.address().replace(',', '').replace('\n', '') 
    bank_country = faker.bank_country() 
    account_number = faker.bban() 
    intl_account_number = faker.iban() 

    user_info = f"'{user_id}','{phone_number}','{nom}','{job}','{adresse}' \n"
    account_info = f"'{user_id}','{account_number}','{bank_country}','{intl_account_number}' \n" 

    u_info.write(user_info) 
    acc_info.write(account_info) 

u_info.close() 
acc_info.close ()



COPY user_info(id, phone, name, job, address) FROM '/path/to/csv' DELIMITER ','; 

COPY payment_info(id, account_number, bank_country, intl_account_number) FROM '/path/to/csv' DELIMITER ',' ;