so://phie

verbal

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

blob: 57e9ee363a9573f504c83fa6cd5b43f9ab0b75a1 (3693 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);

21

22ALTER TABLE station

23 ADD CONSTRAINT station_group_id

24 FOREIGN KEY (group_id)

25 REFERENCES station_group(id);

26

27/* ############################################################ */

28/* # station_group # */

29/* ############################################################ */

30

31CREATE TABLE station_group (

32 id SERIAL PRIMARY KEY,

33 name TEXT NOT NULL,

34 description TEXT

35);

36

37/* ############################################################ */

38/* # station_status # */

39/* ############################################################ */

40

41CREATE TABLE station_status (

42 id SERIAL PRIMARY KEY,

43 station_id INTEGER UNIQUE,

44 is_restricted BOOLEAN DEFAULT false,

45 is_broken BOOLEAN DEFAULT false,

46 is_no_track_info BOOLEAN DEFAULT false,

47 is_hidden BOOLEAN DEFAULT false,

48 is_icon BOOLEAN DEFAULT false

49);

50

51ALTER TABLE station_status

52 ADD CONSTRAINT station_status_station_id

53 FOREIGN KEY (station_id)

54 REFERENCES station(id);

55

56/* ############################################################ */

57/* # station_stats # */

58/* ############################################################ */

59

60CREATE TABLE station_stats (

61 id SERIAL PRIMARY KEY,

62 account_id INTEGER,

63 station_id INTEGER,

64 playtime INTEGER DEFAULT 0,

65 latest_at TIMESTAMP WITH TIME ZONE DEFAULT now()

66);

67

68ALTER TABLE station_stats

69 ADD CONSTRAINT station_stats_unique

70 UNIQUE(account_id, station_id);

71

72ALTER TABLE station_stats

73 ADD CONSTRAINT station_stats_account_id

74 FOREIGN KEY (account_id)

75 REFERENCES account(id);

76

77ALTER TABLE station_stats

78 ADD CONSTRAINT station_stats_station_id

79 FOREIGN KEY (station_id)

80 REFERENCES station(id);

81

82/* ############################################################ */

83/* # account # */

84/* ############################################################ */

85

86CREATE TABLE account (

87 id SERIAL PRIMARY KEY,

88 name TEXT,

89 language TEXT DEFAULT 'en',

90 created_at TIMESTAMP WITH TIME ZONE DEFAULT now()

91);

92

93/* ############################################################ */

94/* # device # */

95/* ############################################################ */

96

97CREATE TABLE device (

98 id SERIAL PRIMARY KEY,

99 uid TEXT UNIQUE NOT NULL,

100 name TEXT,

101 account_id INTEGER,

102 created_at TIMESTAMP WITH TIME ZONE DEFAULT now()

103);

104

105ALTER TABLE device

106 ADD CONSTRAINT device_account_id

107 FOREIGN KEY (account_id)

108 REFERENCES account(id);

109

110/* ############################################################ */

111/* # favorite # */

112/* ############################################################ */

113

114CREATE TABLE favorite (

115 id SERIAL PRIMARY KEY,

116 account_id INTEGER,

117 station_id INTEGER

118);

119

120ALTER TABLE favorite

121 ADD CONSTRAINT favorite_account_id

122 FOREIGN KEY (account_id)

123 REFERENCES account(id);

124

125ALTER TABLE favorite

126 ADD CONSTRAINT favorite_station_id

127 FOREIGN KEY (station_id)

128 REFERENCES station(id);