[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Question about import process from sql-ledger, and Rose::DB



Hi Everyone,

Two questions: 

1) Does anyone else here use Rose::DB objects with ledgerSMB?  I found the system extremely useful both for doing my initial import from SQL-Ledger, and for any other data manipulation or random tasks that need to get done here and there.  In order to use it you need to do a slightly labor-intensive setup process for each table, an example of which I've appended to the end of this message.  However, once you get this done, you have a perl object that you can work with without the need to write any more SQL queries -- coming from a C++ background, it feels very natural to me.  Once you have it running the interface looks like this:

    $Assembly = LedgerSMB::DB::Assembly->new(db => $newDB);
    $Assembly->parts_id($myPartID);
    $Assembly->qty($myQty);
    $Assembly->save;

With that I just created an assembly item and inserted it into the table.  As a newbie here, I'm wondering does everybody already use this, or is everybody fine without it, or would other people like to try it out?  Because I've done all the setup work and would be more than happy to share the perl modules if it would be of use to people.

2)  Second question, related to the first: when I did my import, I may have just missed the obvious way but I didn't really see an easy obvious script for grabbing everything out of my SQL Ledger database and converting it to LedgerSMB (grabbing addresses out of Address and stuffing them into Customer & Vendor, etc.).  At the same time, I had to do some cleanup to handle places where SQL-Ledger was less diligent than LS when it came to enforcing unique fields, etc.  I wrote a big function in am.pl called import_everything, which used the aforementioned Rose::DB objects to do get everything I needed and stuff it into the new database, and for the transition period I've hooked this up to a menu item so we can keep using SQL Ledger until we're ready, but easily grab all the data into LedgerSMB. 

So, the question here is, do people think this is generally useful code that others could use?  Again, more than happy to post it if it can help anyone out.

Thanks everybody, keep up the great work!

Chris Calef
<..hidden..>


-----------------------------------------------------

Rose::DB setup for Assembly table:


use base qw(LedgerSMB::DB::Object);

__PACKAGE__->meta->setup
(
  table   => 'assembly',

  columns =>
  [
    id       => { type => 'integer', not_null => 1 },
    parts_id => { type => 'integer', not_null => 1 },
    qty      => { type => 'numeric' },
    bom      => { type => 'boolean' },
    adj      => { type => 'boolean' },
  ],

  primary_key_columns => [ 'id', 'parts_id' ],

  relationships =>
  [
    component =>
    {
      type       => 'many to one',
      class      => 'LedgerSMB::DB::Part',
      column_map => { parts_id => 'id' },
    },
    assembly =>
    {
      type       => 'many to one',
      class      => 'LedgerSMB::DB::Part',
      column_map => { id => 'id' },
    },
  ],
);