need an DBIx::DBSchema with delcolumn
[freeside.git] / bin / fs-setup
1 #!/usr/bin/perl -Tw
2 #
3 # $Id: fs-setup,v 1.39 2001-07-30 07:42:39 ivan Exp $
4 #
5 # ivan@sisd.com 97-nov-8,9
6 #
7 # agent_type and type_pkgs added.
8 # (index need to be declared, & primary keys shoudln't have mysql syntax)
9 # ivan@sisd.com 97-nov-13
10 #
11 # pulled modified version back out of register.cgi ivan@sisd.com 98-feb-21
12 #
13 # removed extraneous sample data ivan@sisd.com 98-mar-23
14 #
15 # gained the big hash from dbdef.pm, dbdef.pm usage rewrite ivan@sisd.com
16 # 98-apr-19 - 98-may-11 plus
17 #
18 # finished up ivan@sisd.com 98-jun-1
19 #
20 # part_svc fields are all forced NULL, not the opposite
21 # hmm: also are forced varchar($char_d) as fixed '0' for things like
22 # uid is Not Good.  will this break anything else?
23 # ivan@sisd.com 98-jun-29
24 #
25 # ss is 11 chars ivan@sisd.com 98-jul-20
26 #
27 # setup of arbitrary radius fields ivan@sisd.com 98-aug-9
28 #
29 # ouch, removed index on company name that wasn't supposed to be there
30 # ivan@sisd.com 98-sep-4
31 #
32 # fix radius attributes ivan@sisd.com 98-sep-27
33 #
34 # $Log: fs-setup,v $
35 # Revision 1.39  2001-07-30 07:42:39  ivan
36 # need an DBIx::DBSchema with delcolumn
37 #
38 # Revision 1.38  2001/07/30 07:36:04  ivan
39 # templates!!!
40 #
41 # Revision 1.37  2001/06/03 14:16:11  ivan
42 # allow empty refund reasons
43 #
44 # Revision 1.36  2001/04/15 12:56:31  ivan
45 # s/dbdef/DBIx::DBSchema/
46 #
47 # Revision 1.35  2001/04/15 09:36:43  ivan
48 # http://www.sisd.com/freeside/list-archive/msg01450.html
49 #
50 # Revision 1.34  2001/04/09 23:05:16  ivan
51 # Transactions Part I!!!
52 #
53 # Revision 1.33  2001/02/03 14:03:50  ivan
54 # time-based prepaid cards, session monitor.  woop!
55 #
56 # Revision 1.32  2000/12/04 00:13:02  ivan
57 # fix nas.last type
58 #
59 # Revision 1.31  2000/12/01 18:34:53  ivan
60 # another tyop
61 #
62 # Revision 1.30  2000/12/01 18:33:32  ivan
63 # tyop
64 #
65 # Revision 1.29  2000/11/07 15:00:37  ivan
66 # session monitor
67 #
68 # Revision 1.28  2000/10/30 10:47:26  ivan
69 # nas.last can't be defined NULL if indexed
70 #
71 # Revision 1.26  2000/07/06 08:57:27  ivan
72 # support for radius check attributes (except importing).  poorly documented.
73 #
74 # Revision 1.25  2000/06/29 12:00:49  ivan
75 # support for pre-encrypted md5 passwords.
76 #
77 # Revision 1.24  2000/03/02 07:44:07  ivan
78 # typo forgot closing '
79 #
80 # Revision 1.23  2000/02/03 05:16:52  ivan
81 # beginning of DNS and Apache support
82 #
83 # Revision 1.22  2000/01/31 05:22:23  ivan
84 # prepaid "internet cards"
85 #
86 # Revision 1.21  2000/01/30 06:03:26  ivan
87 # postgres 6.5 finally supports decimal(10,2)
88 #
89 # Revision 1.20  2000/01/28 22:53:33  ivan
90 # track full phone number
91 #
92 # Revision 1.19  1999/07/29 08:50:35  ivan
93 # wrong type for cust_pay_batch.exp
94 #
95 # Revision 1.18  1999/04/15 22:46:30  ivan
96 # TT isn't a state!
97 #
98 # Revision 1.17  1999/04/14 07:58:39  ivan
99 # export getsecrets from FS::UID instead of calling it explicitly
100 #
101 # Revision 1.16  1999/02/28 19:44:16  ivan
102 # constructors s/create/new/ pointed out by "Bao C. Ha" <bao@hacom.net>
103 #
104 # Revision 1.15  1999/02/27 21:06:21  ivan
105 # cust_main.paydate should be varchar(10), not @date_type ; problem reported
106 # by Ben Leibig <leibig@colorado.edu>
107 #
108 # Revision 1.14  1999/02/07 09:59:14  ivan
109 # more mod_perl fixes, and bugfixes Peter Wemm sent via email
110 #
111 # Revision 1.13  1999/02/04 06:09:23  ivan
112 # add AU provences
113 #
114 # Revision 1.12  1999/02/03 10:42:27  ivan
115 # *** empty log message ***
116 #
117 # Revision 1.11  1999/01/17 03:11:52  ivan
118 # remove preliminary completehost changes
119 #
120 # Revision 1.10  1998/12/16 06:05:38  ivan
121 # add table cust_main_invoice
122 #
123 # Revision 1.9  1998/12/15 04:36:29  ivan
124 # s/croak/die/; #oops
125 #
126 # Revision 1.8  1998/12/15 04:33:27  ivan
127 # dies if it isn't running as the freeside user
128 #
129 # Revision 1.7  1998/11/18 09:01:31  ivan
130 # i18n! i18n!
131 #
132 # Revision 1.6  1998/11/15 13:18:02  ivan
133 # remove debugging
134 #
135 # Revision 1.5  1998/11/15 09:43:03  ivan
136 # update for new config file syntax, new adminsuidsetup
137 #
138 # Revision 1.4  1998/10/22 15:51:23  ivan
139 # also varchar with no length specified - postgresql fix broke mysql.
140 #
141 # Revision 1.3  1998/10/22 15:46:28  ivan
142 # now smallint is illegal, so remove that too.
143 #
144
145 #to delay loading dbdef until we're ready
146 BEGIN { $FS::Record::setup_hack = 1; }
147
148 use strict;
149 use DBI;
150 use DBIx::DBSchema 0.18;
151 use DBIx::DBSchema::Table;
152 use DBIx::DBSchema::Column;
153 use DBIx::DBSchema::ColGroup::Unique;
154 use DBIx::DBSchema::ColGroup::Index;
155 use FS::UID qw(adminsuidsetup datasrc checkeuid getsecrets);
156 use FS::Record;
157 use FS::cust_main_county;
158
159 die "Not running uid freeside!" unless checkeuid();
160
161 my $user = shift or die &usage;
162 getsecrets($user);
163
164 #needs to match FS::Record
165 my($dbdef_file) = "/usr/local/etc/freeside/dbdef.". datasrc;
166
167 ###
168
169 print "\nEnter the maximum username length: ";
170 my($username_len)=&getvalue;
171
172 print "\n\n", <<END, ":";
173 Freeside tracks the RADIUS attributes User-Name, check attribute Password and
174 reply attribute Framed-IP-Address for each user.  You can specify additional
175 check and reply attributes.  First enter any additional RADIUS check attributes
176 you need to track for each user, separated by whitespace.
177 END
178 my @check_attributes = map { s/\-/_/g; $_; } split(" ",&getvalue);
179
180 print "\n\n", <<END, ":";
181 Now enter any additional reply attributes you need to track for each user,
182 separated by whitespace.
183 END
184 my @attributes = map { s/\-/_/g; $_; } split(" ",&getvalue);
185
186 print "\n\n", <<END, ":";
187 Do you wish to enable the tracking of a second, separate shipping/service
188 address?
189 END
190 my $ship = &_yesno;
191
192 sub getvalue {
193   my($x)=scalar(<STDIN>);
194   chop $x;
195   $x;
196 }
197
198 sub _yesno {
199   print " [y/N]:";
200   my $x = scalar(<STDIN>);
201   $x =~ /^y/i;
202 }
203
204 ###
205
206 my($char_d) = 80; #default maxlength for text fields
207
208 #my(@date_type)  = ( 'timestamp', '', ''     );
209 my(@date_type)  = ( 'int', 'NULL', ''     );
210 my(@perl_type) = ( 'varchar', 'NULL', 255  ); 
211 my @money_type = ( 'decimal',   '', '10,2' );
212
213 ###
214 # create a dbdef object from the old data structure
215 ###
216
217 my(%tables)=&tables_hash_hack;
218
219 #turn it into objects
220 my($dbdef) = new DBIx::DBSchema ( map {  
221   my(@columns);
222   while (@{$tables{$_}{'columns'}}) {
223     my($name,$type,$null,$length)=splice @{$tables{$_}{'columns'}}, 0, 4;
224     push @columns, new DBIx::DBSchema::Column ( $name,$type,$null,$length );
225   }
226   DBIx::DBSchema::Table->new(
227     $_,
228     $tables{$_}{'primary_key'},
229     DBIx::DBSchema::ColGroup::Unique->new($tables{$_}{'unique'}),
230     DBIx::DBSchema::ColGroup::Index->new($tables{$_}{'index'}),
231     @columns,
232   );
233 } (keys %tables) );
234
235 #remove ship_ from cust_main
236 unless ($ship) {
237   my $cust_main = $dbdef->table('cust_main');
238   $cust_main->delcolumn($_) foreach ( grep /^ship_/, $cust_main->columns );
239 }
240
241 #add radius attributes to svc_acct
242
243 my($svc_acct)=$dbdef->table('svc_acct');
244
245 my($attribute);
246 foreach $attribute (@attributes) {
247   $svc_acct->addcolumn ( new DBIx::DBSchema::Column (
248     'radius_'. $attribute,
249     'varchar',
250     'NULL',
251     $char_d,
252   ));
253 }
254
255 foreach $attribute (@check_attributes) {
256   $svc_acct->addcolumn( new DBIx::DBSchema::Column (
257     'rc_'. $attribute,
258     'varchar',
259     'NULL',
260     $char_d,
261   ));
262 }
263
264 #make part_svc table (but now as object)
265
266 my($part_svc)=$dbdef->table('part_svc');
267
268 #because of svc_acct_pop
269 #foreach (grep /^svc_/, $dbdef->tables) { 
270 #foreach (qw(svc_acct svc_acct_sm svc_charge svc_domain svc_wo)) {
271 foreach (qw(svc_acct svc_acct_sm svc_domain svc_www)) {
272   my($table)=$dbdef->table($_);
273   my($col);
274   foreach $col ( $table->columns ) {
275     next if $col =~ /^svcnum$/;
276     $part_svc->addcolumn( new DBIx::DBSchema::Column (
277       $table->name. '__' . $table->column($col)->name,
278       'varchar', #$table->column($col)->type, 
279       'NULL',
280       $char_d, #$table->column($col)->length,
281     ));
282     $part_svc->addcolumn ( new DBIx::DBSchema::Column (
283       $table->name. '__'. $table->column($col)->name . "_flag",
284       'char',
285       'NULL',
286       1,
287     ));
288   }
289 }
290
291 #important
292 $dbdef->save($dbdef_file);
293 &FS::Record::reload_dbdef($dbdef_file);
294
295 ###
296 # create 'em
297 ###
298
299 my($dbh)=adminsuidsetup $user;
300
301 #create tables
302 $|=1;
303
304 my @sql = $dbdef->sql($dbh);
305 foreach my $statement ( $dbdef->sql($dbh) ) {
306   $dbh->do( $statement )
307     or die "CREATE error: ",$dbh->errstr, "\ndoing statement: $statement";
308 }
309
310 #not really sample data (and shouldn't default to US)
311
312 #cust_main_county
313
314 #USPS state codes
315 foreach ( qw(
316 AL AK AS AZ AR CA CO CT DC DE FM FL GA GU HI ID IL IN IA KS KY LA
317 ME MH MD MA MI MN MS MO MT NC ND NE NH NJ NM NV NY MP OH OK OR PA PW PR RI 
318 SC SD TN TX UT VT VI VA WA WV WI WY AE AA AP
319 ) ) {
320   my($cust_main_county)=new FS::cust_main_county({
321     'state' => $_,
322     'tax'   => 0,
323     'country' => 'US',
324   });  
325   my($error);
326   $error=$cust_main_county->insert;
327   die $error if $error;
328 }
329
330 #AU "offical" state codes ala mark.williamson@ebbs.com.au (Mark Williamson)
331 foreach ( qw(
332 VIC NSW NT QLD TAS ACT WA SA
333 ) ) {
334   my($cust_main_county)=new FS::cust_main_county({
335     'state' => $_,
336     'tax'   => 0,
337     'country' => 'AU',
338   });  
339   my($error);
340   $error=$cust_main_county->insert;
341   die $error if $error;
342 }
343
344 #ISO 2-letter country codes (same as country TLDs) except US and AU
345 foreach ( qw(
346 AF AL DZ AS AD AO AI AQ AG AR AM AW AT AZ BS BH BD BB BY BE BZ BJ BM BT BO
347 BA BW BV BR IO BN BG BF BI KH CM CA CV KY CF TD CL CN CX CC CO KM CG CK CR CI
348 HR CU CY CZ DK DJ DM DO TP EC EG SV GQ ER EE ET FK FO FJ FI FR FX GF PF TF GA
349 GM GE DE GH GI GR GL GD GP GU GT GN GW GY HT HM HN HK HU IS IN ID IR IQ IE IL
350 IT JM JP JO KZ KE KI KP KR KW KG LA LV LB LS LR LY LI LT LU MO MK MG MW MY MV
351 ML MT MH MQ MR MU YT MX FM MD MC MN MS MA MZ MM NA NR NP NL AN NC NZ NI NE NG
352 NU NF MP NO OM PK PW PA PG PY PE PH PN PL PT PR QA RE RO RU RW KN LC VC WS SM
353 ST SA SN SC SL SG SK SI SB SO ZA GS ES LK SH PM SD SR SJ SZ SE CH SY TW TJ TZ
354 TH TG TK TO TT TN TR TM TC TV UG UA AE GB UM UY UZ VU VA VE VN VG VI WF EH
355 YE YU ZR ZM ZW
356 ) ) {
357   my($cust_main_county)=new FS::cust_main_county({
358     'tax'   => 0,
359     'country' => $_,
360   });  
361   my($error);
362   $error=$cust_main_county->insert;
363   die $error if $error;
364 }
365
366 $dbh->disconnect or die $dbh->errstr;
367
368 print "Freeside database initialized sucessfully\n";
369
370 sub usage {
371   die "Usage:\n  fs-setup user\n"; 
372 }
373
374 ###
375 # Now it becomes an object.  much better.
376 ###
377 sub tables_hash_hack {
378
379   #note that s/(date|change)/_$1/; to avoid keyword conflict.
380   #put a kludge in FS::Record to catch this or? (pry need some date-handling
381   #stuff anyway also)
382
383   my(%tables)=( #yech.}
384
385     'agent' => {
386       'columns' => [
387         'agentnum', 'int',            '',     '',
388         'agent',    'varchar',           '',     $char_d,
389         'typenum',  'int',            '',     '',
390         'freq',     'int',       'NULL', '',
391         'prog',     @perl_type,
392       ],
393       'primary_key' => 'agentnum',
394       'unique' => [ [] ],
395       'index' => [ ['typenum'] ],
396     },
397
398     'agent_type' => {
399       'columns' => [
400         'typenum',   'int',  '', '',
401         'atype',     'varchar', '', $char_d,
402       ],
403       'primary_key' => 'typenum',
404       'unique' => [ [] ],
405       'index' => [ [] ],
406     },
407
408     'type_pkgs' => {
409       'columns' => [
410         'typenum',   'int',  '', '',
411         'pkgpart',   'int',  '', '',
412       ],
413       'primary_key' => '',
414       'unique' => [ ['typenum', 'pkgpart'] ],
415       'index' => [ ['typenum'] ],
416     },
417
418     'cust_bill' => {
419       'columns' => [
420         'invnum',    'int',  '', '',
421         'custnum',   'int',  '', '',
422         '_date',     @date_type,
423         'charged',   @money_type,
424         'printed',   'int',  '', '',
425       ],
426       'primary_key' => 'invnum',
427       'unique' => [ [] ],
428       'index' => [ ['custnum'] ],
429     },
430
431     'cust_bill_pkg' => {
432       'columns' => [
433         'pkgnum',  'int', '', '',
434         'invnum',  'int', '', '',
435         'setup',   @money_type,
436         'recur',   @money_type,
437         'sdate',   @date_type,
438         'edate',   @date_type,
439       ],
440       'primary_key' => '',
441       'unique' => [ ['pkgnum', 'invnum'] ],
442       'index' => [ ['invnum'] ],
443     },
444
445     'cust_credit' => {
446       'columns' => [
447         'crednum',  'int', '', '',
448         'custnum',  'int', '', '',
449         '_date',    @date_type,
450         'amount',   @money_type,
451         'otaker',   'varchar', '', 8,
452         'reason',   'varchar', 'NULL', 255,
453       ],
454       'primary_key' => 'crednum',
455       'unique' => [ [] ],
456       'index' => [ ['custnum'] ],
457     },
458
459     'cust_main' => {
460       'columns' => [
461         'custnum',  'int',  '',     '',
462         'agentnum', 'int',  '',     '',
463 #        'titlenum', 'int',  'NULL',   '',
464         'last',     'varchar', '',     $char_d,
465 #        'middle',   'varchar', 'NULL', $char_d,
466         'first',    'varchar', '',     $char_d,
467         'ss',       'char', 'NULL', 11,
468         'company',  'varchar', 'NULL', $char_d,
469         'address1', 'varchar', '',     $char_d,
470         'address2', 'varchar', 'NULL', $char_d,
471         'city',     'varchar', '',     $char_d,
472         'county',   'varchar', 'NULL', $char_d,
473         'state',    'varchar', 'NULL', $char_d,
474         'zip',      'varchar', '',     10,
475         'country',  'char', '',     2,
476         'daytime',  'varchar', 'NULL', 20,
477         'night',    'varchar', 'NULL', 20,
478         'fax',      'varchar', 'NULL', 12,
479         'ship_last',     'varchar', 'NULL', $char_d,
480 #        'ship_middle',   'varchar', 'NULL', $char_d,
481         'ship_first',    'varchar', 'NULL', $char_d,
482         'ship_company',  'varchar', 'NULL', $char_d,
483         'ship_address1', 'varchar', 'NULL', $char_d,
484         'ship_address2', 'varchar', 'NULL', $char_d,
485         'ship_city',     'varchar', 'NULL', $char_d,
486         'ship_county',   'varchar', 'NULL', $char_d,
487         'ship_state',    'varchar', 'NULL', $char_d,
488         'ship_zip',      'varchar', 'NULL', 10,
489         'ship_country',  'char', 'NULL', 2,
490         'ship_daytime',  'varchar', 'NULL', 20,
491         'ship_night',    'varchar', 'NULL', 20,
492         'ship_fax',      'varchar', 'NULL', 12,
493         'payby',    'char', '',     4,
494         'payinfo',  'varchar', 'NULL', 16,
495         #'paydate',  @date_type,
496         'paydate',  'varchar', 'NULL', 10,
497         'payname',  'varchar', 'NULL', $char_d,
498         'tax',      'char', 'NULL', 1,
499         'otaker',   'varchar', '',     8,
500         'refnum',   'int',  '',     '',
501       ],
502       'primary_key' => 'custnum',
503       'unique' => [ [] ],
504       #'index' => [ ['last'], ['company'] ],
505       'index' => [ ['last'], ],
506     },
507
508     'cust_main_invoice' => {
509       'columns' => [
510         'destnum',  'int',  '',     '',
511         'custnum',  'int',  '',     '',
512         'dest',     'varchar', '',  $char_d,
513       ],
514       'primary_key' => 'destnum',
515       'unique' => [ [] ],
516       'index' => [ ['custnum'], ],
517     },
518
519     'cust_main_county' => { #county+state+country are checked off the
520                             #cust_main_county for validation and to provide
521                             # a tax rate.
522       'columns' => [
523         'taxnum',   'int',   '',    '',
524         'state',    'varchar',  'NULL',    $char_d,
525         'county',   'varchar',  'NULL',    $char_d,
526         'country',  'char',  '', 2, 
527         'tax',      'real',  '',    '', #tax %
528       ],
529       'primary_key' => 'taxnum',
530       'unique' => [ [] ],
531   #    'unique' => [ ['taxnum'], ['state', 'county'] ],
532       'index' => [ [] ],
533     },
534
535     'cust_pay' => {
536       'columns' => [
537         'paynum',   'int',    '',   '',
538         'invnum',   'int',    '',   '',
539         'paid',     @money_type,
540         '_date',    @date_type,
541         'payby',    'char',   '',     4, # CARD/BILL/COMP, should be index into
542                                          # payment type table.
543         'payinfo',  'varchar',   'NULL', 16,  #see cust_main above
544         'paybatch', 'varchar',   'NULL', $char_d, #for auditing purposes.
545       ],
546       'primary_key' => 'paynum',
547       'unique' => [ [] ],
548       'index' => [ ['invnum'] ],
549     },
550
551     'cust_pay_batch' => { #what's this used for again?  list of customers
552                           #in current CARD batch? (necessarily CARD?)
553       'columns' => [
554         'invnum',   'int',    '',   '',
555         'custnum',   'int',    '',   '',
556         'last',     'varchar', '',     $char_d,
557         'first',    'varchar', '',     $char_d,
558         'address1', 'varchar', '',     $char_d,
559         'address2', 'varchar', 'NULL', $char_d,
560         'city',     'varchar', '',     $char_d,
561         'state',    'varchar', '',     $char_d,
562         'zip',      'varchar', '',     10,
563         'country',  'char', '',     2,
564         'trancode', 'int', '', '',
565         'cardnum',  'varchar', '',     16,
566         #'exp',      @date_type,
567         'exp',      'varchar', '',     11,
568         'payname',  'varchar', 'NULL', $char_d,
569         'amount',   @money_type,
570       ],
571       'primary_key' => '',
572       'unique' => [ [] ],
573       'index' => [ ['invnum'], ['custnum'] ],
574     },
575
576     'cust_pkg' => {
577       'columns' => [
578         'pkgnum',    'int',    '',   '',
579         'custnum',   'int',    '',   '',
580         'pkgpart',   'int',    '',   '',
581         'otaker',    'varchar', '', 8,
582         'setup',     @date_type,
583         'bill',      @date_type,
584         'susp',      @date_type,
585         'cancel',    @date_type,
586         'expire',    @date_type,
587       ],
588       'primary_key' => 'pkgnum',
589       'unique' => [ [] ],
590       'index' => [ ['custnum'] ],
591     },
592
593     'cust_refund' => {
594       'columns' => [
595         'refundnum',    'int',    '',   '',
596         'crednum',      'int',    '',   '',
597         '_date',        @date_type,
598         'refund',       @money_type,
599         'otaker',       'varchar',   '',   8,
600         'reason',       'varchar',   '',   $char_d,
601         'payby',        'char',   '',     4, # CARD/BILL/COMP, should be index
602                                              # into payment type table.
603         'payinfo',      'varchar',   'NULL', 16,  #see cust_main above
604       ],
605       'primary_key' => 'refundnum',
606       'unique' => [ [] ],
607       'index' => [ ['crednum'] ],
608     },
609
610     'cust_svc' => {
611       'columns' => [
612         'svcnum',    'int',    '',   '',
613         'pkgnum',    'int',    'NULL',   '',
614         'svcpart',   'int',    '',   '',
615       ],
616       'primary_key' => 'svcnum',
617       'unique' => [ [] ],
618       'index' => [ ['svcnum'], ['pkgnum'], ['svcpart'] ],
619     },
620
621     'part_pkg' => {
622       'columns' => [
623         'pkgpart',    'int',    '',   '',
624         'pkg',        'varchar',   '',   $char_d,
625         'comment',    'varchar',   '',   $char_d,
626         'setup',      @perl_type,
627         'freq',       'int', '', '',  #billing frequency (months)
628         'recur',      @perl_type,
629       ],
630       'primary_key' => 'pkgpart',
631       'unique' => [ [] ],
632       'index' => [ [] ],
633     },
634
635 #    'part_title' => {
636 #      'columns' => [
637 #        'titlenum',   'int',    '',   '',
638 #        'title',      'varchar',   '',   $char_d,
639 #      ],
640 #      'primary_key' => 'titlenum',
641 #      'unique' => [ [] ],
642 #      'index' => [ [] ],
643 #    },
644
645     'pkg_svc' => {
646       'columns' => [
647         'pkgpart',    'int',    '',   '',
648         'svcpart',    'int',    '',   '',
649         'quantity',   'int',    '',   '',
650       ],
651       'primary_key' => '',
652       'unique' => [ ['pkgpart', 'svcpart'] ],
653       'index' => [ ['pkgpart'] ],
654     },
655
656     'part_referral' => {
657       'columns' => [
658         'refnum',   'int',    '',   '',
659         'referral', 'varchar',   '',   $char_d,
660       ],
661       'primary_key' => 'refnum',
662       'unique' => [ [] ],
663       'index' => [ [] ],
664     },
665
666     'part_svc' => {
667       'columns' => [
668         'svcpart',    'int',    '',   '',
669         'svc',        'varchar',   '',   $char_d,
670         'svcdb',      'varchar',   '',   $char_d,
671       ],
672       'primary_key' => 'svcpart',
673       'unique' => [ [] ],
674       'index' => [ [] ],
675     },
676
677     #(this should be renamed to part_pop)
678     'svc_acct_pop' => {
679       'columns' => [
680         'popnum',    'int',    '',   '',
681         'city',      'varchar',   '',   $char_d,
682         'state',     'varchar',   '',   $char_d,
683         'ac',        'char',   '',   3,
684         'exch',      'char',   '',   3,
685         'loc',       'char',   'NULL',   4, #NULL for legacy purposes
686       ],
687       'primary_key' => 'popnum',
688       'unique' => [ [] ],
689       'index' => [ [] ],
690     },
691
692     'svc_acct' => {
693       'columns' => [
694         'svcnum',    'int',    '',   '',
695         'username',  'varchar',   '',   $username_len, #unique (& remove dup code)
696         '_password', 'varchar',   '',   50, #13 for encryped pw's plus ' *SUSPENDED* (mp5 passwords can be 34)
697         'popnum',    'int',    'NULL',   '',
698         'uid',       'int', 'NULL',   '',
699         'gid',       'int', 'NULL',   '',
700         'finger',    'varchar',   'NULL',   $char_d,
701         'dir',       'varchar',   'NULL',   $char_d,
702         'shell',     'varchar',   'NULL',   $char_d,
703         'quota',     'varchar',   'NULL',   $char_d,
704         'slipip',    'varchar',   'NULL',   15, #four TINYINTs, bah.
705         'seconds',   'int', 'NULL',   '', #uhhhh
706       ],
707       'primary_key' => 'svcnum',
708       'unique' => [ [] ],
709       'index' => [ ['username'] ],
710     },
711
712     'svc_acct_sm' => {
713       'columns' => [
714         'svcnum',    'int',    '',   '',
715         'domsvc',    'int',    '',   '',
716         'domuid',    'int', '',   '',
717         'domuser',   'varchar',   '',   $char_d,
718       ],
719       'primary_key' => 'svcnum',
720       'unique' => [ [] ],
721       'index' => [ ['domsvc'], ['domuid'] ], 
722     },
723
724     #'svc_charge' => {
725     #  'columns' => [
726     #    'svcnum',    'int',    '',   '',
727     #    'amount',    @money_type,
728     #  ],
729     #  'primary_key' => 'svcnum',
730     #  'unique' => [ [] ],
731     #  'index' => [ [] ],
732     #},
733
734     'svc_domain' => {
735       'columns' => [
736         'svcnum',    'int',    '',   '',
737         'domain',    'varchar',    '',   $char_d,
738       ],
739       'primary_key' => 'svcnum',
740       'unique' => [ ['domain'] ],
741       'index' => [ [] ],
742     },
743
744     'domain_record' => {
745       'columns' => [
746         'recnum',    'int',     '',  '',
747         'svcnum',    'int',     '',  '',
748         'reczone',   'varchar', '',  $char_d,
749         'recaf',     'char',    '',  2,
750         'rectype',   'char',    '',  5,
751         'recdata',   'varchar', '',  $char_d,
752       ],
753       'primary_key' => 'recnum',
754       'unique'      => [ [] ],
755       'index'       => [ ['svcnum'] ],
756     },
757
758     'svc_www' => {
759       'columns' => [
760         'svcnum',   'int',    '',  '',
761         'recnum',   'int',    '',  '',
762         'usersvc',  'int',    '',  '',
763       ],
764       'primary_key' => 'svcnum',
765       'unique'      => [ [] ],
766       'index'       => [ [] ],
767     },
768
769     #'svc_wo' => {
770     #  'columns' => [
771     #    'svcnum',    'int',    '',   '',
772     #    'svcnum',    'int',    '',   '',
773     #    'svcnum',    'int',    '',   '',
774     #    'worker',    'varchar',   '',   $char_d,
775     #    '_date',     @date_type,
776     #  ],
777     #  'primary_key' => 'svcnum',
778     #  'unique' => [ [] ],
779     #  'index' => [ [] ],
780     #},
781
782     'prepay_credit' => {
783       'columns' => [
784         'prepaynum',   'int',     '',   '',
785         'identifier',  'varchar', '', $char_d,
786         'amount',      @money_type,
787         'seconds',     'int',     'NULL', '',
788       ],
789       'primary_key' => 'prepaynum',
790       'unique'      => [ ['identifier'] ],
791       'index'       => [ [] ],
792     },
793
794     'port' => {
795       'columns' => [
796         'portnum',  'int',     '',   '',
797         'ip',       'varchar', 'NULL', 15,
798         'nasport',  'int',     'NULL', '',
799         'nasnum',   'int',     '',   '',
800       ],
801       'primary_key' => 'portnum',
802       'unique'      => [],
803       'index'       => [],
804     },
805
806     'nas' => {
807       'columns' => [
808         'nasnum',   'int',     '',    '',
809         'nas',      'varchar', '',    $char_d,
810         'nasip',    'varchar', '',    15,
811         'nasfqdn',  'varchar', '',    $char_d,
812         'last',     'int',     '',    '',
813       ],
814       'primary_key' => 'nasnum',
815       'unique'      => [ [ 'nas' ], [ 'nasip' ] ],
816       'index'       => [ [ 'last' ] ],
817     },
818
819     'session' => {
820       'columns' => [
821         'sessionnum', 'int',       '',   '',
822         'portnum',    'int',       '',   '',
823         'svcnum',     'int',       '',   '',
824         'login',      @date_type,
825         'logout',     @date_type,
826       ],
827       'primary_key' => 'sessionnum',
828       'unique'      => [],
829       'index'       => [ [ 'portnum' ] ],
830     },
831
832   );
833
834   %tables;
835
836 }
837