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