Add datbase setup
This commit is contained in:
@@ -0,0 +1,260 @@
|
||||
{% extends "bootstrap/base.html" %}
|
||||
|
||||
{% block title %}Database Setup - MOTM Admin{% endblock %}
|
||||
|
||||
{% block head %}
|
||||
{{ super() }}
|
||||
<style>
|
||||
.database-section {
|
||||
margin-bottom: 30px;
|
||||
padding: 20px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
|
||||
.database-section h3 {
|
||||
margin-top: 0;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.btn-group {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.alert {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.current-config {
|
||||
background-color: #e8f4f8;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.current-config h4 {
|
||||
margin-top: 0;
|
||||
color: #2c3e50;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<h1>Database Setup & Configuration</h1>
|
||||
<p class="lead">Configure and initialize the database for the MOTM application.</p>
|
||||
|
||||
<!-- Current Configuration Display -->
|
||||
<div class="current-config">
|
||||
<h4>Current Configuration</h4>
|
||||
<p><strong>Database Type:</strong> {{ current_config.database_type|title }}</p>
|
||||
{% if current_config.database_type == 'sqlite' %}
|
||||
<p><strong>Database File:</strong> {{ current_config.sqlite_database_path }}</p>
|
||||
{% elif current_config.database_type == 'mysql' %}
|
||||
<p><strong>Host:</strong> {{ current_config.mysql_host }}:{{ current_config.mysql_port }}</p>
|
||||
<p><strong>Database:</strong> {{ current_config.mysql_database }}</p>
|
||||
<p><strong>Username:</strong> {{ current_config.mysql_username }}</p>
|
||||
{% elif current_config.database_type == 'postgresql' %}
|
||||
<p><strong>Host:</strong> {{ current_config.postgres_host }}:{{ current_config.postgres_port }}</p>
|
||||
<p><strong>Database:</strong> {{ current_config.postgres_database }}</p>
|
||||
<p><strong>Username:</strong> {{ current_config.postgres_username }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<!-- Flash Messages -->
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
{% for category, message in messages %}
|
||||
<div class="alert alert-{{ 'danger' if category == 'error' else 'success' }} alert-dismissible" role="alert">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
{{ message }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
|
||||
<!-- Database Setup Form -->
|
||||
<form method="POST" action="{{ url_for('database_setup') }}">
|
||||
{{ form.hidden_tag() }}
|
||||
|
||||
<!-- Database Type Selection -->
|
||||
<div class="database-section">
|
||||
<h3>Database Type</h3>
|
||||
<div class="form-group">
|
||||
{{ form.database_type.label(class="control-label") }}
|
||||
{{ form.database_type(class="form-control") }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SQLite Configuration -->
|
||||
<div class="database-section" id="sqlite-config">
|
||||
<h3>SQLite Configuration</h3>
|
||||
<div class="form-group">
|
||||
{{ form.sqlite_database_path.label(class="control-label") }}
|
||||
{{ form.sqlite_database_path(class="form-control") }}
|
||||
<small class="form-text text-muted">Path to the SQLite database file</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- MySQL Configuration -->
|
||||
<div class="database-section" id="mysql-config">
|
||||
<h3>MySQL/MariaDB Configuration</h3>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
{{ form.mysql_host.label(class="control-label") }}
|
||||
{{ form.mysql_host(class="form-control") }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
{{ form.mysql_port.label(class="control-label") }}
|
||||
{{ form.mysql_port(class="form-control") }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
{{ form.mysql_database.label(class="control-label") }}
|
||||
{{ form.mysql_database(class="form-control") }}
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
{{ form.mysql_username.label(class="control-label") }}
|
||||
{{ form.mysql_username(class="form-control") }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
{{ form.mysql_password.label(class="control-label") }}
|
||||
{{ form.mysql_password(class="form-control") }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
{{ form.mysql_charset.label(class="control-label") }}
|
||||
{{ form.mysql_charset(class="form-control") }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- PostgreSQL Configuration -->
|
||||
<div class="database-section" id="postgresql-config">
|
||||
<h3>PostgreSQL Configuration</h3>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
{{ form.postgres_host.label(class="control-label") }}
|
||||
{{ form.postgres_host(class="form-control") }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
{{ form.postgres_port.label(class="control-label") }}
|
||||
{{ form.postgres_port(class="form-control") }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
{{ form.postgres_database.label(class="control-label") }}
|
||||
{{ form.postgres_database(class="form-control") }}
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
{{ form.postgres_username.label(class="control-label") }}
|
||||
{{ form.postgres_username(class="form-control") }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
{{ form.postgres_password.label(class="control-label") }}
|
||||
{{ form.postgres_password(class="form-control") }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Setup Options -->
|
||||
<div class="database-section">
|
||||
<h3>Setup Options</h3>
|
||||
<div class="form-group">
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
{{ form.initialize_tables() }} {{ form.initialize_tables.label.text }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
{{ form.create_sample_data() }} {{ form.create_sample_data.label.text }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Action Buttons -->
|
||||
<div class="btn-group">
|
||||
{{ form.test_connection(class="btn btn-info") }}
|
||||
{{ form.save_config(class="btn btn-primary") }}
|
||||
{{ form.initialize_database(class="btn btn-success") }}
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<!-- Navigation -->
|
||||
<div class="row" style="margin-top: 30px;">
|
||||
<div class="col-md-12">
|
||||
<a href="{{ url_for('database_status') }}" class="btn btn-default">View Database Status</a>
|
||||
<a href="{{ url_for('motm_admin') }}" class="btn btn-default">Back to MOTM Admin</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Show/hide database configuration sections based on selected type
|
||||
function toggleDatabaseConfig() {
|
||||
var dbType = document.getElementById('database_type').value;
|
||||
|
||||
// Hide all config sections
|
||||
document.getElementById('sqlite-config').style.display = 'none';
|
||||
document.getElementById('mysql-config').style.display = 'none';
|
||||
document.getElementById('postgresql-config').style.display = 'none';
|
||||
|
||||
// Show relevant config section
|
||||
if (dbType === 'sqlite') {
|
||||
document.getElementById('sqlite-config').style.display = 'block';
|
||||
} else if (dbType === 'mysql') {
|
||||
document.getElementById('mysql-config').style.display = 'block';
|
||||
} else if (dbType === 'postgresql') {
|
||||
document.getElementById('postgresql-config').style.display = 'block';
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize on page load
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
toggleDatabaseConfig();
|
||||
|
||||
// Add event listener for database type changes
|
||||
document.getElementById('database_type').addEventListener('change', toggleDatabaseConfig);
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,162 @@
|
||||
{% extends "bootstrap/base.html" %}
|
||||
|
||||
{% block title %}Database Status - MOTM Admin{% endblock %}
|
||||
|
||||
{% block head %}
|
||||
{{ super() }}
|
||||
<style>
|
||||
.status-card {
|
||||
margin-bottom: 20px;
|
||||
padding: 20px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
|
||||
.status-card h3 {
|
||||
margin-top: 0;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.status-item {
|
||||
margin-bottom: 10px;
|
||||
padding: 10px;
|
||||
background-color: white;
|
||||
border-radius: 3px;
|
||||
border-left: 4px solid #3498db;
|
||||
}
|
||||
|
||||
.status-item.success {
|
||||
border-left-color: #27ae60;
|
||||
}
|
||||
|
||||
.status-item.error {
|
||||
border-left-color: #e74c3c;
|
||||
}
|
||||
|
||||
.status-item.warning {
|
||||
border-left-color: #f39c12;
|
||||
}
|
||||
|
||||
.status-label {
|
||||
font-weight: bold;
|
||||
color: #2c3e50;
|
||||
}
|
||||
|
||||
.status-value {
|
||||
color: #7f8c8d;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
margin-top: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.btn {
|
||||
margin: 0 10px;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<h1>Database Status</h1>
|
||||
<p class="lead">Current database configuration and connection status.</p>
|
||||
|
||||
<!-- Database Status Card -->
|
||||
<div class="status-card">
|
||||
<h3>Database Information</h3>
|
||||
|
||||
<div class="status-item {{ 'success' if 'Connected' in db_info.connection_status else 'error' }}">
|
||||
<div class="status-label">Connection Status:</div>
|
||||
<div class="status-value">{{ db_info.connection_status }}</div>
|
||||
</div>
|
||||
|
||||
<div class="status-item">
|
||||
<div class="status-label">Database Type:</div>
|
||||
<div class="status-value">{{ db_info.database_type|title }}</div>
|
||||
</div>
|
||||
|
||||
<div class="status-item">
|
||||
<div class="status-label">Database URL:</div>
|
||||
<div class="status-value">{{ db_info.database_url }}</div>
|
||||
</div>
|
||||
|
||||
<div class="status-item">
|
||||
<div class="status-label">Tables Count:</div>
|
||||
<div class="status-value">{{ db_info.table_count }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Quick Actions -->
|
||||
<div class="status-card">
|
||||
<h3>Quick Actions</h3>
|
||||
<div class="action-buttons">
|
||||
<a href="{{ url_for('database_setup') }}" class="btn btn-primary">
|
||||
<i class="glyphicon glyphicon-cog"></i> Database Setup
|
||||
</a>
|
||||
<a href="{{ url_for('motm_admin') }}" class="btn btn-default">
|
||||
<i class="glyphicon glyphicon-arrow-left"></i> Back to MOTM Admin
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Database Tables Information -->
|
||||
{% if db_info.table_count != 'Unknown' and db_info.table_count > 0 %}
|
||||
<div class="status-card">
|
||||
<h3>Database Tables</h3>
|
||||
<p>The database contains {{ db_info.table_count }} tables. The following tables are available:</p>
|
||||
<ul>
|
||||
<li><strong>players</strong> - Player information and details</li>
|
||||
<li><strong>clubs</strong> - Hockey club information</li>
|
||||
<li><strong>teams</strong> - Team information and league details</li>
|
||||
<li><strong>match_squad</strong> - Match squad selections</li>
|
||||
<li><strong>hockey_fixtures</strong> - Match fixtures and results</li>
|
||||
<li><strong>admin_settings</strong> - Application configuration</li>
|
||||
<li><strong>motm_votes</strong> - Man of the Match voting data</li>
|
||||
<li><strong>match_comments</strong> - Match comments and feedback</li>
|
||||
<li><strong>hockey_users</strong> - User authentication data</li>
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- Configuration Help -->
|
||||
<div class="status-card">
|
||||
<h3>Configuration Help</h3>
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<h4>SQLite</h4>
|
||||
<p>Best for development and small deployments. No server required.</p>
|
||||
<ul>
|
||||
<li>File-based database</li>
|
||||
<li>No installation required</li>
|
||||
<li>Good for testing</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<h4>MySQL/MariaDB</h4>
|
||||
<p>Popular choice for web applications. Good performance and reliability.</p>
|
||||
<ul>
|
||||
<li>Server-based database</li>
|
||||
<li>Good for production</li>
|
||||
<li>Wide hosting support</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<h4>PostgreSQL</h4>
|
||||
<p>Advanced features and excellent performance. Great for complex applications.</p>
|
||||
<ul>
|
||||
<li>Advanced SQL features</li>
|
||||
<li>Excellent performance</li>
|
||||
<li>Strong data integrity</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -55,6 +55,14 @@
|
||||
<h4 class="list-group-item-heading">Player of the Year</h4>
|
||||
<p class="list-group-item-text">View season totals and Player of the Year standings</p>
|
||||
</a>
|
||||
<a href="/admin/database-setup" class="list-group-item">
|
||||
<h4 class="list-group-item-heading">Database Setup</h4>
|
||||
<p class="list-group-item-text">Configure and initialize the database</p>
|
||||
</a>
|
||||
<a href="/admin/database-status" class="list-group-item">
|
||||
<h4 class="list-group-item-heading">Database Status</h4>
|
||||
<p class="list-group-item-text">View current database configuration and status</p>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user