Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

MODULE creation and YII migrations


Chadduck

Recommended Posts

Apologies in advance for the complexity and being long-winded with this topic...  I am looking for input BEFORE I make a mistake.  Hopefully @pandrei you will give me the answers and insight I need.

After completing the tutorial posted by Yuriy Nechitajlo in the Wiki entitled "Creating Extension from Scratch" I have began to transition a module from OSC Frozen to Osc V4.  I am at a point where I need some insight about using the YII database migration functions within the module as part of the Setup.php file.

Yes, I have made a backup of the database...

PART 1 of my question(s)

I need to add two columns to an existing table.  Realizing how dangerous it can be for the novice to attempt this I would like to make absolutely certain that I understand the CORRECT way to do this.  Using the YII v2 documentation located here
https://www.yiiframework.com/doc/guide/2.0/en/db-migrations

It appears that these are the necessary commands... 

Quote

class m150811_220037_add_position_column_to_post_table extends Migration
{
    public function up ()
    {
        $this->addColumn('post', 'position', $this->integer()); 
    }

public function down ()
    {
        $this->dropColumn('post', 'position'); 
    }
}

As I understand it the above would add the column called "Position" to the tablle called "Post".  It is also my understanding that the $this portion would be similar to  

$this->addColumn('post', 'postion', $this->string(64));

PART 2 of my question(s)

Regarding - this particular line of the YII 2 example

m150811_220037_add_position_column_to_post_table extends Migration

Does the "add_position_column_to_post_table" need to reflect the CORRECT info like this

add_ <DB COLUMN NAME> _column_to_ <DB TABLE NAME> _table

OR is the only required part the "m150811_220037"?

I couldn't locate an example to follow and the Tutorial doesn't cover it.

PART 3 of my question(s)

During the extension installation phase does migration run automatically OR is that done in the Settings > Cache control section with Migrations Apply checked then pressing Flush button afterward?

Hopefully this makes sense because I really don't want to make a mistake.

BJ

Link to comment
Share on other sites

13 hours ago, Chadduck said:

Apologies in advance for the complexity and being long-winded with this topic...  I am looking for input BEFORE I make a mistake.  Hopefully @pandrei you will give me the answers and insight I need.

Migrations are used to modify core of osCommerce. If you are working on extension, you don't need to use it. osCommerce has its own extension methodology.

I think this sample is an answer to your questions: https://www.oscommerce.com/wiki/Sample_of_Creating_Extensions_with_Widget_for_Editing_and_Outputting_Additional_Information_about_Product

Link to comment
Share on other sites

@pandrei

Thank you.  I had pulled that file but did not realize it was a tutorial that included changing the database by adding a field to an existing table. 

Will step my way through it and learn things that I don't know.

Thank you again for pointing me in the correct direction.

BJ

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...