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