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