gotosocial/internal/db/bundb/migrations
tobi 70d65b683f
[feature] Refetch emojis when they change on remote instances (#905)
* select emoji using image_static_url

* use updated on AP emojis

* allow refetch of updated emojis

* cheeky workaround for test

* clean up old files for refreshed emoji

* check error for originalPostData

* shorten GetEmojiByStaticImageURL

* delete kirby (sorry nintendo)
2022-10-13 15:16:24 +02:00
..
20211113114307_init Extend license notices to 2022 (#354) 2021-12-20 18:42:19 +01:00
20220214175650_media_cleanup [chore] update dependencies, bump to Go 1.19.1 (#826) 2022-09-28 18:30:40 +01:00
20220315160814_admin_account_actions [chore] update dependencies, bump to Go 1.19.1 (#826) 2022-09-28 18:30:40 +01:00
20220905150505_custom_emoji_updates [bug] fix unique constraint conflict (#820) 2022-09-12 13:58:31 +02:00
20211113114307_init.go Extend license notices to 2022 (#354) 2021-12-20 18:42:19 +01:00
20220214175650_media_cleanup.go [bugfix] use Exec to rename media_attachments (#498) 2022-04-28 08:43:41 +01:00
20220305130328_database_optimizations.go [performance] Database optimizations (#419) 2022-03-07 11:33:18 +01:00
20220315160814_admin_account_actions.go [feature] Admin account actions (#432) 2022-03-19 12:01:40 +01:00
20220502113806_add_missing_indexes.go add extra indexes as a migration (#527) 2022-05-02 13:55:48 +01:00
20220506110822_add_account_raw_note.go postgres locale: fix accounts.note_raw migration (#651) 2022-06-16 11:22:51 +02:00
20220511165212_add_account_raw_note_fix.go [bugfix] for the second accounts.note_raw migration (#653) 2022-06-16 19:39:57 +02:00
20220518123621_additional_indexing.go [performance] Add further indexes to mitigate laggy queries (#586) 2022-05-18 15:58:26 +01:00
20220612091800_duplicated_media_cleanup.go [chore] Standardize database queries, use bun.Ident() properly (#886) 2022-10-08 13:50:48 +02:00
20220710153020_fix_slow_web_profile_queries.go [performance] Add new index to fix slow web profile queries (#706) 2022-07-11 12:52:12 +01:00
20220804120132_account_default_post_format.go [feature] Let accounts set default status format, and use this when processing new statuses (#739) 2022-08-06 12:09:21 +02:00
20220823140228_user_custom_css.go [feature] Allow users to set custom css for their profiles + threads (#808) 2022-09-12 13:14:29 +02:00
20220827085121_assign_missing_in_reply_to_uris.go [bugfix] Status visibility + excludeReplies fixes (#769) 2022-08-27 11:35:31 +02:00
20220830014732_regenerate_indexes_for_follows.go [feature] Sort follow requests, followers, and following by updated_at (#774) 2022-08-31 11:27:39 +02:00
20220903141016_store_gifs_as_image.go [bugfix] Use 'Image' instead of unrecognized 'Gif' type for media attachments (#801) 2022-09-04 14:58:58 +02:00
20220905150505_custom_emoji_updates.go [feature] Custom emoji updates (serve emoji via s2s api, tune db models) (#805) 2022-09-06 12:42:55 +02:00
20220916122701_emojis_in_accounts.go [feature] Show + federate emojis in accounts (#837) 2022-09-26 11:56:01 +02:00
20220922142408_shared_inbox_delivery.go [feature] Allow delivery to sharedInboxes where possible (#847) 2022-09-23 20:27:35 +01:00
20220926115233_indexes.go [performance] Update indexes that were causing slow db queries (#855) 2022-09-26 14:43:19 +02:00
20221006114842_add_rss_functionality.go [feature] Add opt-in RSS feed for account's latest Public posts (#897) 2022-10-08 14:00:39 +02:00
20221011125732_refetch_updated_emojis.go [feature] Refetch emojis when they change on remote instances (#905) 2022-10-13 15:16:24 +02:00
main.go [chore] use our own logging implementation (#716) 2022-07-19 10:47:55 +02:00
README.md Extend license notices to 2022 (#354) 2021-12-20 18:42:19 +01:00

Migrations

How do I write a migration file?

See here

As a template, take one of the existing migration files and modify it, or use the below code snippet:

/*
   GoToSocial
   Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU Affero General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU Affero General Public License for more details.

   You should have received a copy of the GNU Affero General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package migrations

import (
    "context"

    "github.com/uptrace/bun"
)

func init() {
    up := func(ctx context.Context, db *bun.DB) error {
        return db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
            // your logic here
            return nil
        })
    }

    down := func(ctx context.Context, db *bun.DB) error {
        return db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
            // your logic here
            return nil
        })
    }

    if err := Migrations.Register(up, down); err != nil {
        panic(err)
    }
}

File format

Bun requires a very specific format: 14 digits, then letters or underscores.

You can use the following bash command on your branch to generate a suitable migration filename.

echo "$(date --utc +%Y%m%d%H%M%S | head -c 14)_$(git rev-parse --abbrev-ref HEAD).go"

Rules of thumb

  1. DON'T DROP TABLES!!!!!!!!
  2. Don't make something NOT NULL if it's likely to already contain null fields.