populate a table while migrations

Discussion forum for Extension Writers regarding Extension Development.
User avatar
Kailey
Community Team Leader
Community Team Leader
Posts: 3862
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay

Re: populate a table while migrations

Post by Kailey »

This was almost too easy. :lol:

In your install_sample_data file, change this line (~line 22).

Code: Select all

return ['\sebo\postreact\migration\install_sample_schema'];
to

Code: Select all

return ['\sebo\postreact\migrations\install_sample_schema'];
You had "migration" instead of "migrations"
Kailey Snay - Community Team Leader
Knowledge Base | Documentation | Community rules
If you have any questions about the rules/customs of this website, feel free to send me a PM.

My little corner of the world | Administrator @ phpBB Modders
User avatar
sebo
Registered User
Posts: 54
Joined: Mon Jan 22, 2024 10:28 pm

Re: populate a table while migrations

Post by sebo »

mmmh...i tryed to update "migrations" as you said, or used "migration" too...but the error the forum gave me is:
Something went wrong during the request and an exception was thrown. The changes made before the error occurred were reversed to the best of our abilities, but you should check the board for errors.

The migration "\sebo\postreact\migrations\install_sample_data" is not fulfillable, missing migration "\phpbb\db\migrations\data\v320\v320".

Return to the extension list
so i realized, :idea: i changed the folder name (was migrations, made up by skeleton app) and changed to "migration".

