forked from KrauseFx/auxcord.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.rb
49 lines (44 loc) · 1.21 KB
/
db.rb
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
43
44
45
46
47
48
49
# frozen_string_literal: true
require 'sequel'
module SonosPartyMode
class Db
def self.shared_database
@shared_database ||= Sequel.connect(ENV.fetch('DATABASE_URL'))
end
def self.users
unless shared_database.table_exists?(:users)
shared_database.create_table :users do
primary_key :id
end
end
shared_database[:users]
end
def self.sonos_tokens
unless shared_database.table_exists?(:sonos_tokens)
shared_database.create_table :sonos_tokens do
primary_key :id
foreign_key :user_id, :users
String :access_token
String :refresh_token
String :expires_in
Int :volume, default: 20
String :group
String :household
TrueClass :party_active
end
end
return shared_database[:sonos_tokens]
end
def self.spotify_tokens
unless shared_database.table_exists?(:spotify_tokens)
shared_database.create_table :spotify_tokens do
primary_key :id
foreign_key :user_id, :users
String :options
String :playlist_id
end
end
return shared_database[:spotify_tokens]
end
end
end