Skip to content

Commit

Permalink
merging identical authors (#49): updated the database schema and mode…
Browse files Browse the repository at this point in the history
…l classes to support the functionality
  • Loading branch information
Rija Menage committed Mar 22, 2018
1 parent a332f26 commit 6726f17
Show file tree
Hide file tree
Showing 5 changed files with 255 additions and 0 deletions.
107 changes: 107 additions & 0 deletions protected/models/AuthorRel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

/**
* This is the model class for table "author_rel".
*
* The followings are the available columns in table 'author_rel':
* @property integer $id
* @property integer $author_id
* @property integer $related_author_id
* @property integer $relationship_id
*
* The followings are the available model relations:
* @property Relationship $relationship
* @property Author $author
*/
class AuthorRel extends CActiveRecord
{
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return AuthorRel the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}

/**
* @return string the associated database table name
*/
public function tableName()
{
return 'author_rel';
}

/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('author_id, related_author_id', 'required'),
array('author_id, related_author_id, relationship_id', 'numerical', 'integerOnly'=>true),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, author_id, related_author_id, relationship_id', 'safe', 'on'=>'search'),
);
}

/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'relationship' => array(self::BELONGS_TO, 'Relationship', 'relationship_id'),
'author' => array(self::BELONGS_TO, 'Author', 'author_id'),
);
}

/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'ID',
'author_id' => 'Author',
'related_author_id' => 'Related Author',
'relationship_id' => 'Relationship',
);
}

/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.

$criteria=new CDbCriteria;

$criteria->compare('id',$this->id);
$criteria->compare('author_id',$this->author_id);
$criteria->compare('related_author_id',$this->related_author_id);
$criteria->compare('relationship_id',$this->relationship_id);

return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}

public function behaviors() {
return array(
'ActiveRecordLogableBehavior' => 'application.behaviors.DatasetRelatedTableBehavior',
);
}

}

?>
14 changes: 14 additions & 0 deletions protected/schema/migrations/author_rel.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
table: author_rel
from: null
to: ram_1
depends:
- [author, stpn_1]
- [relation, stpn_1]
sql: |
CREATE TABLE author_rel (
id SERIAL NOT NULL PRIMARY KEY,
author_id INTEGER NOT NULL REFERENCES author(id) ON DELETE CASCADE,
related_author_id INTEGER NOT NULL REFERENCES author(id) ON DELETE CASCADE,
relationship_id INTEGER NOT NULL REFERENCES relation(id) ON DELETE CASCADE,
);
45 changes: 45 additions & 0 deletions sql/gigadb_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,45 @@ ALTER TABLE author_id_seq OWNER TO gigadb;
ALTER SEQUENCE author_id_seq OWNED BY author.id;


--
-- TOC entry 252 (class 1259 OID 18403)
-- Name: author_rel; Type: TABLE; Schema: public; Owner: gigadb
--

CREATE TABLE author_rel (
id integer NOT NULL,
author_id integer NOT NULL,
related_author_id integer NOT NULL,
relationship_id integer
);


ALTER TABLE author_rel OWNER TO gigadb;

--
-- TOC entry 253 (class 1259 OID 18406)
-- Name: author_rel_id_seq; Type: SEQUENCE; Schema: public; Owner: gigadb
--

CREATE SEQUENCE author_rel_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;


ALTER TABLE author_rel_id_seq OWNER TO gigadb;

--
-- TOC entry 2903 (class 0 OID 0)
-- Dependencies: 253
-- Name: author_rel_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: gigadb
--

ALTER SEQUENCE author_rel_id_seq OWNED BY author_rel.id;


