[PR #484] [MERGED] feat: support transfer address from user to user #590

Closed
opened 2026-02-26 21:31:56 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/dreamhunter2333/cloudflare_temp_email/pull/484
Author: @dreamhunter2333
Created: 11/14/2024
Status: Merged
Merged: 11/14/2024
Merged by: @dreamhunter2333

Base: mainHead: feature/dev


📝 Commits (2)

  • cfda051 feat: support transfer address from user to user
  • df453cd feat: remove service worker

📊 Changes

7 files changed (+159 additions, -9 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 db/schema.sql (+1 -1)
📝 frontend/src/main.js (+0 -4)
📝 frontend/src/views/user/AddressManagement.vue (+65 -2)
📝 frontend/vite.config.js (+1 -1)
📝 worker/src/user_api/bind_address.ts (+90 -1)
📝 worker/src/user_api/index.ts (+1 -0)

📄 Description

User description

如果你是全新部署,不需要迁移数据,下面的内容可以忽略,可以离开本文档了。

如果要用户间转移邮箱地址,并需要之前的用户无法登录,就需要进行数据迁移操作。因为目前的表结构最大的 ID 会被重复使用,所以转移最大 id 的邮箱会导致 ID 相同,如果你并不在意这件事可以忽略下面的步骤。

下面是更改表结构的详细步骤

  1. 创建新表:
    为了增加新的特性(例如 AUTOINCREMENT)并且保留现有 id,您需要创建一个新表。确保新表结构与原始表完全一致,只是在 id 列上添加 AUTOINCREMENT。
    CREATE TABLE address_new (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT UNIQUE,
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
    );

  2. 从旧表迁移数据到新表:
    这里,我们需要保留所有字段,包括 id 列。因此,插入时要明确指定各个字段:
    INSERT INTO address_new (id, name, created_at, updated_at)
    SELECT id, name, created_at, updated_at FROM address;

  3. 验证迁移数据:
    迁移后,我们需要验证新表中的数据是否与旧表一致,包括 id 值是否正确迁移:
    SELECT * FROM address_new;

  4. 重命名旧表:
    在迁移数据成功并验证之后,可以重命名旧表以备用:
    ALTER TABLE address RENAME TO address_old;

  5. 将新表重命名为原始表的名称:
    紧接着,将新表重命名为原始表名,以便应用程序继续使用相同的表名:
    ALTER TABLE address_new RENAME TO address;

  6. 最终验证:
    确认新命名的表结构和数据:
    PRAGMA table_info(address);
    SELECT * FROM address;

  7. 删除旧表(可选):
    确认一切工作正常并且不再需要旧表后,可以删除旧表以释放空间(此步骤是可选的):
    DROP TABLE address_old;

完整示例

以下是从创建新表、迁移数据到最终重命名表的完整 SQL 示例:

-- Step 1: 创建新的 table
CREATE TABLE address_new (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT UNIQUE,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);

-- Step 2: 从旧表迁移数据,包括 id 列
INSERT INTO address_new (id, name, created_at, updated_at)
SELECT id, name, created_at, updated_at FROM address;

-- Step 3: 验证迁移
SELECT * FROM address_new;

-- Step 4: 重命名旧表
ALTER TABLE address RENAME TO address_old;

-- Step 5: 将新表重命名为旧表名称
ALTER TABLE address_new RENAME TO address;

-- Step 6: 最终验证
PRAGMA table_info(address);
SELECT * FROM address;

-- Step 7: 删除旧表(可选)
DROP TABLE address_old;

通过上述步骤,您将成功地迁移旧表的数据至新表,包括 id 列的完整保留,并有效实现 AUTOINCREMENT。


PR Type

Enhancement, Documentation


Description

  • Added new UI elements and logic in the frontend to support transferring addresses between users.
  • Implemented a new API endpoint in the backend to handle the transfer of addresses between users.
  • Updated the database schema to use AUTOINCREMENT for the id column in the address table.
  • Documented the new feature in the changelog.

Changes walkthrough 📝

Relevant files
Enhancement
AddressManagement.vue
Add UI and logic for transferring addresses between users

frontend/src/views/user/AddressManagement.vue

  • Added new UI elements for transferring addresses between users.
  • Added new modal for address transfer confirmation.
  • Added new methods for handling address transfer logic.
  • +65/-2   
    bind_address.ts
    Implement API endpoint and logic for address transfer       

    worker/src/user_api/bind_address.ts

  • Added new API endpoint for transferring addresses between users.
  • Implemented logic to check and transfer addresses.
  • Updated error handling for address unbinding.
  • +90/-1   
    index.ts
    Add route for address transfer API endpoint                           

    worker/src/user_api/index.ts

    • Added route for the new address transfer API endpoint.
    +1/-0     
    schema.sql
    Update address table schema to use AUTOINCREMENT                 

    db/schema.sql

  • Updated address table schema to use AUTOINCREMENT for the id column.
  • +1/-1     
    Documentation
    CHANGELOG.md
    Update changelog with address transfer feature                     

    CHANGELOG.md

  • Documented the new feature for transferring addresses between users.
  • +1/-0     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information


    🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

    ## 📋 Pull Request Information **Original PR:** https://github.com/dreamhunter2333/cloudflare_temp_email/pull/484 **Author:** [@dreamhunter2333](https://github.com/dreamhunter2333) **Created:** 11/14/2024 **Status:** ✅ Merged **Merged:** 11/14/2024 **Merged by:** [@dreamhunter2333](https://github.com/dreamhunter2333) **Base:** `main` ← **Head:** `feature/dev` --- ### 📝 Commits (2) - [`cfda051`](https://github.com/dreamhunter2333/cloudflare_temp_email/commit/cfda05187ff8c09ec1c69feb5feb83f2a0644dbc) feat: support transfer address from user to user - [`df453cd`](https://github.com/dreamhunter2333/cloudflare_temp_email/commit/df453cdda750cbacead0d573c7c7ab63e3a42bb1) feat: remove service worker ### 📊 Changes **7 files changed** (+159 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `db/schema.sql` (+1 -1) 📝 `frontend/src/main.js` (+0 -4) 📝 `frontend/src/views/user/AddressManagement.vue` (+65 -2) 📝 `frontend/vite.config.js` (+1 -1) 📝 `worker/src/user_api/bind_address.ts` (+90 -1) 📝 `worker/src/user_api/index.ts` (+1 -0) </details> ### 📄 Description ### **User description** 如果你是全新部署,不需要迁移数据,下面的内容可以忽略,可以离开本文档了。 如果要用户间转移邮箱地址,并需要之前的用户无法登录,就需要进行数据迁移操作。因为目前的表结构最大的 ID 会被重复使用,所以转移最大 id 的邮箱会导致 ID 相同,如果你并不在意这件事可以忽略下面的步骤。 下面是更改表结构的详细步骤 1. 创建新表: 为了增加新的特性(例如 AUTOINCREMENT)并且保留现有 id,您需要创建一个新表。确保新表结构与原始表完全一致,只是在 id 列上添加 AUTOINCREMENT。 CREATE TABLE address_new ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ); 2. 从旧表迁移数据到新表: 这里,我们需要保留所有字段,包括 id 列。因此,插入时要明确指定各个字段: INSERT INTO address_new (id, name, created_at, updated_at) SELECT id, name, created_at, updated_at FROM address; 3. 验证迁移数据: 迁移后,我们需要验证新表中的数据是否与旧表一致,包括 id 值是否正确迁移: SELECT * FROM address_new; 4. 重命名旧表: 在迁移数据成功并验证之后,可以重命名旧表以备用: ALTER TABLE address RENAME TO address_old; 5. 将新表重命名为原始表的名称: 紧接着,将新表重命名为原始表名,以便应用程序继续使用相同的表名: ALTER TABLE address_new RENAME TO address; 6. 最终验证: 确认新命名的表结构和数据: PRAGMA table_info(address); SELECT * FROM address; 7. 删除旧表(可选): 确认一切工作正常并且不再需要旧表后,可以删除旧表以释放空间(此步骤是可选的): DROP TABLE address_old; 完整示例 以下是从创建新表、迁移数据到最终重命名表的完整 SQL 示例: -- Step 1: 创建新的 table CREATE TABLE address_new ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ); -- Step 2: 从旧表迁移数据,包括 id 列 INSERT INTO address_new (id, name, created_at, updated_at) SELECT id, name, created_at, updated_at FROM address; -- Step 3: 验证迁移 SELECT * FROM address_new; -- Step 4: 重命名旧表 ALTER TABLE address RENAME TO address_old; -- Step 5: 将新表重命名为旧表名称 ALTER TABLE address_new RENAME TO address; -- Step 6: 最终验证 PRAGMA table_info(address); SELECT * FROM address; -- Step 7: 删除旧表(可选) DROP TABLE address_old; 通过上述步骤,您将成功地迁移旧表的数据至新表,包括 id 列的完整保留,并有效实现 AUTOINCREMENT。 ___ ### **PR Type** Enhancement, Documentation ___ ### **Description** - Added new UI elements and logic in the frontend to support transferring addresses between users. - Implemented a new API endpoint in the backend to handle the transfer of addresses between users. - Updated the database schema to use AUTOINCREMENT for the `id` column in the `address` table. - Documented the new feature in the changelog. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><table> <tr> <td> <details> <summary><strong>AddressManagement.vue</strong><dd><code>Add UI and logic for transferring addresses between users</code></dd></summary> <hr> frontend/src/views/user/AddressManagement.vue <li>Added new UI elements for transferring addresses between users.<br> <li> Added new modal for address transfer confirmation.<br> <li> Added new methods for handling address transfer logic.<br> </details> </td> <td><a href="https://github.com/dreamhunter2333/cloudflare_temp_email/pull/484/files#diff-5335bdd9b323e39aa20e1c5a80f4eead4f05d7fdf92cc3cfc6a580cf5e1db97f">+65/-2</a>&nbsp; &nbsp; </td> </tr> <tr> <td> <details> <summary><strong>bind_address.ts</strong><dd><code>Implement API endpoint and logic for address transfer</code>&nbsp; &nbsp; &nbsp; &nbsp; </dd></summary> <hr> worker/src/user_api/bind_address.ts <li>Added new API endpoint for transferring addresses between users.<br> <li> Implemented logic to check and transfer addresses.<br> <li> Updated error handling for address unbinding.<br> </details> </td> <td><a href="https://github.com/dreamhunter2333/cloudflare_temp_email/pull/484/files#diff-ada3e8ad268246f0c99c97065551303c02fded466c73a4f525f6206cb49bdebf">+90/-1</a>&nbsp; &nbsp; </td> </tr> <tr> <td> <details> <summary><strong>index.ts</strong><dd><code>Add route for address transfer API endpoint</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary> <hr> worker/src/user_api/index.ts - Added route for the new address transfer API endpoint. </details> </td> <td><a href="https://github.com/dreamhunter2333/cloudflare_temp_email/pull/484/files#diff-5295b4a62dc27ad938da4f5769e8c944b01cff33c3e76ce16ebf21c6d81144d1">+1/-0</a>&nbsp; &nbsp; &nbsp; </td> </tr> <tr> <td> <details> <summary><strong>schema.sql</strong><dd><code>Update address table schema to use AUTOINCREMENT</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary> <hr> db/schema.sql <li>Updated <code>address</code> table schema to use AUTOINCREMENT for the <code>id</code> column.<br> </details> </td> <td><a href="https://github.com/dreamhunter2333/cloudflare_temp_email/pull/484/files#diff-948c089a4de6325dd9a8f187fb0116272dedf46306023dce6d70b548e9f7539c">+1/-1</a>&nbsp; &nbsp; &nbsp; </td> </tr> </table></td></tr><tr><td><strong>Documentation</strong></td><td><table> <tr> <td> <details> <summary><strong>CHANGELOG.md</strong><dd><code>Update changelog with address transfer feature</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary> <hr> CHANGELOG.md <li>Documented the new feature for transferring addresses between users.<br> </details> </td> <td><a href="https://github.com/dreamhunter2333/cloudflare_temp_email/pull/484/files#diff-06572a96a58dc510037d5efa622f9bec8519bc1beab13c9f251e97e657a9d4ed">+1/-0</a>&nbsp; &nbsp; &nbsp; </td> </tr> </table></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: Comment `/help "your question"` on any pull request to receive relevant information --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
    kerem 2026-02-26 21:31:56 +03:00
    Sign in to join this conversation.
    No milestone
    No project
    No assignees
    1 participant
    Notifications
    Due date
    The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

    No due date set.

    Dependencies

    No dependencies set.

    Reference
    starred/cloudflare_temp_email#590
    No description provided.