tangled
alpha
login
or
join now
teal.fm
/
teal
110
fork
atom
Your music, beautifully tracked. All yours. (coming soon)
teal.fm
teal-fm
atproto
110
fork
atom
overview
issues
pulls
pipelines
add schema
natalie
1 year ago
c8c01099
47c9d88a
+53
-28
1 changed file
expand all
collapse all
unified
split
packages
db
schema.ts
+53
-28
packages/db/schema.ts
···
1
1
-
import { sqliteTable, text } from "drizzle-orm/sqlite-core";
1
1
+
import {
2
2
+
numeric,
3
3
+
sqliteTable,
4
4
+
text,
5
5
+
customType,
6
6
+
integer,
7
7
+
} from "drizzle-orm/sqlite-core";
2
8
3
3
-
export type DatabaseSchema = {
4
4
-
status: Status;
5
5
-
auth_session: AuthSession;
6
6
-
auth_state: AuthState;
7
7
-
};
8
8
-
9
9
-
export type Status = {
10
10
-
uri: string;
11
11
-
authorDid: string;
12
12
-
status: string;
13
13
-
createdAt: string;
14
14
-
indexedAt: string;
15
15
-
};
16
16
-
17
17
-
export type AuthSession = {
18
18
-
key: string;
19
19
-
session: AuthSessionJson;
20
20
-
};
21
21
-
22
22
-
export type AuthState = {
23
23
-
key: string;
24
24
-
state: AuthStateJson;
25
25
-
};
26
26
-
27
27
-
type AuthStateJson = string;
28
28
-
29
29
-
type AuthSessionJson = string;
9
9
+
// string array custom type
10
10
+
const json = <TData>() =>
11
11
+
customType<{ data: TData; driverData: string }>({
12
12
+
dataType() {
13
13
+
return "text";
14
14
+
},
15
15
+
toDriver(value: TData): string {
16
16
+
return JSON.stringify(value);
17
17
+
},
18
18
+
})();
30
19
31
20
// Tables
32
21
···
70
59
followed: text().primaryKey(),
71
60
createdAt: text().notNull(),
72
61
});
62
62
+
63
63
+
// play
64
64
+
export const play = sqliteTable("play", {
65
65
+
uri: text().primaryKey(),
66
66
+
authorDid: text().notNull(),
67
67
+
createdAt: text().notNull(),
68
68
+
indexedAt: text().notNull(),
69
69
+
70
70
+
/** The name of the track */
71
71
+
trackName: text().notNull(),
72
72
+
/** The Musicbrainz ID of the track */
73
73
+
trackMbId: text(),
74
74
+
/** The Musicbrainz recording ID of the track */
75
75
+
recordingMbId: text(),
76
76
+
/** The length of the track in seconds */
77
77
+
duration: integer(),
78
78
+
/** The name of the artist */
79
79
+
artistName: text().notNull(),
80
80
+
/** Array of Musicbrainz artist IDs */
81
81
+
// type of string[]
82
82
+
artistMbIds: json<string[]>(),
83
83
+
/** The name of the release/album */
84
84
+
releaseName: text(),
85
85
+
/** The Musicbrainz release ID */
86
86
+
releaseMbId: text(),
87
87
+
/** The ISRC code associated with the recording */
88
88
+
isrc: text(),
89
89
+
/** The URL associated with this track */
90
90
+
originUrl: text(),
91
91
+
/** The base domain of the music service. e.g. music.apple.com, tidal.com, spotify.com. */
92
92
+
musicServiceBaseDomain: text(),
93
93
+
/** A user-agent style string specifying the user agent. e.g. tealtracker/0.0.1b */
94
94
+
submissionClientAgent: text(),
95
95
+
/** The unix timestamp of when the track was played */
96
96
+
playedTime: text(),
97
97
+
});