-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyoutubearchive.go
42 lines (37 loc) · 1 KB
/
youtubearchive.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package youtubearchive
import (
"github.com/Necroforger/youtubearchive/models"
"github.com/jinzhu/gorm"
)
// InitDB initializes the gorm DB with models
func InitDB(db *gorm.DB) error {
err := db.AutoMigrate(&models.Video{}).Error
if err != nil {
return err
}
err = db.AutoMigrate(&models.Tag{}).Error
if err != nil {
return err
}
// Create a table for storing channel metadata as JSON
err = db.Exec(`
CREATE TABLE IF NOT EXISTS channel_metadata (
ID INTEGER PRIMARY KEY,
created TEXT,
updated TEXT,
uploader_url TEXT,
json TEXT
);
-- A view of all channels most recent metadata archive
CREATE VIEW IF NOT EXISTS recent_channel_metadata AS
select * from channel_metadata where ID in (
select
(select ID from channel_metadata where a.uploader_url = uploader_url order by created desc) as ID
from
(select uploader_url from channel_metadata group by uploader_url) a)
`).Error
if err != nil {
return err
}
return nil
}