--
-- TOC entry 180 (class 1259 OID 18143)
-- Name: dataset; Type: TABLE; Schema: public; Owner: gigadb
Expand Down Expand Up @@ -1993,6 +2032,12 @@ ALTER TABLE ONLY attribute ALTER COLUMN id SET DEFAULT nextval('attribute_id_seq

ALTER TABLE ONLY author ALTER COLUMN id SET DEFAULT nextval('author_id_seq'::regclass);

--
-- TOC entry 2479 (class 2604 OID 18508)
-- Name: id; Type: DEFAULT; Schema: public; Owner: gigadb
--

ALTER TABLE ONLY author_rel ALTER COLUMN id SET DEFAULT nextval('author_rel_id_seq'::regclass);

--
-- TOC entry 2418 (class 2604 OID 18473)
Expand Down
44 changes: 44 additions & 0 deletions sql/gigadb_testdata.sql
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,44 @@ ALTER SEQUENCE author_id_seq OWNED BY author.id;

SELECT pg_catalog.setval('author_id_seq', 3809, true);

--
-- TOC entry 252 (class 1259 OID 18403)
-- Name: author_rel; Type: TABLE; Schema: public; Owner: gigadb
--

CREATE TABLE author_rel (
id integer NOT NULL,
author_id integer NOT NULL,
related_author_id integer NOT NULL,
relationship_id integer
);


ALTER TABLE author_rel OWNER TO gigadb;

--
-- TOC entry 253 (class 1259 OID 18406)
-- Name: author_rel_id_seq; Type: SEQUENCE; Schema: public; Owner: gigadb
--

CREATE SEQUENCE author_rel_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;


ALTER TABLE author_rel_id_seq OWNER TO gigadb;

--
-- TOC entry 2903 (class 0 OID 0)
-- Dependencies: 253
-- Name: author_rel_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: gigadb
--

ALTER SEQUENCE author_rel_id_seq OWNED BY author_rel.id;


--
-- Name: dataset; Type: TABLE; Schema: public; Owner: gigadb; Tablespace:
Expand Down Expand Up @@ -2065,6 +2103,12 @@ ALTER TABLE ONLY attribute ALTER COLUMN id SET DEFAULT nextval('attribute_id_seq

ALTER TABLE ONLY author ALTER COLUMN id SET DEFAULT nextval('author_id_seq'::regclass);

--
-- TOC entry 2479 (class 2604 OID 18508)
-- Name: id; Type: DEFAULT; Schema: public; Owner: gigadb
--

ALTER TABLE ONLY author_rel ALTER COLUMN id SET DEFAULT nextval('author_rel_id_seq'::regclass);

--
-- Name: id; Type: DEFAULT; Schema: public; Owner: gigadb
Expand Down
45 changes: 45 additions & 0 deletions sql/gigadb_testdata_penguin.sql
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,45 @@ ALTER SEQUENCE author_id_seq OWNED BY author.id;
SELECT pg_catalog.setval('author_id_seq', 3791, true);


--
-- TOC entry 252 (class 1259 OID 18403)
-- Name: author_rel; Type: TABLE; Schema: public; Owner: gigadb
--

CREATE TABLE author_rel (
id integer NOT NULL,
author_id integer NOT NULL,
related_author_id integer NOT NULL,
relationship_id integer
);


ALTER TABLE author_rel OWNER TO gigadb;

--
-- TOC entry 253 (class 1259 OID 18406)
-- Name: author_rel_id_seq; Type: SEQUENCE; Schema: public; Owner: gigadb
--

CREATE SEQUENCE author_rel_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;


ALTER TABLE author_rel_id_seq OWNER TO gigadb;

--
-- TOC entry 2903 (class 0 OID 0)
-- Dependencies: 253
-- Name: author_rel_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: gigadb
--

ALTER SEQUENCE author_rel_id_seq OWNED BY author_rel.id;


--
-- Name: dataset; Type: TABLE; Schema: public; Owner: gigadb; Tablespace:
--
Expand Down Expand Up @@ -2056,6 +2095,12 @@ ALTER TABLE ONLY attribute ALTER COLUMN id SET DEFAULT nextval('attribute_id_seq

ALTER TABLE ONLY author ALTER COLUMN id SET DEFAULT nextval('author_id_seq'::regclass);

--
-- TOC entry 2479 (class 2604 OID 18508)
-- Name: id; Type: DEFAULT; Schema: public; Owner: gigadb
--

ALTER TABLE ONLY author_rel ALTER COLUMN id SET DEFAULT nextval('author_rel_id_seq'::regclass);

--
-- Name: id; Type: DEFAULT; Schema: public; Owner: gigadb
Expand Down

0 comments on commit 6726f17

Please sign in to comment.