diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 331d6d48..09703ed3 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -21,7 +21,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: '1.19.4' + go-version: '>=1.20.0' # This step usually is not needed because the /ui/dist is pregenerated locally # but its here to ensure that each release embeds the latest admin ui artifacts. diff --git a/daos/table.go b/daos/table.go index c10a2d93..82bd8a14 100644 --- a/daos/table.go +++ b/daos/table.go @@ -39,8 +39,17 @@ func (dao *Dao) GetTableInfo(tableName string) ([]*models.TableInfoRow, error) { err := dao.DB().NewQuery("SELECT * FROM PRAGMA_TABLE_INFO({:tableName})"). Bind(dbx.Params{"tableName": tableName}). All(&info) + if err != nil { + return nil, err + } - return info, err + // mattn/go-sqlite3 doesn't throw an error on invalid or missing table + // so we additionally have to check whether the loaded info result is nonempty + if len(info) == 0 { + return nil, fmt.Errorf("empty table info probably due to invalid or missing table %s", tableName) + } + + return info, nil } // DeleteTable drops the specified table. diff --git a/daos/table_test.go b/daos/table_test.go index 04e8281a..533d71d3 100644 --- a/daos/table_test.go +++ b/daos/table_test.go @@ -70,8 +70,8 @@ func TestGetTableInfo(t *testing.T) { tableName string expected string }{ - {"", "[]"}, - {"missing", "[]"}, + {"", "null"}, + {"missing", "null"}, { "_admins", `[{"PK":1,"Index":0,"Name":"id","Type":"TEXT","NotNull":false,"DefaultValue":null},{"PK":0,"Index":1,"Name":"avatar","Type":"INTEGER","NotNull":true,"DefaultValue":0},{"PK":0,"Index":2,"Name":"email","Type":"TEXT","NotNull":true,"DefaultValue":null},{"PK":0,"Index":3,"Name":"tokenKey","Type":"TEXT","NotNull":true,"DefaultValue":null},{"PK":0,"Index":4,"Name":"passwordHash","Type":"TEXT","NotNull":true,"DefaultValue":null},{"PK":0,"Index":5,"Name":"lastResetSentAt","Type":"TEXT","NotNull":true,"DefaultValue":""},{"PK":0,"Index":6,"Name":"created","Type":"TEXT","NotNull":true,"DefaultValue":""},{"PK":0,"Index":7,"Name":"updated","Type":"TEXT","NotNull":true,"DefaultValue":""}]`,