Yii Framework Forum: ActiveStructure - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

ActiveStructure ActiveStructure that represent data-storage shema. Rate Topic: -----

Poll: ActiveStructure (8 member(s) have cast votes)

will you use it?

  1. Yes (1 votes [12.50%])

    Percentage of vote: 12.50%

  2. No (4 votes [50.00%])

    Percentage of vote: 50.00%

  3. Don't care (3 votes [37.50%])

    Percentage of vote: 37.50%

Vote Guests cannot vote

#1 User is offline   Ulten 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 04-October 10

Posted 11 December 2010 - 10:01 AM

i don't have match time and describe how i came to it.(if some one will be interested in that just comment i will answer later).

ActiveStructure
Active structure represent structure of DB, that currently used,

1) when DB is empty it possible to fill it with needed structure
2) when DB contained some structure its possible to generate this ActiveSctructure objects
3) and synchronizing structure betwin Db and AS objects.
4) possible to use DB structure changes in realtime, for creating DB-structure programmatically.


some usage example

class Post extends ActiveStructure
{

public $structure = array(
array('id'=>'int','primarykey'),
array('post'=>'text'),
array('user'=>'text'),
)

(overrides) public synchronize(){
return false;//no sincronization
return $this;//sincronize db to this file
return 'data_base';//sincronize this to target database;
}

}
0

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,727
  • Joined: 17-January 09
  • Location:Russia

Posted 11 December 2010 - 04:08 PM

Looks like AR + migrations?
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#3 User is offline   Ulten 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 04-October 10

Posted 12 December 2010 - 06:50 AM

View Postsamdark, on 11 December 2010 - 04:08 PM, said:

Looks like AR + migrations?

Yes, looks like you right its something like migrations but working with it more in manner AR, and definitely synchronized between AR <-> ActiveStructure.
0

#4 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,727
  • Joined: 17-January 09
  • Location:Russia

Posted 12 December 2010 - 08:19 AM

Well, I don't think Yii should go this way. It makes things much more complex. Now we are syncing models with database. There are a lot of nice tools to work with DB, a lot of articles and books on it.

In your case we have to learn new syntax that will generate DB and model. Additionally it will have a big performance impact since we'll need to check if database and model is up to date.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#5 User is offline   Ulten 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 04-October 10

Posted 12 December 2010 - 09:22 AM

View Postsamdark, on 12 December 2010 - 08:19 AM, said:

Well, I don't think Yii should go this way. It makes things much more complex. Now we are syncing models with database. There are a lot of nice tools to work with DB, a lot of articles and books on it.

In your case we have to learn new syntax that will generate DB and model. Additionally it will have a big performance impact since we'll need to check if database and model is up to date.


1) Complexity - how you measure it?
2) If you want to change application behavior with data go to nice tool, make changes - apply, regenerate Model, make changes to model, insted of just changing such ActivStructure class.
3) no new syntax, just in special cases when you need to optimize performance etc.Generally database used to store php-types , why should do (int),(string),(bool),(data), etc(php base clases), and another thing is great that create some serialized objects and store it in AR nativity db via ActiveStructure.
4) don't forget that will be possible to create/manage/delete Tables, in real time (great thing for temporary,memory, etc. tables)
5) of what performance impact you talk, if you already use AR, impact is not more then regenerate Model, when needed.(done once per change)
0

#6 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,727
  • Joined: 17-January 09
  • Location:Russia

Posted 12 December 2010 - 11:39 AM

1) Requirement to learn new syntax and rules.
2) Yes, it's nice during development but, I think, migrations are more convenient. You can track what was changed by your team and adapt your code accordingly.
5) How can I tell if a change was made?
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#7 User is offline   Ulten 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 04-October 10

Posted 12 December 2010 - 12:44 PM

View Postsamdark, on 12 December 2010 - 11:39 AM, said:

1) Requirement to learn new syntax and rules.
2) Yes, it's nice during development but, I think, migrations are more convenient. You can track what was changed by your team and adapt your code accordingly.
5) How can I tell if a change was made?


1) syntax Ń‹hould be as intuitive as possible (php or AR like).
example try:

class Post extends ActiveStructure {

public $columns=(
'id'=>array('int','pk'),
'message'=>array('string','nn'),//not null
'user_id'=>array('int',HAS_MENY_LIKE_AR_RELETIONSHIP),
'uniq_record'=>array('char(32)','nn','unique');// something like md5 of message
);

} // is it to hard, or not understandable?
// my favorite is OOP approach like this

class Post extends ActiveStructure {

public $id;
public $message;
public $user_id;
public $uniq_record;
public $syncronize = ActiveStructure::ClassPriority;
//or ActiveStructure::DataBasePriority;


public function inicialize{ // or __construct()
$this->id = new ASculumn();
$this->id->type = ASculumn::int;
$this->id->pk = true;

$this->message= new ASculumn();
$this->message->type = ASculumn::string;
$this->message->nn = true;

$this->user_id= new ASculumn();
$this->user_id->type = ASculumn::int;
$this->user_id->relations = 'HAS_MENY_LIKE_AR_RELETIONSHIP';

$this->uniq_record = new ASculumn(Asculumn::char(32)); '=>array('char(32)','nn','unique');
$this->uniq_record->notnull = true;
$this->uniq_record->unique = true;

}
// btw, is it possible to create Yii's ActiveRecord like that?

}

