Migration from single text-node to collection

In my first application model, I added a single text-node with a reference, in a collection. It looks like this:

	'Concerts': collection ['Concert'] @icon: "event" {
		'Concert': text
		'Artist': text -> downstream ^ .'Artists'[]
}

Now I wanted to expand the model and add the full collection instead of just a text note. This in order to select multiple performing artists within a concert.

I added quite a few artists already, so I want to migrate the data instead of create empty.

I get this error:

state constraint violation for 'collection'. Unexpected state for 'type':
	- expected:  'collection' at /home/coder/project/migrations/from_release/migration.alan:6:123 to 6:132
	- but found: 'text' at /home/coder/project/migrations/from_release/from/application.alan:11:14 to 11:49
		defined by .'Concerten'.'Artiest' of type 'application'!'node'.'attributes'.'type'?'property' at /home/coder/project/migrations/from_release/from/application.alan:11:14 to 11:49
/home/coder/project/migrations/from_release/migration.alan

My question: how do I change the migration-file so that all my already added entries are being added to my newly created collection?

Thanks in advance :slight_smile:

Assuming your new structure looks like this:

'Concerts': collection ['Concert'] @icon: "event" {
	'Concert': text
	'Artists': collection ['Artist'] {
		'Artist': text -> downstream ^ ^ .'Artists'[]
	}
}

Then the migration can be written as follows:

'Concerts': collection = <! !> map ( $ .'Concerts'* ) as $ = (
	'Concert': text = $ .'Concert'
	'Artists': collection = <! !> = (
		'Artist': text = $ .'Artist'
	)
)

This creates an 'Artists' collection with one ‘Artist’ entry using the first version’s ‘Artist’ value. After migration, you will be able to have concerts with zero, one or more artists.

1 Like

Thanks, it works perfectly!