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