2) in team development there more advantage ,imagine you will always have "fresh" structure class, and will be very usable when adopt new changes.
5) select structure from DB , create object ActiveSctucture and compare them or , create some kind of hash and compere them, and then just mark it as synchronized.
0

#8 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,727
  • Joined: 17-January 09
  • Location:Russia

Posted 12 December 2010 - 12:51 PM

5) So what is the advantage if we have to manually compare and synchronize changes? Aren't migrations better for this task?
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#9 User is offline   Ulten 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 04-October 10

Posted 12 December 2010 - 01:15 PM

View Postsamdark, on 12 December 2010 - 12:51 PM, said:

5) So what is the advantage if we have to manually compare and synchronize changes? Aren't migrations better for this task?


5) so its not manual, is it not possible to compare it in ActiveStructure class it self?

like ,
1-> select * from data_base_structure even posible to use AR to get it.

2-> initialize current table;

3-> compare between 1,2 in foreach () foreach loop.
0

#10 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,727
  • Joined: 17-January 09
  • Location:Russia

Posted 12 December 2010 - 04:46 PM

If we'll compare it in the class itself, this comparison will degrade performance slightly because of usage of PHP reflexion and SQL schema queries. If we'll cache it then there are no pros compared to migrations.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#11 User is offline   Ulten 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 04-October 10

Posted 12 December 2010 - 05:42 PM

View Postsamdark, on 12 December 2010 - 04:46 PM, said:

If we'll compare it in the class itself, this comparison will degrade performance slightly because of usage of PHP reflexion and SQL schema queries. If we'll cache it then there are no pros compared to migrations.


its like migrations but with possibility to change structure in real-time, even create and delete tables and use them.
0

#12 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,727
  • Joined: 17-January 09
  • Location:Russia

Posted 12 December 2010 - 06:46 PM

Well, with migrations you can change structure. And you can do the same in realtime using query builder (see http://code.google.c...lder.txt?r=2738, starting from "Building Schema Manipulation Queries").
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#13 User is offline   Ulten 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 04-October 10

Posted 14 December 2010 - 04:40 AM

View Postsamdark, on 12 December 2010 - 06:46 PM, said:

Well, with migrations you can change structure. And you can do the same in realtime using query builder (see http://code.google.c...lder.txt?r=2738, starting from "Building Schema Manipulation Queries").


generally speaking why using active record when you can use query builder, why not? meaby its because of manageability?
0

#14 User is offline   Ulten 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 04-October 10

Posted 14 December 2010 - 05:38 AM

In some consideration it seems that ActiveStructure is really a part of ActionRecord, because their already is mention of relations, and its really possible to back-translate to database structure.
More of that its not a bad idea to have some information about types of columns in AR.
0

#15 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,727
  • Joined: 17-January 09
  • Location:Russia

Posted 15 December 2010 - 04:43 AM

Well, maybe. I don't think we'll implement this in 1.1 releases so if you really want this you can try creating an extension to see if it actually works as a feature.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#16 User is offline   Ulten 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 04-October 10

Posted 15 December 2010 - 07:13 AM

View Postsamdark, on 15 December 2010 - 04:43 AM, said:

Well, maybe. I don't think we'll implement this in 1.1 releases so if you really want this you can try creating an extension to see if it actually works as a feature.


yes, i think its can be some major thing in 1.2 maybe?
about extension i don't realy have knowledge about database abstraction if it has some(i hope)
i can create it for mysql that just proofing the idea, will it help?
0

#17 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,727
  • Joined: 17-January 09
  • Location:Russia

Posted 15 December 2010 - 12:15 PM

I think so. At least you'll receive some comments about idea itself.

Right now, as I can see, there is only one positive vote in this topic poll.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#18 User is offline   Ulten 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 04-October 10

Posted 15 December 2010 - 02:40 PM

View Postsamdark, on 15 December 2010 - 12:15 PM, said:

I think so. At least you'll receive some comments about idea itself.

Right now, as I can see, there is only one positive vote in this topic poll.


i believe opinion of 8 active users of forum not enough to judge an idea.
0

#19 User is offline   seb 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 240
  • Joined: 29-June 09

Posted 16 December 2010 - 05:56 AM

Some similar idea is discussed here.
I am personally think automatic database changes can be too dangerous - some bug can dynamically destroy database. Usually when I upgrade database I make backup of current structure and make sure that everything is ok on local database copy before upgrading production version. So I prefer to run migrations manually.
Another one problem is support for different databases and support for some features like triggers, view and procedures which can be hard to describe as php array.
Also CActiveRecord already has information about database columns - see getMetaData() method, so back sync from database to AR is already present.
0

#20 User is offline   intel352 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 196
  • Joined: 05-February 10
  • Location:Southport, NC

Posted 09 March 2011 - 11:10 PM

I think something along the lines of this idea, but implemented in a more Yii-aware way, would be nice.
Such as, automatically creating migration classes from DB (on-the-fly even, when change is detected).
Then, using migrations, an option could be added to automatically attempt applying migrations when a newer migration version is detected.


No need for the complexities suggested in the ActiveStructure proposal, while still retaining some of the possible advantages.
Need live Yii support? - Join the #yii IRC channel on Freenode!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users