3.x upgrade vs. tax-pkg_address, #30413
[freeside.git] / bin / freeside.import
1 #!/usr/bin/perl -w
2
3 use strict;
4 use DBI;
5
6 my $s_datasrc = 'DBI:mysql:host=ns1.enetonline.net;port=3307;user=ivan;dbname=freeside';
7 my $s_dbuser = 'ivan';
8 my $s_dbpass = '';
9
10 my $d_datasrc = 'DBI:Pg:dbname=freeside';
11 my $d_dbuser = 'freeside';
12 my $d_dbpass = '';
13
14 #my @tables = qw(
15 #addr_block
16 #agent
17 #agent_type
18 #cust_bill
19 #cust_bill_event
20 #cust_bill_pay
21 #cust_bill_pkg
22 #cust_bill_pkg_detail
23 #cust_credit
24 #cust_credit_bill
25 #cust_credit_refund
26 #cust_main
27 #cust_main_county
28 #cust_main_invoice
29 #cust_pay
30 #cust_pay_batch
31 #cust_pkg
32 #cust_refund
33 #cust_svc
34 #cust_tax_exempt
35 #domain_record
36 #export_svc
37 #h_addr_block
38 #h_agent
39 #h_agent_type
40 #h_cust_bill
41 #h_cust_bill_event
42 #h_cust_bill_pay
43 #h_cust_bill_pkg
44 #h_cust_bill_pkg_detail
45 #h_cust_credit
46 #h_cust_credit_bill
47 #h_cust_credit_refund
48 #h_cust_main
49 #h_cust_main_county
50 #h_cust_main_invoice
51 #h_cust_pay
52 #h_cust_pay_batch
53 #h_cust_pkg
54 #h_cust_refund
55 #h_cust_svc
56 #h_cust_tax_exempt
57 #h_domain_record
58 #h_export_svc
59 #h_msgcat
60 #h_nas
61 #h_part_bill_event
62 #h_part_export
63 #h_part_export_option
64 #h_part_pkg
65 #h_part_pop_local
66 #h_part_referral
67 #h_part_svc
68 #h_part_svc_column
69 #h_part_svc_router
70 #h_pkg_svc
71 #h_port
72 #h_prepay_credit
73 #h_queue
74 #h_queue_arg
75 #h_queue_depend
76 #h_radius_usergroup
77 #h_router
78 #h_router_field
79 #h_sb_field
80 #h_session
81 #h_svc_acct
82 #h_svc_acct_pop
83 #h_svc_broadband
84 #h_svc_domain
85 #h_svc_forward
86 #h_svc_www
87 #h_type_pkgs
88 #msgcat
89 #nas
90 #part_bill_event
91 #part_export
92 #part_export_option
93 #part_pkg
94
95 my @tables = qw(
96 part_pop_local
97 part_referral
98 part_router_field
99 part_sb_field
100 part_svc
101 part_svc_column
102 part_svc_router
103 pkg_svc
104 port
105 prepay_credit
106 queue
107 queue_arg
108 queue_depend
109 radius_usergroup
110 router
111 router_field
112 sb_field
113 session
114 svc_acct
115 svc_acct_pop
116 svc_broadband
117 svc_domain
118 svc_forward
119 svc_www
120 type_pkgs
121 );
122
123 my $s_dbh = DBI->connect($s_datasrc, $s_dbuser, $s_dbpass) or die $DBI::errstr;
124 my $d_dbh = DBI->connect($d_datasrc, $d_dbuser, $d_dbpass) or die $DBI::errstr;
125
126 foreach my $table ( @tables ) {
127   $d_dbh->do("delete from $table");
128
129   my $s_sth = $s_dbh->prepare("select * from $table");
130   $s_sth->execute or die $s_sth->errstr;
131
132   my $row;
133   while ( $row = $s_sth->fetchrow_arrayref ) {
134     my $d_sth = $d_dbh->prepare(
135       "insert into $table ( ".
136         join(', ', @{$s_sth->{NAME}} ).
137         ' ) VALUES ( '.
138         join(', ', map { '?' } @{$s_sth->{NAME}} ). 
139         ' )'
140     ) or die $d_dbh->errstr;
141
142     $d_sth->execute(@$row) or die $d_sth->errstr;
143
144   }
145 }
146