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