so://phie

verbal

A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal

blob: 346fc63e42ea7610a283147d125948a73c056638 (4038 bytes)[doc][blame][raw]

1/* ############################################################ */

2/* # station # */

3/* ############################################################ */

4

5CREATE TABLE station (

6 id SERIAL PRIMARY KEY,

7 uid TEXT UNIQUE,

8 name TEXT NOT NULL,

9 url TEXT NOT NULL,

10 icon TEXT,

11 homepage TEXT,

12 tags TEXT[],

13 country TEXT,

14 state TEXT,

15 languages TEXT[],

16 score INTEGER,

17 description TEXT,

18 color TEXT,

19 group_id INTEGER,

20 utc INTEGER

21);

22

23ALTER TABLE station

24 ADD CONSTRAINT station_group_id

25 FOREIGN KEY (group_id)

26 REFERENCES station_group(id);

27

28/* ############################################################ */

29/* # station_group # */

30/* ############################################################ */

31

32CREATE TABLE station_group (

33 id SERIAL PRIMARY KEY,

34 name TEXT NOT NULL,

35 description TEXT

36);

37

38/* ############################################################ */

39/* # station_status # */

40/* ############################################################ */

41

42CREATE TABLE station_status (

43 id SERIAL PRIMARY KEY,

44 station_id INTEGER UNIQUE,

45 is_restricted BOOLEAN DEFAULT false,

46 is_broken BOOLEAN DEFAULT false,

47 is_no_track_info BOOLEAN DEFAULT false,

48 is_hidden BOOLEAN DEFAULT false,

49 is_icon BOOLEAN DEFAULT false

50);

51

52ALTER TABLE station_status

53 ADD CONSTRAINT station_status_station_id

54 FOREIGN KEY (station_id)

55 REFERENCES station(id);

56

57/* ############################################################ */

58/* # station_stats # */

59/* ############################################################ */

60

61CREATE TABLE station_stats (

62 id SERIAL PRIMARY KEY,

63 account_id INTEGER,

64 station_id INTEGER,

65 playtime INTEGER DEFAULT 0,

66 latest_at TIMESTAMP WITH TIME ZONE DEFAULT now()

67);

68

69ALTER TABLE station_stats

70 ADD CONSTRAINT station_stats_unique

71 UNIQUE(account_id, station_id);

72

73ALTER TABLE station_stats

74 ADD CONSTRAINT station_stats_account_id

75 FOREIGN KEY (account_id)

76 REFERENCES account(id);

77

78ALTER TABLE station_stats

79 ADD CONSTRAINT station_stats_station_id

80 FOREIGN KEY (station_id)

81 REFERENCES station(id);

82

83/* ############################################################ */

84/* # account # */

85/* ############################################################ */

86

87CREATE TABLE account (

88 id SERIAL PRIMARY KEY,

89 name TEXT,

90 language TEXT DEFAULT 'en',

91 created_at TIMESTAMP WITH TIME ZONE DEFAULT now()

92);

93

94/* ############################################################ */

95/* # device # */

96/* ############################################################ */

97

98CREATE TABLE device (

99 id SERIAL PRIMARY KEY,

100 uid TEXT UNIQUE NOT NULL,

101 name TEXT,

102 account_id INTEGER,

103 created_at TIMESTAMP WITH TIME ZONE DEFAULT now()

104);

105

106ALTER TABLE device

107 ADD CONSTRAINT device_account_id

108 FOREIGN KEY (account_id)

109 REFERENCES account(id);

110

111/* ############################################################ */

112/* # favorite # */

113/* ############################################################ */

114

115CREATE TABLE favorite (

116 id SERIAL PRIMARY KEY,

117 account_id INTEGER,

118 station_id INTEGER

119);

120

121ALTER TABLE favorite

122 ADD CONSTRAINT favorite_account_id

123 FOREIGN KEY (account_id)

124 REFERENCES account(id);

125

126ALTER TABLE favorite

127 ADD CONSTRAINT favorite_station_id

128 FOREIGN KEY (station_id)

129 REFERENCES station(id);

130

131/* ############################################################ */

132/* # guest account # */

133/* ############################################################ */

134

135INSERT INTO account (id, name)

136 VALUES (0, 'Guest');

137

138INSERT INTO device (uid, account_id)

139 VALUES ('guest-token', 0);