// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package v1_26

import (
	"code.gitea.io/gitea/modules/timeutil"

	"xorm.io/xorm"
)

// AddUploadSessionTable adds the upload_session table for chunked uploads
func AddUploadSessionTable(x *xorm.Engine) error {
	type UploadSession struct {
		ID             int64              `xorm:"pk autoincr"`
		UUID           string             `xorm:"uuid UNIQUE NOT NULL"`
		RepoID         int64              `xorm:"INDEX NOT NULL"`
		ReleaseID      int64              `xorm:"INDEX"`
		IssueID        int64              `xorm:"INDEX"`
		UploaderID     int64              `xorm:"INDEX NOT NULL"`
		FileName       string             `xorm:"NOT NULL"`
		FileSize       int64              `xorm:"DEFAULT -1"`
		ChunkSize      int64              `xorm:"NOT NULL"`
		ChunksExpected int64              `xorm:"DEFAULT -1"`
		ChunksReceived int64              `xorm:"DEFAULT 0"`
		BytesReceived  int64              `xorm:"DEFAULT 0"`
		Status         int                `xorm:"DEFAULT 0"`
		TempPath       string             `xorm:"NOT NULL"`
		CreatedUnix    timeutil.TimeStamp `xorm:"created"`
		UpdatedUnix    timeutil.TimeStamp `xorm:"updated"`
		ExpiresUnix    timeutil.TimeStamp `xorm:"INDEX"`
	}

	return x.Sync(new(UploadSession))
}
