如何在现有系统上合并标签

发布于 2024-09-28 10:41:58 字数 698 浏览 4 评论 0原文

我们有一个简单的界面来标记特定问题

(e.g. entry has 1..many tags and each tag entry has a foriegn key pointer back to the entry table)

1.    What is the current production version of the jdk? (Tags: jdk6 jdk-6 jdk java)
2.    In what version was java.util.spi package introduced? (Tags: jdk-6, jdk7, jdk5)
3.    Which version of java is going to be released soon? (Tags: jdk-6, jdk7, jdk8)

我们希望将所有名为“jdk-6”的标签合并到jdk6。我们如何在即将投入生产但包含有用数据的系统中实现这一目标。

在[1]中,需要删除jdk-6,因为jdk6已经存在。 [2,3]中jdk-6需要重命名为“jdk6”。

我需要什么样的脚本才能有效地迁移这些数据。

编辑

create table entry (id, question, ...)
create table entry_tag (id, entry_id, tag)

We have a simple interface to tag a particular question

(e.g. entry has 1..many tags and each tag entry has a foriegn key pointer back to the entry table)

1.    What is the current production version of the jdk? (Tags: jdk6 jdk-6 jdk java)
2.    In what version was java.util.spi package introduced? (Tags: jdk-6, jdk7, jdk5)
3.    Which version of java is going to be released soon? (Tags: jdk-6, jdk7, jdk8)

We would like to merge all tags named as "jdk-6" to jdk6. How do we achieve this in a system which is nearing production but contains useful data.

In [1] jdk-6 needs to be removed, since jdk6 is already present. In [2,3] jdk-6 needs to be renamed as "jdk6".

What kind of scripts do I need to migrate this data in a effective fashion.

EDIT

create table entry (id, question, ...)
create table entry_tag (id, entry_id, tag)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一直在等你来 2024-10-05 10:41:58

我会执行以下操作:

  1. 用好的标签更新“坏”标签 (UPDATE TagTable SET Tag = 'jdk6' WHERE tag = 'jdk-6')

  2. 删除重复的标签(其中entry_id 和 Tag 相同)。具体如何执行此操作取决于表上是否有单独的唯一键,但快速谷歌将为您提供在不同情况下工作的各种方法。

  3. 假设您有一个包含所有可用标签列表的 TagsList 表,请从中删除 jdk-6 (DELETE FROM TagsList WHERE Tag = 'jdk-6')。

I would do the following:

  1. Update the "bad" tags with the good one (UPDATE TagTable SET Tag = 'jdk6' WHERE tag = 'jdk-6')

  2. Remove the duplicate tags (where entry_id and Tag are the same) . Exactly how you do this will depend on whether you have a separate unique key on the table or not, but a quick google will provide you with a variety of methods that work under different circumstances.

  3. Assuming you have a TagsList table with the list of all available tags, remove jdk-6 from it (DELETE FROM TagsList WHERE Tag = 'jdk-6').

清风不识月 2024-10-05 10:41:58

我首先创建一个新表,其中包含包含标签“jdk-6”或“jdk6”的条目 ID 列表。

然后我将删除标签“jdk6”和“jdk-6”的所有标签记录。

然后我将使用开始时创建的表将它们添加回来。

I would first create a new table with a list of entry IDs that contain either of the tags 'jdk-6' or 'jdk6'.

Then I would remove all tag records for the tags 'jdk6' and 'jdk-6'.

And then I would add them back in using the table created at the start.

戏剧牡丹亭 2024-10-05 10:41:58
/* Step 1 - Delete where both tags exist */
delete from et1
    from entry_tag et1
        inner join entry_tag et2
            on et1.entry_id = et2.entry_id
                and et2.tag = 'jdk6'
    where et1.tag = 'jdk-6'

/* Step 2 - Update remaining tags */
update entry_tag
    set tag = 'jdk6'
    where tag = 'jdk-6'
/* Step 1 - Delete where both tags exist */
delete from et1
    from entry_tag et1
        inner join entry_tag et2
            on et1.entry_id = et2.entry_id
                and et2.tag = 'jdk6'
    where et1.tag = 'jdk-6'

/* Step 2 - Update remaining tags */
update entry_tag
    set tag = 'jdk6'
    where tag = 'jdk-6'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文