Problem geting addon migrations to work
Created 5 years ago by jcastillotx

So I followed the instructions on https://pyrocms.com/videos/series/module-development/module-migrations and nothing shows. What am I doing wrong?

  1. php artisan make:migration create_next_date_field --addon=sponsorships --fields
  2. php artisan make:migration assign_next_date_field --addon=sponsorships --stream=sponsorships
  3. I edit 2017_04_10_021550_modules.module.sponsorships__create_next_date_field.php
<?php
	
	use Anomaly\Streams\Platform\Database\Migration\Migration;
	
	class ModulesModuleSponsorshipsCreateNextDateField extends Migration {
		
		/**
		 * The addon fields.
		 *
		 * @var array
		 */
		protected $fields = [
			'next_charge' => [
				"type"   => "anomaly.field_type.datetime",
				'config' => [
					"mode"        => "date",
					"date_format" => "j F, Y",
					"year_range"  => "-50:+50",
				]
			],
			'processed'   => [
				'type' => 'anomaly.field_type.boolean'
			]
		];
		
	}
  1. Then I edit 2017_04_10_024520_modules.module.sponsorships__assign_next_date_field.php
<?php

use Anomaly\Streams\Platform\Database\Migration\Migration;

class ModulesModuleSponsorshipsAssignNextDateField extends Migration
{

    /**
     * The stream definition.
     *
     * @var array
     */
    protected $stream = [
        'slug' => 'sponsorships'
    ];

    /**
     * The stream assignments.
     *
     * @var array
     */
    protected $assignments = [
	    'next_charge',
	    'processed'
    ];

}
  1. Run php artisan migrate --all-addons
  2. Nothing shows up on the form.

What am I missing

ryanthompson  —  5 years ago

Did you get this working? Did you confirm that these are created in your addon directory? Is the addon installed?

jcastillotx  —  5 years ago

Still does not work and yes is in the sponsorship module migrations folder and shows it migrated. However, nothing shows on the form.

piterden  —  5 years ago

That what I have to do to get it working:

    protected $fields = [
        'meta_fb_title'       => [
            'namespace' => 'pages',
            'type'      => 'anomaly.field_type.text',
        ],
        'meta_fb_description' => [
            'namespace' => 'pages',
            'type'      => 'anomaly.field_type.textarea',
        ],
        'meta_fb_image'       => [
            'namespace' => 'pages',
            'type'      => 'anomaly.field_type.file',
            'config'    => [
                'folder'        => 2,
            ],
        ],
        'meta_tw_title'       => [
            'namespace' => 'pages',
            'type'      => 'anomaly.field_type.text',
        ],
        'meta_tw_description' => [
            'namespace' => 'pages',
            'type'      => 'anomaly.field_type.textarea',
        ],
        'meta_tw_image'       => [
            'namespace' => 'pages',
            'type'      => 'anomaly.field_type.file',
            'config'    => [
                'folder'        => 2,
            ],
        ],
    ];

And assignments:

    /**
     * The addon fields.
     *
     * @var array
     */
    protected $assignments = [
        'meta_fb_title'       => [
            'translatable' => true,
        ],
        'meta_fb_description' => [
            'translatable' => true,
        ],
        'meta_fb_image' => [],
        'meta_tw_title'       => [
            'translatable' => true,
        ],
        'meta_tw_description' => [
            'translatable' => true,
        ],
        'meta_tw_image' => [],
    ];

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        $stream = $this->streams()->findBySlugAndNamespace('pages', 'pages');

        foreach ($this->assignments as $slug => $params)
        {
            $field = $this->fields()->findBySlugAndNamespace($slug, 'pages');

            $this->assignments()->create(array_merge([
                'stream' => $stream,
                'field'  => $field,
            ], $params));
        }
    }