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