SQLite and multiple renaming or dropColumn ‘s error in laravel 5.0 aritsan migrate

So #HTH

One of my migration scripts in Laravel 5 has 3 dropColumn requests in and 1 rename column. This all works fine with laravel migrations on MySQL and MariaDB, as you would expect.

However once you try to run those same migrations on a mysqlite / sqlite database you may start seeing errors like so

SQLSTATE[HY000]: General error: 1 no such column: XXX (SQL: CREATE TEMPORARY TABLE

Now following up the issue on Github it is related to this, https://github.com/laravel/framework/issues/2979 but Taylor doesn’t believe it’s a bug, saying,

I would do them in two separate operations.

 The work around unfortunately is to split EACH drop Column and rename into 1 separate migration file each…

Crazy, but tbh. if that’s the worst bug I come across with Laravel 5, I’ll take it.

State of the union (since starting at Warwick Uni)

A small state of the union post so I don’t forget my journey so far…

The largest change is introducing my Agile experience into many aspects of workflow and to many members of staff.

Agile Training
* I have delivered three separate sets of Agile training
* Once for the Project Management Networking Group
* Once for the WMG IT team
* Once for an individual member of staff

I have introduced some better online tools to support the University’s work
* Trello – The whole IT team use it now to track and collaborate on their work
* Quickcast – The use of screen casting to show staff how to use certain material
* Continuous Integration – GitLab’s CI runner Is now provided by the University following me pushing for access
* Google analytics – To prove that students are using more of their own devices which are Apple based, than the university owned Windows machines
* Twitter Bootstrap must be used across all our custom apps. Our custom built apps from externals had custom CSS wrappers, but now use Twitter bootstrap 3.

Methods of working
* A lot of the Moodle work is “Handle turning”, I have floated the idea of an apprentice, which has led to a summer intern coming in
* IT partners – Following the Agile training, the following ideas of roles and responsibilities of a Product Owner leading and ordering tasks in priorities was taken on for our WMG IT partners
* We use an Agile approach to define what work should be done next. “If it went live tomorrow, what would we need?”

Development Bootstrap
* Deployment
* Folder organistion
* Server registration
* Repository Model
* Interfaces
* Behaviour Driven Development testing
* Unit testing

University Wide
* One of my three University wide ideas has gone onto review stage, using rechargeable mics for presenting will save on batteries and reduce support calls

Projects
* Biddr – an online reverse auction. I coached Agile to the staff and also built this learning tool in Laravel 4.
* Gradr – an online app to consolidate marks from multiple modules into one simple dashboard. It provides students a single overview and tutors an overall table of their students marks. I coached the staff in Agile and also built this in Laravel 5.
NEXT!

  • More Project management
  • More Laravel 5 and Elastic Search
  • Improving the University’s IT network (of people, not wires)
  • More training, hopefully in leadership (it’s different here to a small self-owned company!)

Being brave enough to change a process

Today we had to change a large process that wasn’t working.

The State.

A web development being built hasn’t got automated tests written for it and requires an office member to go through and MANUALLY test every item. Basically what Behat or DalekJS should be doing…

Anyway, the tests were all written in 1 document. “When I create a module, it should appear in a student’s list”, “When I select 3 modules, it calculates the student’s points correctly”, etc…

My process to solving a process.

Sometimes improving it can feel a bit daunting, however, as you talk through it with the team, record small sticking points and pains, then the you should start to see a bigger picture.
Always remember, you probably just need an evolution not a total revolution.

Steps…

  1. Remind the team, that they own this process so they will want to find solutions to save themselves time
  2. Talk through the whole process, record EVERY sticking point
  3. Look through the sticking points for the worst offenders
  4. Think of simple ideas to fix them
  5. Repeat 4 until happy :)
  6. Talk it through with all the team
  7. Go!
  8. Re-look at it again soon!

Our Biggest Problems were…

  • Testing document, who has the latest copy and where?
  • TheTesting document is really fiddly for comments
  • TheTesting document doesn’t really handle versions very well
  • It’s difficult to discuss the comments inside theTesting document
  • What should the developer work on next?

Some solutions…

  • Testing document has been moved to a Shared OneDrive for all the project Team.
  • Re-named testing document “Testing Document v1″ to “Testing Document”, losing the version number indicated its “alive” state
  • All Passes are still recorded in the Testing document with the word “Pass”
  • All Fails are recorded int he Testing document as “Fail”, but no comment
  • All Fails with comments are created as tickets in a Trello board with the unique test id and a description of the fail
  • All Fails are re-ordered in the list by the Product Owner to show importance
  • A Trello list was created for the Product Owner to rack up no more than 5 tickets which the need the developer to work on next

