Thoughts On Contentful Migrations

Contententful have a wonderful headless CMS. It has a UI for the content editors but the developers get a stream of JSON. This means that the consuming application is free to do anything with the output – which is a major contrast to other CMS systems.

Contentful have a CLI tool that allows migrations to be applied to the schemas (and content). This is not the approach that my team has taken (largely because the migration tool did not exist when we needed it).

Our approach is to have a declarative content schema in code. On deployment it compares this to the environments current state and attempts to upgrade it.

Upgrades happen on a field level of each content type. Once a content type has been upgraded then the widget type for each field is set.

We don’t attempt to remove fields or migrate data as we have not in two years had the need to automate this (we have manually removed a few fields or redundant content types).

This approach is closer to desired state configuration than migrations. It has the benefit of acting as it’s own complete documentation.

 

Eight Influential Development Books

Here are eight influential books that relate to software development:

The classic:20180526_183055

Introducing techniques:

20180526_183109.jpg

The skills around development:

20180526_183115.jpg

How to unit test anything:

20180526_183120.jpg

How to stretch your knowledge:

20180526_183129

How to stretch your knowledge further:

20180526_183135.jpg

How to explain your new ideas to other people:

20180526_183254.jpg

Information about Quality, Gumption Traps and The Scientific Method:

20180526_183142.jpg

Redux CombineReducers is broken

Recently I have started using react redux. It’s amazing how complex React/Redux makes even the simplest task.

I needed to pass an environment value through to the client side rendered ui. This was to allow the component to vary by environment – something essential in a dev -> qa -> preprod -> live pipeline.

You need to pass this into the store and map it out into the state of your component. All of the documentation and examples seem to care about is state mutation. The trivial case is overlooked.

The app that I am working on has multiple reducers that are combined with CombineReducers. This has the interesting side effect of dropping any state that is not included in a reducer.

This is not accidental it actually warns you (cryptically) that it is doing it.

I solved this for now by creating an idempotentReducer that simply returns the state. This is not a good long term solution.

The documentation on CombineReducers does state that it is intended for simple cases. I can’t imagine why passing through static state is not the simplest case.

Phoenix for Rails Developers – Part 3

I have now completed the book (although not all of the bonus exercises).

https://github.com/chriseyre2000/storex

The remainder of the book demonstrated extensions to the application to create an administration mode. This shows how you extend an existing application.

Overall the book is a gentle introduction to Phoenix and avoids introducing some of the more complex features (there is no attempt to explain OTP or Channels).

The code struct has been easy to follow with the examples being split into the correct sized chunks. This is in comparison to Learn React Native who code samples were excessive given that you needed to type in several pages of code before anything could be checked.

I did find a few typos which the author says are due to be corrected soon (an early view of the contents of the database includes the admin flag, some brackets are missing on some of the redirects and the validate_max_price method breaks when the price is null).

This has been a very useful addition to my Elixir/Phoenix study library.

It is interesting to compare the changes in the Phoenix framework between the Learning Phoenix book and this one. The major difference is the movement of the model from within the Phoenix app itself (storex_web) into a library (storex).

The only variation I took from the book was to add Credo:

{:credo, “~> 0.9.0”}
This is a style and code recommendation tool that use gets suggested in a number of places.
This adds a number of styling warnings for any application. It can be customised but does encourage good practice.
I have fixed up some of the hints (spacing issues, don’t use cond with only one non-true condition).

Learning React Native – Part One

I am now trying to learn react-native from the book Learning React Native.

These are my notes that may help other people following this path.

First problem:

You can’t use npm 5 with create-react-native-app.

This can be resolved by using

npm install -g npm@4.6.1

This will roll npm back to a known good version. Later versions may work (and by the time you read this (it’s April 2018 as I write this) things may have moved on.

 

Note that you will also need to install the Expo app onto your phone.

The phone and your machine need to be on the same network.

This is for the first version of the app that was deployed.

There is also a react-native-cli version, but that requires a more complex android setup.

If you are using Expo it has a built in QR reader.

You may also need to register your own api code to use openweathermap.org.

It’s a bad idea to publish a public key for a free service.

So far this book seems less professionally written than the pragprog
 books that I have been working through recently. 
It does not seem to flow well and has a few rough edges. 
Typically code is added piecemeal but requires style details that 
are not supplied until the full sample.

The weather app is slightly broken. Image can no longer have children. There was no stated version of create-react-native-app so I have installed the latest.

That’s it for now – just finished Chapter 3

Note this is the end of this series of articles. The book was found to have so many broken examples that it was not worth continuing.

Linux Development on Android

It is now possible to start Linux Development on an android device:

https://medium.freecodecamp.org/building-a-node-js-application-on-android-part-1-termux-vim-and-node-js-dfa90c28958f

The above article shows how to install enough onto your phone to allow basic development.

Here is some of the history from my first session

1 apt update && apt upgrade
2 apt install coreutils
8 which awk
9 which sed
10 which grep
11 which curl

# not found so installed via
12 pkg install curl
13 curl
19 apt install vim
21 apt install nodejs
22 which node
24 node -v
25 history

Given that I now have node, vim, curl, grep, awk and sed this looks to be a useful base platform.

Phoenix for Rails Developers – Part 2

I now have the code working upto the cart on the page.

https://github.com/chriseyre2000/storex

Elixir and Phoenix are still great for showing exactly where the error is.

This can be handy as Elixir is very picky on whitespace usage.

Frequent use of:

mix clean

mix phx.routes

Will show any compiler warnings. It’s best to keep on top of these as they do give you clues as to obvious typos. This is especially true of unused variables.

It’s great that a whole chapter was written test first – especially when this demonstrates the DDD concept of Contexts. This is my main bugbear on some of the other Elixir books – tests have been removed to save space.

Also when you add a Plug you need to restart the server – these are not automatically added.

Phoenix for Rails Developers – Part 1

I was lucky enough to win a copy of Phoenix for Rails Developers.

(Thanks to @plataformatec)

This gives me one more thing to study!

Oddly I am not a Rails developer (but have worked on a number of frameworks that were inspired by Rails).

So far I am working through the main examples and will post them here:

https://github.com/chriseyre2000/storex

I am developing this using Visual Studio Code.

Typically I also have two terminal tabs open.

The first is to run the application in:

mix phx.server

or

iex -S phx.server

The second is used for generator or to update git.

I am working with Elixir 1.6.4

So far the book is a gentle introduction to Phoenix. The language is introduced as needed.

It has stayed away from more complex Elixir topics (OTP).

When I have made typos the Elixir compiler will always tell you exactly where you have made the mistake, although it is not always obvious what the mistake was. The live reloading of the web application does allow for very rapid feedback. You do need to remember to restart the app on non-website changes.

The only catch that I have had so far is setting up Postgres locally. All other details have been clearly explained.