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