Excellent Customer Service training

Today I attended some training on Excellent Customer Service provided by the University.

The reason I signed up was because some of the work I’ve taken over here for providing Moodle Gradebook support is not “so hot” right now. It feels like we’re failing on some really basic stuff, which is frustrating to both me and obviusly the staff. Also, by failing on the basics, it knocking effect of WOW things, like custom code of the gradebook.

To be fair, a lot of the stuff I have taken on is going pretty well and the tutors seem very happy with my Project Management and Custom coding. But, I still want to be doing better in the areas I’m presently weakest in, whether they are inherited problems or brand new.

The first things to learn was, “who is my customer?”, Because yes, my work affects the students too, I did wonder if they were my customer. However, nope. My work sits in a chain of support and my direct customer is the staff I deal with on a day to day basis.

Then we used a very useful model and excercise, the Kano Model. It splits and identifies different parts of your service from Basic, Satisfactory and WOW.

Kano_model_showing_transition_over_time

It turns out after doing the excercise, I identified loads of basics, but had trouble picking anything above that. Which is becuase, in a few ways the service isn’t even hitting the basics, so there’s no point offering WOWs. The analogy we were given was, “With a hotel, your basics are Bed, Clean room & Toilet. So if none of those basics are met, you wouldn’t be so overly happy with a WOW of champagne on arrival”.

So… to identify some of the basics within my control,

  1. Staff know when Moodle is going down for maintanence
  2. When marks are released, they stay released
  3. Course rollover will happen

So.. to identify some actions to help with those basics,

  1. Maintenance
  • Create a staff list / Sharepoint group for notifications
  • On receipt of Russell’s emails, share with the list

2. Marks released

  • Map the Moodle Show / Hide flow
  • Request a Show / Hide logger from Central
  • Dan Course to take on marks release for the rest of this term
  • Analyse the Service Now calls raised

3. Course rollover

  • Inform staff when this will happen

Why we test… the two other tests I’m forgetting to write

This morning was spent fixing something, which frankly, I should have known better! However, when you’re coding and project managing on your own, it’s not easy to keep everything rolling.

When I write new Repository methods, I leave a comment note @totest to remind me to come back and write some tests!

However, I’ve missed writing 2 simple types of tests which would have taken 20 mins and then saved me an hour this morning. So I thought I’d share with you lot.

In My Laravel Middleware I have a method which checks the UserId provided is one of our students.

    $user = $this->userRepo->findByUidOrFail($this->fetchUser());

However, because I haven’t filled in any tests on that Repo yet, I’ve been going around the houses trying to fix a problem which some simple unit tests would have flagged 2 days ago. The return wasn’t erroring if the user isn’t there AND was returning a Collection when it should have been giving me a Model

So along with unit testing positive results from a successful method call, we should be writing two other types of tests.

The Exception Test.

Clearly this method name says, find…OR FAIL!!!! However, it wasn’t throwing a ModelNotFoundException on failing, it was just returning a Collection!

The tests I have written to assert it’s working now,


// UserRepositoryInterfaceTest.php /** * @expectedException ErrorException */ public function test_findByUidOrFail_incorrect_params() { $records = $this->theRepo->findByUidOrFail(); } /** * @expectedException Illuminate\Database\Eloquent\ModelNotFoundException */ public function test_findByUidOrFail_modelNotFound() { $this->theRepo->findByUidOrFail("foo"); }

The returned type Test.

It seems weird to test you’re getting the write variable type back, however, it’s crucially important. Because what if you expect an integer, 2, and you’re returned a string of “2”. Any triple if’s === would fail and probably throw something else off.

So we test for cast types. In this example, I assert the Model by looking for a certain method’s availability or not.

// UserRepositoryInterfaceTest.php

public function test_findByUidOrFail_is_model()
{
    $record = $this->helper->createAUser();
    $result = $this->theRepo->findByUidOrFail($record->uid);

    $this->helper->assertIsModel($result);
}

// TestHelper.php

public function assertIsModel($obj)
{
    PHPUnit::assertEquals(
        method_exists($obj, 'getTable'),
        true,
        'obj is not a Model'
    );
}

Women in Leadership, a simple write-up

I was fortunate enough to attend a Women in Leadership briefing at WMG today which was very interesting. It was a short, high-level run down from training two of our colleagues have attended.

From the outset, it’s clear there’s evidence showing some old ways of thinking and practices around! Some of them which will act to block or slow women gaining leadership roles. Also, some really classic actions of self promotion which generally men might naturally do, but women may find foreign.

