Compare commits
No commits in common. "08c54b1f750116aab07b8289fa12f2c37bebac73" and "4030cc90b28a39c980b69f5a553ef728a197eca1" have entirely different histories.
08c54b1f75
...
4030cc90b2
2 changed files with 17 additions and 44 deletions
|
|
@ -209,33 +209,25 @@ jobs:
|
||||||
env:
|
env:
|
||||||
FORGEJO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
FORGEJO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
# DELETE uses API v1, PUT uses the package upload API
|
PKG_URL="${GITHUB_SERVER_URL}/api/packages/${GITHUB_REPOSITORY_OWNER}/generic/simpl-resultat/latest"
|
||||||
DELETE_URL="${GITHUB_SERVER_URL}/api/v1/packages/${GITHUB_REPOSITORY_OWNER}/generic/simpl-resultat/latest"
|
|
||||||
UPLOAD_URL="${GITHUB_SERVER_URL}/api/packages/${GITHUB_REPOSITORY_OWNER}/generic/simpl-resultat/latest"
|
|
||||||
|
|
||||||
# Delete the old package version to avoid 409 conflicts
|
# Delete the old package version to avoid 409 conflicts
|
||||||
echo "Deleting old package version (if any)..."
|
echo "Deleting old package version (if any)..."
|
||||||
DEL_CODE=$(curl -s -w "%{http_code}" -X DELETE \
|
DEL_CODE=$(curl -s -w "%{http_code}" -X DELETE \
|
||||||
"${DELETE_URL}" \
|
"${PKG_URL}" \
|
||||||
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
||||||
-o /tmp/del_response.json)
|
-o /tmp/del_response.json)
|
||||||
echo "Delete HTTP $DEL_CODE"
|
echo "Delete HTTP $DEL_CODE"
|
||||||
# 204 = deleted, 404 = didn't exist (both OK)
|
|
||||||
if [ "$DEL_CODE" != "204" ] && [ "$DEL_CODE" != "404" ]; then
|
|
||||||
echo "WARNING: Unexpected delete response:"
|
|
||||||
cat /tmp/del_response.json
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Uploading latest.json to package registry..."
|
echo "Uploading latest.json to package registry..."
|
||||||
HTTP_CODE=$(curl -w "%{http_code}" -X PUT \
|
HTTP_CODE=$(curl -w "%{http_code}" -X PUT \
|
||||||
"${UPLOAD_URL}/latest.json" \
|
"${PKG_URL}/latest.json" \
|
||||||
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
--data-binary "@release-assets/latest.json" \
|
--data-binary "@release-assets/latest.json" \
|
||||||
-o /tmp/pkg_response.json)
|
-o /tmp/pkg_response.json)
|
||||||
echo "Upload HTTP $HTTP_CODE"
|
echo "Upload HTTP $HTTP_CODE"
|
||||||
if [ "$HTTP_CODE" != "201" ]; then
|
if [ "$HTTP_CODE" != "201" ]; then
|
||||||
echo "ERROR: Failed to publish latest.json:"
|
echo "Upload response:"
|
||||||
cat /tmp/pkg_response.json
|
cat /tmp/pkg_response.json
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sha2::{Digest, Sha256, Sha384};
|
use sha2::{Digest, Sha256};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use tauri::Manager;
|
use tauri::Manager;
|
||||||
|
|
||||||
|
|
@ -157,8 +157,8 @@ fn hex_encode(bytes: &[u8]) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Repair migration checksums for a profile database.
|
/// Repair migration checksums for a profile database.
|
||||||
/// Updates stored checksums to match current migration SQL, avoiding re-application
|
/// Deletes migration records that have mismatched checksums so they can be re-applied.
|
||||||
/// of destructive migrations (e.g., migration 2 which DELETEs categories/keywords).
|
/// This fixes the "migration X was previously applied but has been modified" error.
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn repair_migrations(app: tauri::AppHandle, db_filename: String) -> Result<bool, String> {
|
pub fn repair_migrations(app: tauri::AppHandle, db_filename: String) -> Result<bool, String> {
|
||||||
let app_dir = app
|
let app_dir = app
|
||||||
|
|
@ -174,6 +174,7 @@ pub fn repair_migrations(app: tauri::AppHandle, db_filename: String) -> Result<b
|
||||||
let conn = rusqlite::Connection::open(&db_path)
|
let conn = rusqlite::Connection::open(&db_path)
|
||||||
.map_err(|e| format!("Cannot open database: {}", e))?;
|
.map_err(|e| format!("Cannot open database: {}", e))?;
|
||||||
|
|
||||||
|
// Check if _sqlx_migrations table exists
|
||||||
let table_exists: bool = conn
|
let table_exists: bool = conn
|
||||||
.query_row(
|
.query_row(
|
||||||
"SELECT COUNT(*) > 0 FROM sqlite_master WHERE type='table' AND name='_sqlx_migrations'",
|
"SELECT COUNT(*) > 0 FROM sqlite_master WHERE type='table' AND name='_sqlx_migrations'",
|
||||||
|
|
@ -186,34 +187,14 @@ pub fn repair_migrations(app: tauri::AppHandle, db_filename: String) -> Result<b
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Current migration SQL — must match the vec in lib.rs
|
// Delete migration 1 record so it can be cleanly re-applied
|
||||||
let migrations: &[(i64, &str)] = &[
|
// Migration 1 is idempotent (CREATE IF NOT EXISTS + INSERT OR IGNORE)
|
||||||
(1, database::SCHEMA),
|
let deleted = conn
|
||||||
(2, database::SEED_CATEGORIES),
|
.execute(
|
||||||
];
|
"DELETE FROM _sqlx_migrations WHERE version = 1",
|
||||||
|
[],
|
||||||
|
)
|
||||||
|
.map_err(|e| format!("Cannot repair migrations: {}", e))?;
|
||||||
|
|
||||||
let mut repaired = false;
|
Ok(deleted > 0)
|
||||||
for (version, sql) in migrations {
|
|
||||||
let expected_checksum = Sha384::digest(sql.as_bytes()).to_vec();
|
|
||||||
|
|
||||||
// Check if this migration exists with a different checksum
|
|
||||||
let needs_repair: bool = conn
|
|
||||||
.query_row(
|
|
||||||
"SELECT COUNT(*) > 0 FROM _sqlx_migrations WHERE version = ?1 AND checksum != ?2",
|
|
||||||
rusqlite::params![version, expected_checksum],
|
|
||||||
|row| row.get(0),
|
|
||||||
)
|
|
||||||
.unwrap_or(false);
|
|
||||||
|
|
||||||
if needs_repair {
|
|
||||||
conn.execute(
|
|
||||||
"UPDATE _sqlx_migrations SET checksum = ?1 WHERE version = ?2",
|
|
||||||
rusqlite::params![expected_checksum, version],
|
|
||||||
)
|
|
||||||
.map_err(|e| format!("Cannot repair migration {}: {}", version, e))?;
|
|
||||||
repaired = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(repaired)
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue