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