The session wasn’t delivered from a “Man vs Woman” angle, but an expected person centric viewpoint of “Know Thyself”. In-fact, most of the tools or techniques seemed to be just slightly altered slants on a lot of training I’ve already been lucky to have myself with Inge at Polygot coaching or the Agile Bear training… Ironically though, the charts and diagrams were just in a more pastelly’ colour!

It’s important to acknowledge however that Women do face extra challenges in the workplace due to some pretty old draconian thinkings of those in leadership roles already. For example, Tim *unt two days before this briefing session said something pretty dum, (http://www.independent.co.uk/news/uk/home-news/women-scientists-distract-men-fall-in-love-with-them-and-cry-when-criticised-says-nobel-prize-winner-10309125.html)

This however sparked a brilliantly British amusing response online, with women posting tweets of them crying into their lab goggles and showing off their flattering curves in a massive HASMAT suit.

Moving on from the old ways restrictive ways of thinking, another part of the training was around how you “expose” yourself! Focussing on evidence based research, it showed Exposure to the right people with your work rather than working hard is more likely to earn yourself a promotion. Here’s some tips that were shared,

Career success is not based on performance
* Performance 10%, Image 30%, Exposure 60%
* Strong authentic personal brand
* Represent your manger/tea, at meeting
* Find ways to be seen outside (committees)
* Be seen by the people who matter
* Contribute in meetings and conference calls
* Take opportunities for speaking
* Act with integrity at all times
* Be authentic – be assertive about what you believe is important
* Become a subject matter expert
* “Getting tech and people working”

Very interesting session indeed, , and glad I could attend and not feel like the male scapegoat in the room :)

Against the Repository Command pattern…

So a while back I wrote an article about trying out a new pattern, “the repository and command pattern“.

Since using it in one of our major projects I have found it not all that great. So, yes it’s nice having it split from the Repo which I see as a way of searching on data, however, it’s a pain in the wotsit to test. Also, in Laravel it seems to add a lot of extra un-necessary time to my workflow.

The real problem however appears to be a mis-interpretation of what Commands are used for. Since Laravel 5.1 was released it has re-named Commands to Jobs. Highlighting that they should be used more so for delayed tasks rather than, inserting new models NOW!

So, it’ll take time to un-do I imagine and move them into the repository, however I’m glad I tried it as I’ve learnt a lot about testing!

The Repository and Command Pattern…

So I’m a big fan of the Repository Pattern with Laravel. Using interfaces it separates the logic of searching away from the models and also acts as a place to store all your searching commands.

http://bosnadev.com/2015/03/07/using-repository-pattern-in-laravel-5/

However sometimes I feel like the definition goes to far and needs splitting out. It might only be me making a rod for my own coding back, however, the repository makes sense to me only as a data access place, but not a wrapper for CRUD like operations.

So I split my repos out, there’s a base Class to extend which has some generic methods findOrFail, allPaginate. Then inside each extension are methods which search more specifically for some data.

However, for storing a new model I use a SelfHandling Command / Job.

class ProjectStoreCommand extends Command implements SelfHandling {

and the same for Destroy and Update.

It does make for more tests, but having the repo as a place for too much doesn’t sit right with the cleanliness of a Repository for me.

Disable the CSRF token in Laravel 5

Just a #HTH

Often when you’re devving’ forms in Laravel a quick refresh of the page rightly errors on the CSRF token. This is a bit of a bummer if you want to keep testing the same request, so all I do is…

Goto App/Http/Kernel.php and comment out,

// 'App\Http\Middleware\VerifyCsrfToken',

Then you can dev to your heart’s content, just remember to un-comment it! Maybe write a unit test to check it’s on before allowing you to push or create a merge request. Like one that alters the hidden field and submits.

The missing route in Laravel Route::resource…

The Route::resource method in routes.php Laravel 5 is brilliant. It saves time setting up simple CRUD routes and consolidates lots of routes into one method.

However, I’m not sure the Create and Update route both have a pre-route for the form however Destroy doesn’t?

I know the Store and Update commands both need to have a form of data fed to them, however… all my Destroy commands need a page to check the user is sure they want to delete the resource. So all my routes resource calls have this “delete” GET with them,

Route::resource('taxonomy', 'TaxonomyController');
Route::get('taxonomy/{id}/delete', [
'as' => 'taxonomy.delete', 'uses' => 'TaxonomyController@delete'
]);

Otherwise, people are tempted to use a Javascript confirm box as the only way to check people want to delete something first. However, that’s a bit dumb :) JS alert boxes are fiddly, also don’t fit with most site’s design styles and if your browser has JS off, your user is screwed.