~mrooney/etherpad/ubuntu

« back to all changes in this revision

Viewing changes to trunk/trunk/etherpad/src/etherpad/db_migrations/m0002_eepnet_signups_2.js

  • Committer: Aaron Iba
  • Date: 2009-12-18 07:40:23 UTC
  • Revision ID: hg-v1:a9f8774a2e00cc15b35857471fecea17f649e3c9
initial code push

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Copyright 2009 Google Inc.
 
3
 * 
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 * 
 
8
 *      http://www.apache.org/licenses/LICENSE-2.0
 
9
 * 
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS-IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
import("sqlbase.sqlobj");
 
18
import("etherpad.utils.isPrivateNetworkEdition");
 
19
 
 
20
function run() {
 
21
  if (isPrivateNetworkEdition()) {
 
22
    return;
 
23
  }
 
24
 
 
25
  // add new columns.
 
26
  sqlobj.addColumns('eepnet_signups', {
 
27
    firstName: 'VARCHAR(128) NOT NULL DEFAULT \'\'',
 
28
    lastName: 'VARCHAR(128) NOT NULL DEFAULT \'\'',
 
29
    phone: 'VARCHAR(128) NOT NULL DEFAULT \'\''
 
30
  });
 
31
 
 
32
  // split name into first/last
 
33
  var rows = sqlobj.selectMulti('eepnet_signups', {}, {});
 
34
  rows.forEach(function(r) {
 
35
    var name = r.fullName;
 
36
    r.firstName = (r.fullName.split(' ')[0]) || "?";
 
37
    r.lastName = (r.fullName.split(' ').slice(1).join(' ')) || "?";
 
38
    r.phone = "?";
 
39
    sqlobj.updateSingle('eepnet_signups', {id: r.id}, r);
 
40
  });
 
41
 
 
42
  // drop column fullName
 
43
  sqlobj.dropColumn('eepnet_signups', 'fullName');
 
44
}
 
45
 
 
46
 
 
47