#!/usr/bin/python3 import uuid import sys global_id = 0 def gen_id(): global global_id global_id += 1 return global_id def gen_string(): return uuid.uuid4().hex def gen_account(): pkey = gen_id() print(""" insert into account ( id, name ) values ( %s, '%s' ); """ % ( pkey, gen_string() )) return pkey def gen_contact(): pkey = gen_id() print(""" insert into contact ( id, name, email ) values ( %s, '%s', '%s' ); """ % ( pkey, gen_string(), gen_string() )) return pkey def gen_relationship(account_id, contact_id, main): pkey = gen_id() print(""" insert into contactrelationship ( id, account_id, contact_id, main ) values ( %s, %s, %s, '%s' ); """ % ( pkey, account_id, contact_id, main and "t" or "f" )) return pkey def do_account(): account_id = gen_account() # Add 1 to ensure all accounts get a contact num_contacts = (gen_id() % 5) + 1 main = True for i in range(num_contacts): contact_id = gen_contact() gen_relationship(account_id, contact_id, main) main = False try: num_accounts = int(sys.argv[1]) except: sys.stderr.write("Usage: %s num_accounts\n" % sys.argv[0]) sys.exit(1) for i in range(num_accounts): do_account()