{% extends "massmigration/base.html" %}

{% block content %}

<h1>Migration <code>{{migration.key}}</h1>
<p>{{migration.description}}</p>

<table class="table mt">

	<tr scope="row">
		<th>Backend</th>
		<td>{{migration.backend_str}}</td>
	</tr>
	<tr scope="row">
		<th>Database</th>
		<td>{{db_alias}}</td>
	</tr>
	<tr scope="row">
		<th>Dependencies</th>
		<td>
			{% for dependency in dependencies %}
				<div>
					<a href="{% url 'massmigration_detail' key=dependency.key db_alias=db_alias %}">{{dependency.key}}</a>
					({% if dependency.record %}{{dependency.record.status}}{% else %}NOT RUN{% endif %})
				</div>
			{% empty %}
				None
			{% endfor %}
		</td>
	</tr>
	<tr scope="row">
		<th>Status</th>
		<td>{% if record %}{{record.status}}{% else %}NOT RUN{% endif %}</td>
	</tr>
	<tr scope="row">
		<th>Started at</th>
		<td>{{record.initiated_at|default:'-'}}</td>
	</tr>
	<tr scope="row">
		<th>Finished at</th>
		<td>{{record.applied_at|default:'-'}}</td>
	</tr>
	<tr scope="row">
		<th>Was faked</th>
		<td>{% if record.applied_at %}{{record.was_faked|yesno}}{% else %}-{% endif %}</td>
	</tr>
	<tr scope="row">
		<th>Has error</th>
		<td>{{record.has_error|yesno}}</td>
	</tr>
	<tr scope="row">
		<th>Last error</th>
		<td><code>{{record.last_error|default:'-'}}</code></td>
	</tr>
</table>
<h2>Actions</h2>
<p>
	{% if not record %}<a href="{% url 'massmigration_run' key=migration.key db_alias=db_alias %}">Run...</a>
	{% else %}<a href="{% url 'massmigration_delete' key=migration.key db_alias=db_alias %}">Cancel/Delete...</a>
	{% endif %}
</p>

{% endblock %}