Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
m120321_063206_user.php
1 <?php
2 /**
3  * Gentics Portal.Node PHP
4  * Author & Copyright (c) by Gentics Software GmbH
5  * sales@gentics.com
6  * http://www.gentics.com
7  * Licenses can be found in the LICENSE.txt file in the root-folder of this installation
8  * You must not use this software without a valid license agreement.
9  *
10  * Postgres type casting fix:
11  *
12  * select s.typname source, t.typname target, f.proname, castcontext, c.oid
13  * from pg_cast c
14  * join pg_type s on s.oid = c.castsource
15  * join pg_type t on t.oid = c.casttarget
16  * join pg_proc f on f.oid = c.castfunc
17  * where (s.typname like 'bool' and t.typname like 'int4');
18  *
19  * update pg_cast set castcontext = 'i' where oid = OID;
20  *
21  * select s.typname source, t.typname target, f.proname, castcontext, c.oid
22  * from pg_cast c
23  * join pg_type s on s.oid = c.castsource
24  * join pg_type t on t.oid = c.casttarget
25  * join pg_proc f on f.oid = c.castfunc
26  * where (s.typname like 'int4' and t.typname like 'bool');
27  *
28  * update pg_cast set castcontext = 'a' where oid = OID;
29  */
30 class m120321_063206_user extends CDbMigration
31 {
32  public function safeUp()
33  {
34  $this->createTable('{{users}}', array(
35  'id' => 'pk',
36  'username' => 'string',
37  'password' => 'string',
38  'email' => 'string NOT NULL',
39  'activkey' => 'string',
40  'createtime' => 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP',
41  'lastvisit' => 'timestamp NULL DEFAULT NULL',
42  'status' => "integer NOT NULL DEFAULT 0",
43  ));
44  $this->createIndex('users_status_idx', '{{users}}', 'status');
45  $this->createIndex('users_username_idx', '{{users}}', 'username');
46  $this->createIndex('users_email_idx', '{{users}}', 'email', true);
47 
48  $this->insert('{{users}}', array(
49  'username' => 'admin',
50  'password' => '21232f297a57a5a743894a0e4a801fc3',
51  'email' => 'webmaster@example.com',
52  'activkey' => '9a24eff8c15a6a141ece27eb6947da0f',
53  'createtime' => "2012-07-02 15:54:45",
54  'status' => 1,
55  ));
56  $this->insert('{{users}}', array(
57  'username' => 'demo',
58  'password' => 'fe01ce2a7fbac8fafaed7c982a04e229',
59  'email' => 'demo@example.com',
60  'activkey' => '099f825543f7850cc038b90aaff39fac',
61  'createtime' => "2012-07-02 15:54:45",
62  'status' => 1,
63  ));
64 
65  $this->createTable('{{profiles}}', array(
66  'user_id' => 'pk',
67  'lastname' => "string NOT NULL DEFAULT ''",
68  'firstname' => "string NOT NULL DEFAULT ''",
69  'birthday' => "date",
70  ));
71 
72  $res = Yii::app()->db->createCommand()->select('id')->from('{{users}}')
73  ->where('username=:username', array(':username' => 'admin'))
74  ->queryRow();
75  $this->insert('{{profiles}}', array(
76  'user_id' => $res['id'],
77  'lastname' => 'Korzhov',
78  'firstname' => 'Vlas',
79  'birthday' => '1971-09-26',
80  ));
81  $res = Yii::app()->db->createCommand()->select('id')->from('{{users}}')
82  ->where('username=:username', array(':username' => 'demo'))
83  ->queryRow();
84  $this->insert('{{profiles}}', array(
85  'user_id' => $res['id'],
86  'lastname' => 'Account',
87  'firstname' => 'Demo',
88  'birthday' => '1999-08-29',
89  ));
90  }
91 
92  public function safeDown()
93  {
94  $this->dropTable('{{profiles}}');
95  $this->dropTable('{{users}}');
96  }
97 }