now the extensions installs without database changes :( :(

no solution...
User avatar
sebo
Registered User
Posts: 54
Joined: Mon Jan 22, 2024 10:28 pm

Re: populate a table while migrations

Post by sebo »

i've copied the install_schema and data of abbc3 (advanced bbcode ext 3, existing ext)...renamed the folder again in migrations...uploaded the files via github, no way.

if i delete dependencies the schema install works, but not the data... :!:
User avatar
Kailey
Community Team Leader
Community Team Leader
Posts: 3862
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay

Re: populate a table while migrations

Post by Kailey »

I'm not sure what you're doing wrong. All I had to do was rename migration to migrations and it worked for me.

I've seen your PM and will respond later tonight (at work right now).
Kailey Snay - Community Team Leader
Knowledge Base | Documentation | Community rules
If you have any questions about the rules/customs of this website, feel free to send me a PM.

My little corner of the world | Administrator @ phpBB Modders
User avatar
sebo
Registered User
Posts: 54
Joined: Mon Jan 22, 2024 10:28 pm

Re: populate a table while migrations

Post by sebo »

still not working...

install_sample_schema keeps the dependencies:
\phpbb\db\migration\data\v320\v320

instead in install_sample_data
  • if i keep dependencies
    \sebo\postreact\migrations\install_sample_schema
    - i get an error message that the table (created via install_sample_schema) does not exist X
    - no data installed X
    - no permission installed X
  • if i remove the dependencies and keep
    \phpbb\db\migration\data\v320\v320
    the same error that the table doesn't exist
    - no data installed X
    - no permission installed X
    - no schema installed X
  • if i remove the entire function
    public static function depends_on()
    the same error that the icon table doesn't exist
    - no data installed X
    - no permission installed X
    - no schema installed X
  • if i remove ['custom', [[$this, 'table_pr_install']]], (custom installation data function call) and keep dependencies return ['\phpbb\db\migration\data\v320\v320'];
    - i get complete installation scheme V
    - install permission V
    - no data install X

    if i remove ['custom', [[$this, 'table_pr_install']]], (custom installation data function call) and keep dependencies return ['\sebo\postreact\migrations\install_sample_schema'];
    - i get complete installation scheme V
    - no install permission X
    - no data install X
i'm getting crazy...:D no trees like in tutorial says...https://area51.phpbb.com/docs/dev/3.3.x ... ncies.html
rxu
Extensions Development Team
Posts: 3852
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation

Re: populate a table while migrations

Post by rxu »

What is sebo_postreact_table? You have it in the function effectively_installed() in install_sample_data migration so if it exists migration doesn't apply schema changes and just considered as already installed. Probably that is the cause.
User avatar
sebo
Registered User
Posts: 54
Joined: Mon Jan 22, 2024 10:28 pm

Re: populate a table while migrations

Post by sebo »

There are 2 tables
sebo_postreact_table (only schema) -> needed for post's info
sebo_postreact_icon (schema + populate) -> needed for icon's info

Schema installs both, data populate one of them. installation schemas are in the same file and same function...what do you mean?!?
The effective installed is:
- in data file -> on data if Is installed icon table
- in schema file -> If already installed first table
rxu
Extensions Development Team
Posts: 3852
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation

Re: populate a table while migrations

Post by rxu »

I couldn't find a code point where sebo_postreact_table is being added in your migration, since the suggestion.
User avatar
sebo
Registered User
Posts: 54
Joined: Mon Jan 22, 2024 10:28 pm

Re: populate a table while migrations

Post by sebo »

install_sample_schema ;)

Code: Select all

	public function update_schema()
	{
		return [
			'add_tables'		=> [
				$this->table_prefix . 'sebo_postreact_table'	=> [
					'COLUMNS'		=> [
						'postreact_id'			=> ['UINT', null, 'auto_increment'],
						'topic_id'				=> ['UINT', 0],
						'post_id'				=> ['UINT', 0],
						'user_id'				=> ['UINT', 0],
						'icon_id'				=> ['UINT', 0],
						'react_time'			=> ['UINT:11', 0],
					],
					'PRIMARY_KEY'	=> 'postreact_id',
				],
				$this->table_prefix . 'sebo_postreact_icon'	=> [
					'COLUMNS'		=> [
						'id'			=> ['UINT', null, 'auto_increment'],
						'icon_id'			=> ['UINT', 0],
						'icon_url'			=> ['VCHAR:200', ''],
						'icon_width'		=> ['UINT', 0],
						'icon_height'		=> ['UINT', 0],
						'icon_alt'			=> ['VCHAR:100', ''],
						'status'			=> ['UINT:1', 0],
						'active'			=> ['UINT:1', 0],
					],
					'PRIMARY_KEY'	=> 'id',
				],
			],
		];
	}
rxu
Extensions Development Team
Posts: 3852
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation

Re: populate a table while migrations

Post by rxu »

Not that much clearer tbh, now there's no any my_table in the schema so the error shouldn't arise at all, lol.
Do you have some up-to-date code for the whole extension somewhere to look into?
User avatar
sebo
Registered User
Posts: 54
Joined: Mon Jan 22, 2024 10:28 pm

Re: populate a table while migrations

Post by sebo »

sebo wrote: Mon Jul 29, 2024 12:36 pm nono is ok, i'm learning it's a project for the community...i have another work :D not a programmer!
instead i have understood how to use github so here is the file:

https://github.com/sebolp/postreact/blo ... e_data.php

i'm uploading the entire ext
yes i uploaded via github ;)
https://github.com/sebolp/postreact/tre ... migrations

sorry for that i thought you was lookin in there :oops:
rxu
Extensions Development Team
Posts: 3852
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation

Re: populate a table while migrations

Post by rxu »

Ah, missed that post, sorry.
Okay but the set of files is not complete still so it's impossible to really test the extension installation, f.e. it throws error A required module info file is missing: \sebo\postreact\acp\main_module so it doesn't even reach to the schema changes :)
User avatar
sebo
Registered User
Posts: 54
Joined: Mon Jan 22, 2024 10:28 pm

Re: populate a table while migrations

Post by sebo »

uploaded now the entire ext ;)
rxu
Extensions Development Team
Posts: 3852
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation

Re: populate a table while migrations

Post by rxu »

Well, the extension has been installed successfully, no errors.
Both tables have been successfully created as well as the ACP module.
rxu
Extensions Development Team
Posts: 3852
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation

Re: populate a table while migrations

Post by rxu »

After removing public function effectively_installed() from the install_sample_data.php migration, data was filled successfully (including permissions, icons table data and config parameter).

Return to “Extension Writers Discussion”